Sequencer

Experimental V1 firmware documentation. Koheron products currently ship with V0.x firmware by default. V1 firmware executables are not publicly available yet. Please contact us if you are interested in early access or would like to evaluate V1 on your device.

The sequencer executes a stored program from EEPROM without requiring continuous host communication. It is useful when a controller must execute a short deterministic sequence of timed commands, checks or register operations.

The sequencer is an advanced feature. Test programs carefully with safe setpoints and limits before connecting sensitive hardware.

Enable and stop

Read the sequencer state:

>> sequ
0

Start execution:

>> sequ 1
1

Stop execution:

>> sequ 0
0

Writing sequ requires advanced access. The value is saved by the UART configuration path. At startup, saved sequencer values are sanitized: only 1 means run; all other values mean stopped.

Program storage

The sequencer reads program lines from user EEPROM pages. Each page contains one line of up to 32 bytes. The sequencer reads from page 0x00 upward and stops when it reaches an empty page or the maximum sequencer page count.

The common sequencer loads at most 32 pages, so sequencer program pages are 0x00 to 0x1F. User EEPROM may contain more pages, but pages after 0x1F are not part of the common sequencer program.

Use memw to write pages and memr to verify them. memw writes exactly 32 raw bytes and requires advanced access.

Line format

Each sequencer line has the form:

<delay> <command>

The delay is in milliseconds and is written as a hexadecimal value. It may also be a register reference such as r0.

Sequencer program line examples:

0 NOP
1f4 rtset 12000
r0 lason 1

A line must fit in one 32-byte EEPROM page. Trailing spaces are ignored when the page is read. An empty page stops program loading.

Timing model

The sequencer uses the firmware millisecond time base. The maximum valid single delay is 0x7fffffff ms.

A delay is scheduled relative to the previous due time when a previous due time exists; otherwise it is scheduled relative to the current millisecond timer. This keeps a running sequence aligned to its intended schedule as long as command execution does not overrun the timing budget.

Zero-delay control instructions can execute back-to-back in the same processing pass. Zero-delay normal firmware commands are rejected. Use a non-zero delay for normal commands that change physical outputs.

Registers

The sequencer has 16 32-bit registers: r0 to rF.

Read all registers:

>> regs
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

Read one register:

>> regs 0
00000000

Write one register:

>> regs 0 00000010
00000010

Register writes require advanced access. Register values are printed as 8 hexadecimal digits.

Register persistence

The common EEPROM layout reserves two EEPROM pages for the 16 sequencer registers. The firmware can export and import these registers through the EEPROM sequencer-register configuration path.

Program pages and register storage are separate. Program pages are accessed with memw and memr.

Normal command entries

A sequencer line may execute a normal firmware command:

64 rtset 12000
64 lason 1
64 tecon 1

Normal commands are executed silently by the sequencer: their text output is suppressed. The sequencer records the command as successful after executing it.

The common sequencer caches at most 8 distinct normal command strings while loading a program. Use control opcodes or fast commands when a program needs more compact logic.

Fast commands

A sequencer line may execute a product-specific fast command beginning with #:

10 #01
10 #23 r0
10 #23 r0 r1
10 #23 00000010

The common parser accepts these forms:

  • #ID
  • #ID dst
  • #ID src dst
  • #ID immediate

The meaning of a fast command ID is product-specific. Do not use fast commands unless the product firmware documents them.

Control opcodes

Control opcodes are interpreted by the common sequencer and do not call a product command. They may use zero delay.

SET

Set a register to a hexadecimal value:

0 SET r0 10

DEC

Decrement a register if it is non-zero:

0 DEC r0

JNZ

Jump to a page if the register is non-zero:

0 JNZ r0 03

GOTO

Unconditional jump:

0 GOTO 05

Conditional jump based on previous command status:

0 GOTO 06 08

If the previous status is valid and true, execution jumps to the first page. Otherwise it jumps to the second page.

ADD and SUB

Saturating register arithmetic:

0 ADD r0 r1
0 SUB r0 r1

ADD r0 r1 stores r0 + r1 in r0, saturated at 0xffffffff. SUB r0 r1 stores r0 - r1 in r0, saturated at zero.

MOV

Copy the second register into the first register:

0 MOV r0 r1

This stores r1 into r0.

CMP, LT and GT

Compare two registers and update the previous status:

0 CMP r0 r1
0 LT r0 r1
0 GT r0 r1

The status is true when the comparison is true.

Bitwise operations

0 AND r0 r1
0 OR r0 r1
0 XOR r0 r1
0 NOT r0
0 TST r0 r1

AND, OR and XOR update the first register in place. NOT inverts one register. TST sets the previous status true when (r0 & r1) != 0.

ERR

Copy the current error mask into a register:

0 ERR r0

The previous status is true when the error mask is zero.

TMS

Copy the low 32 bits of the millisecond timer into a register:

0 TMS r0

NOP

No operation:

0 NOP

END

Stop the sequencer:

0 END

Loading validation

During loading, the firmware validates jump targets for GOTO and JNZ against the number of loaded entries. If a target is outside the loaded program, the firmware sets an invalid-argument error and stops the sequencer.

Example loop

This example executes a command five times with 100 ms spacing, then stops. The delay 64 is hexadecimal for 100 ms.

0 SET r0 5
64 lason 1
64 lason 0
0 DEC r0
0 JNZ r0 01
0 END

Store one line per EEPROM page, starting at page 0x00, and write an empty page after the last line to terminate loading.

Practical advice

  • Keep early programs short and easy to inspect with memr.
  • Use labels in your host-side generator, then compile labels to numeric page targets before writing EEPROM.
  • Use non-zero delays for normal commands that affect outputs.
  • Check err after starting the sequencer.
  • Use sequ 0 as the first recovery command if a test program behaves unexpectedly.
[email protected]