State Machine
 
 

Purpose: To discover what the ABEL program 'statemach.abl' from the Digital Systems web site does.

Procedure:
Download and save the 'statemach.abl' file from the Digital Systems Lab web server (when downloading, select the file type as 'All files'). The next step is to open the file using the ispDesignEXPERT.
Double click on the ISP Design Expert icon. The ISP Design Expert window will appear. This is how it looks like:

 
 
 
  Click on the 'File' tab and select ' New project '. When prompted to save the newly created project, I saved it as "statemach.syn". We can change the Name of the project by double clicking the upper icon in the sources box. The default device is (ispLSI5384VA-125LB388). We change the type of device by double clicking on the yellow CPLD icon:  
   
 
If you get some messages like this choose OK and then confirm the change by choosing "Yes":
 
   
 
We import a new source by choosing 'Source' and then 'Import...'. We choose the statemach.abl file. This is how the Text Editor looks like:
 
   
 
You can download the program from here: statemach.abl. There is more detailed information about the making of the program in "The Program" section
 
 
Select the device (M4-64/32-15JC) from the left pane and double click the 'Constraint Editor' on the Right pane. Once the constraint editor has initialized, select ' LOC ' from the toolbar to assign the correct PIN numbers to the switches and segments ( the box next to the Output must be checked in order to get the full list of the segments). Use the " pin out of the CPLD (both MACH4-32/32 and MACH4-64/32) on the development board " datasheet from the Digital Systems Lab web server for the correct pin assignments.
!REMARK: when assigning the pins use the leftmost column of the table to get the correct pin numbers. DO NOT use the second one. The first time when I did the program I made the wrong associations and got compilation errors.
 
   
 
The image above represents the Pin assignments window. Once all the pins and switches have been assigned, minimize the constraint editor, plug in the JTAG download cable into the parallel port of the laptop, connect the power supply to the development board and run ' Fit Design ' (found on the right navigator window of the ispDesignExpert) by double clicking on it. Once the ' Fit Design ' has completed, a JEDEC file by the name of ' statemach.jed ' was created in the same directory as the "statemach.abl'.

The next step involves downloading the design on to the M4-64/32 CPLD on the development board. In order to do this, run the ' ispVM System '. With the power supply connected to the development board and the JTAG download cable connected to the laptop, click on ' Scan ' in the toolbar to automatically detect the CPLD on the development board. Once the M4-64/32 appears on the device list, double click on it to get the device information dialog box. The image below is a capture from the ispVM System:

 
   
 
You can change the description for the device manually and change the path for the .jed file:
 
   
 
After specifying the JED file click on OK, click on the ' Go ' in the toolbar to begin the download. Once the download is completed you are ready to test the system.
 
 
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.

 
 

Observations:

-The result of the program was the following loop:

(Using the same SSD identification used in Lab Report 2)

U22A to U22B to U22C to U22D to U22E to U22F to U22A...

 
 

Problems and Conclusion:

Again the common error you might experience is that the pins and segment are actually ' active low ' and not ' active high '. You can correct this problem by simply negating (!) the switches and segments in the PIN description part of the program.

In conclusion, the program 'statemach.abl' describes a six state machine.

 
 
Modifications to the program:
Deriving from the previous rolling ball program we can create a program which rolls a ball on the sides of all the 4 seven-segment displays or even a program which rolls several balls, like a snake on the 4 seven-segment displays.
This program rolls the ball on the edges of the 7-segments:

MODULE StateMach
ine

TITLE 'State machine example'

" Inputs from evaluationkit
!SW1 pin;
!SW2 pin;
!SW3 pin;

" fourth SevSeg from left
!U22A pin istype 'com';
!U22B pin istype 'com';
!U22C pin istype 'com';
!U22D pin istype 'com';
!U22E pin istype 'com';
!U22F pin istype 'com';
!U22G pin istype 'com';
!U23A pin istype 'com';
!U23D pin istype 'com';
!U24A pin istype 'com';
!U24D pin istype 'com';
!U24E pin istype 'com';
!U24F pin istype 'com';
!U26A pin istype 'com';
!U26D pin istype 'com';


" Clock inputs
SelClk pin;

Q1..Q12 node istype 'reg';

" Sets for inputsignals
SWINP = [SW1, SW2, SW3];

" Sets for output signals
ON = [Q1..Q12];
SEGs = [U22A, U22B, U22C, U22D, U26D, U23D, U24D, U24E, U24F, U24A, U23A];

Equations

ON.CLK = SelClk; " Clock for counter
ON.AR = (SWINP == 4)#(ON == 1); " Reset for counter

When ON == 0 then ON := 2;
else ON := ON + ON;

SEGs = [Q1..Q11];
U26A = (ON == 0);

END

You can download the moving snake program from here: snakestate.abl. It shows how to move four lights on the SSDs.

 
 

The movie of the experiment -this is the .avi demonstration of how the program works.
The movie of the first modification to the program.

The movie of the second modification to the program.