DCC State Machine version 003

State 0

State 0 is to synchronize on the preamble. It is initiated with DCC_subst set to 20, the minimum number of "1" half cycles for a valid preamble.
ConditionActionProcessNext state
receive 0 bitset DCC_subst to 20 (start over)dca010
receive 1 bitdecrement DCC_subst, if now 0 go to state 1dca020 / 1

State 1

State 1 waits for the first start (0) bit
ConditionActionProcessNext state
receive 0 bitset DCC_subst to 8, go to state 2dca032
receive 1 bitwait 1

State 2

State 2 verifies the second half of a "0" bit
ConditionActionProcessNext state
receive 0 bitif DCC_subst == 0 go to state 5, else go to state 3 for next bitdca063 / 5
receive 1 bitset DCC_subst to 20, go to state 0dca010

State 3

State 3 processes the first half of a bit
ConditionActionProcessNext state
receive 0 bitassemble "0" bit, decrement DCC_subst, go to state 2 to verifydca042
receive 1 bitassemble "1" bit, decrement DCC_subst, go to state 4 to verifydca054

State 4

State 4 verifies the second half of a "1" bit
ConditionActionProcessNext state
receive 0 bitset DCC_subst to 20, go to state 0dca010
receive 1 bitif DCC_subst == 0 go to state 5, else go to state 3 for next bitdca073 / 5

State 5

State 5 looks for EOM or start another byte
ConditionActionProcessNext state
receive 0 bitset DCC_subst to 8, go to state 2dca032
receive 1 bitset EOM, check checksum if used / set DCC_subst to 20 go to state 0dca00/dca010