The
Program:
The program describes a six state machine. The possible
states are namely U22A, U22B, U22C, U22D, U22E, and
U22F.
The
first part of the program involves the declaration
of the inputs, outputs and nodes. The pin types for
the outputs are also declared; where 'com' is for
combinational output and 'reg' is for registered output).
The second part of the program lists and defines the
possible states. For example:
SEG10n0 = [U22A, U22B, U22C, U22D, U22E, U22F, U22G];
S0
= [1, 0, 0, 0, 0, 0, 0];
means
that the S0 state is such that only the U22A pin is
active (1) while all the other pins are inactive(0).
The
'Equations' section describes the response of the
circuit to inputs. The statement 'running_light.CLK
= SelClk;' acts as a counter and allows us to adjust
the speed of the outputs through the on-board jumper
connections. The second statement 'running_light.AR
= (SWINP = =4);) allows us to reset the six state
machine to the U22A state and restart the loop. 'SWINP
== 4' represents the switch input set [1,0,0] (binary
representation of 4); so the machine is reset when
Switch 1 is pressed.
The
'State_diagram' section controls the flow of the program.
It lists all the possible states and the subsequent
arguments of the machine. Typical statements are :
state Seg_A : SEG10n0 = S0;
If S0 then Seg_B;
state Seg_B : SEG10n0 = S1;
The
keyword state_diagram indicates the beginning of a
state machine description.
The
syntax for State_diagram is as follows:
State_diagram
state_reg
STATE
state_value : [equation;]
[equation;]
...
trans_stmt
; ...
The
keyword state_diagram indicates the beginning of a
state machine description.
Here,
state_reg is the identifier to define the signal,
which will determine the state of the machine. state_value
is either an expression or a value or a symbol for
the current state. trans_stmt consists of statements
like 'if-then-else', case or goto to define the next
state.
The
first statement assigns the state S0 to Seg_A . That
is U22 is at the following state:
[1, 0, 0, 0, 0, 0, 0]
(U22A
- ON, U22B - OFF, U22C - OFF, U22D - OFF, U22E - OFF,
U22F - OFF, U22G - OFF)
The
second statement (If S0 then Seg_B) is an argument
that implies that if the state machine is at state
S0, the next state is that for Seg_B (i.e. S1). The
same arguments apply to the rest of the program.