R5 state machine#

The state of the UltraZohm is controlled by a state machine in the R5 (uz_platform_state_machine.c). The initialization of the system is not part of the state machine and is done in main.c of the R5.

        stateDiagram-v2
    [*] --> Idle
    Idle --> Running: Enable System
    Running --> Control: Enable Control
    Control --> Error: Error
    Running --> Error: Error
    Idle --> Error: Error
    Error --> Idle: Stop
    Running --> Idle: Stop
    Control --> Idle: Stop
    state "Idle" as Idle: Slowly blink ready LED
    state "Running" as Running: Blink ready LED <br> Enable FPGA outputs
    state "Control" as Control: Blink ready LED <br> Turn on running LED <br> Enable control algorithm
    state "Error" as Error: Disable FPGA outputs <br> Turn on error LED
    

The figure above shows the four states of the UltraZohm:

  • Idle

  • Running

  • Control

  • Error

The implicit state assertion is not shown (see Assertions). If an assertion is triggered in any state, the state machine enters the error state. From error state, the system returns to idle when a stop input is present. The state machine has the following input variables:

  • Enable system

  • Enable control

  • Stop

  • Error

For all UltraZohm versions >2, enable system, enable control, and stop are available as buttons on the front panel. Additionally, these signals can be set using the JavaScope setter functions (e.g., ultrazohm_state_machine_set_enable_system). The effective state machine inputs are updated in every ultrazohm_state_machine_step by merging both sources:

  • Enable system = front-panel button OR latched JavaScope request

  • Enable control = front-panel button OR latched JavaScope request (only considered in running state)

  • Stop = front-panel stop OR latched JavaScope request (plus optional external stop, if enabled at compile time)

JavaScope requests are latched by the setter functions and consumed (cleared) once per ultrazohm_state_machine_step. A stop input takes priority: any pending enable requests are discarded in the same step that stop is active. The input Error is only set from software functions.

The different states are indicated by the status of the LEDs on the front panel. The main difference between the states is that no output signals are routed through the CPLD (gate signals are off) if the system is not in the state Running or Control. Likewise, the control algorithm in the ISR is not executed, if the system is not in the state Control.

The following table shows the complete state table. In this table, Enable System, Enable Control, and Stop refer to the merged effective inputs described above.

Table 7 State table with inputs and outputs of the UltraZohm#

Output

Output

Output

Output

Output

Output

Input

Input

Input

Input

Next state

LED

LED

LED

LED

Software

FPGA

State

Ready

Running

Error

User

Controller

Outputs

Enable System

Enable Control

Stop

Error

Next state

Idle

Blink slow

Off

Off

Off

Off

Off

==1

x

!=1

!=1

Running

Idle

Blink slow

Off

Off

Off

Off

Off

x

x

x

==1

Error

Running

Blink fast

Off

Off

Off

Off

On

x

==1

!=1

!=1

Control

Running

Blink fast

Off

Off

Off

Off

On

x

x

x

==1

Error

Running

Blink fast

Off

Off

Off

Off

On

x

x

==1

!=1

Idle

Control

Blink fast

On

Off

Off

On

On

x

x

==1

!=1

Idle

Control

Blink fast

On

Off

Off

On

On

x

x

x

==1

Error

Error

Off

Off

On

Off

Off

Off

x

x

==1

!=1

Idle

Software reference#

enum platform_state_t#

Enum for the available states of the UltraZohm.

Values:

enumerator idle_state#
enumerator running_state#
enumerator control_state#
enumerator error_state#
platform_state_t ultrazohm_state_machine_get_state(void)#

Returns the current state of the ultrazohm.

Returns:

platform_state_t

void ultrazohm_state_machine_step(void)#

Exectures the central state machine of the UltraZohm once.

void ultrazohm_state_machine_set_enable_system(bool enable_system)#

Latches a one-shot enable system request for the next state machine step.

Passing false has no effect. The flag is consumed and cleared by ultrazohm_state_machine_step; a stop active at that time discards it.

Parameters:
  • enable_system – Set to true to latch the request.

void ultrazohm_state_machine_set_enable_control(bool enable_control)#

Latches a one-shot enable control request for the next state machine step.

Passing false has no effect. The flag is consumed and cleared by ultrazohm_state_machine_step; a stop active at that time discards it.

Parameters:
  • enable_control – Set to true to latch the request.

void ultrazohm_state_machine_set_stop(bool stop)#

Latches a one-shot stop request for the next state machine step.

Passing false has no effect. Stop takes priority over any pending enable requests in the same step.

Parameters:
  • stop – Set to true to latch the request.

void ultrazohm_state_machine_set_error(bool error)#

Sets the input signal error of the state machine.

Parameters:
  • error

bool ultrazohm_state_machine_get_enable_system(void)#

Get state of the input signal enable system.

Returns:

true

Returns:

false

bool ultrazohm_state_machine_get_enable_control(void)#

Get state of the input signal enable control.

Returns:

true

Returns:

false

bool ultrazohm_state_machine_is_control_state(void)#

Special function to check if the state machine is in the state “control” - should only be used in the ISR!

Returns:

true

Returns:

false

bool ultrazohm_state_get_led_running(void)#

Returns the current state of the running led.

Returns:

true

Returns:

false

bool ultrazohm_state_get_led_ready(void)#

Returns the current state of the ready led.

Returns:

true

Returns:

false

bool ultrazohm_state_get_led_error(void)#

Returns the current state of the error led.

Returns:

true

Returns:

false