Docsity

Creating a Two-Bit Counter using Xilinx State Diagram Editor: A Tutorial, Assignments of Electrical and Electronics Engineering

Toggle sidebar
bg1
1
State Diagram Tutorial
In general, a state diagram can be used to model the transition of a sequential machine.
The sequence is determined by the present state of the machine and the input(s) given.
After completing this tutorial you should be able to create a state diagram in Xilinx, make
I/O assignments, load your design on the FPGA, and test your design using the Read to-
Write to software or using external hardware such as the proto box. As you may have
seen, it is often desired to create a design in a CAD software such as Xilinx. Once the
design is created, Xilinx can easily compile a VHDL source code for it that can in turn be
program on a chip, the FPGA (Field Programmable Gate Array) . If I/O pin numbers
were assigned while you were creating your state diagram, then the FPGA will be able to
communicate with the outside world.
This tutorial walks you through creating a two bit counter in order to help you become
familiar with State CAD, the state diagram editor in the Xilinx ISE Tools.
1. Start a new project (make sure you specify XST VHDL for the design flow and
Spartan 2 xc2s50-5tq144 for the part).
2. Right click in the sources pane and select “New Source…” or choose “New
Source…” from the Project menu.
3. Select “State Diagram” as the source type and give a File Name (make this
different than the name of your project as you do with all other sources used in
ISE)
4. Click Next and then Finish
5. State CAD should launch automatically with a blank file open
6. The toolbar from State CAD is shown in the figure at left. You will need the first
four tools at the top of the toolbar as well as the third tool from the bottom of the
toolbar to construct a state diagram. The first tool is the selector which can be
used to select, resize and move objects that are placed in the diagram. The second
tool is the state drawing tool, the third is the state transition drawing tool and
fourth is the reset drawing tool. Your diagram will consist of states drawn with
the state drawing tool which are connected by transitions drawn with the state
transition drawing tool. The yellow school bus is used to define vectors or buses.
7. Activate the state drawing tool by clicking its icon in the toolbar. Click once on
the state diagram. A state similar to the one shown below appears.
8. You can draw more states by continuing to click on the diagram. It is recommend
you rename the state. You can change the name of a state by switching back to
the selector tool (the arrow) and double clicking the state whose name you want to
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Creating a Two-Bit Counter using Xilinx State Diagram Editor: A Tutorial and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

State Diagram Tutorial

In general, a state diagram can be used to model the transition of a sequential machine. The sequence is determined by the present state of the machine and the input(s) given. After completing this tutorial you should be able to create a state diagram in Xilinx, make I/O assignments, load your design on the FPGA, and test your design using the Read to- Write to software or using external hardware such as the proto box. As you may have seen, it is often desired to create a design in a CAD software such as Xilinx. Once the design is created, Xilinx can easily compile a VHDL source code for it that can in turn be program on a chip, the FPGA (Field Programmable Gate Array). If I/O pin numbers were assigned while you were creating your state diagram, then the FPGA will be able to communicate with the outside world.

This tutorial walks you through creating a two bit counter in order to help you become familiar with State CAD, the state diagram editor in the Xilinx ISE Tools.

  1. Start a new project (make sure you specify XST VHDL for the design flow and Spartan 2 xc2s50-5tq144 for the part).
  2. Right click in the sources pane and select “New Source…” or choose “New Source…” from the Project menu.
  3. Select “State Diagram” as the source type and give a File Name (make this different than the name of your project as you do with all other sources used in ISE)
  4. Click Next and then Finish
  5. State CAD should launch automatically with a blank file open
  6. The toolbar from State CAD is shown in the figure at left. You will need the first four tools at the top of the toolbar as well as the third tool from the bottom of the toolbar to construct a state diagram. The first tool is the selector which can be used to select, resize and move objects that are placed in the diagram. The second tool is the state drawing tool, the third is the state transition drawing tool and fourth is the reset drawing tool. Your diagram will consist of states drawn with the state drawing tool which are connected by transitions drawn with the state transition drawing tool. The yellow school bus is used to define vectors or buses.
  7. Activate the state drawing tool by clicking its icon in the toolbar. Click once on the state diagram. A state similar to the one shown below appears.
  8. You can draw more states by continuing to click on the diagram. It is recommend you rename the state. You can change the name of a state by switching back to the selector tool (the arrow) and double clicking the state whose name you want to

change. Like all other names in Xilinx a state name cannot begin with a number and cannot contain spaces.

  1. Draw three more states and arrange them so that you diagram looks like the one shown below.
  2. You now need to connect the states in your diagram with transitions. Change to the transition drawing tool and create a transition in each direction between sequential states (e.g. make a transition from STATE0 to STATE1 and from STATE1 to STATE0 but not from STATE0 to STATE2 or STATE3). You draw a transition by clicking on the state from which you want to transition and then clicking on the state to which you want to transition. When you are done you should have a total of eight transitions and your diagram should look similar to the one below.
  3. If you do not like how State CAD places a transition you can easily change it using the selector tool. Simply click and drag the end black square on the head or tail of a transition to a different location. You do not need to select the transition you want to modify before dragging its end node, simply click and drag the node. If you accidentally disconnect a transition State CAD will warn you with a dialog box and it will not let you continue until you properly place the transition.
  4. The goal of the state machine you are drawing is to count up or down through the binary sequence 00, 01, 10, 11. Before you can implement this behavior you need to define the inputs and outputs for your machine. There are several ways to do
  1. You will want to be able to determine the present count while the machine is running so each state needs an output indicating what the count is. To do this, double click each state and enter an output (CNT = “00”; for STATE0, CNT = “01”; for STATE1, etc). In addition to displaying the binary count, we will also output the values needed to light up the appropriate segments of the seven segment display. For State0 your screen should look like the figure below.
  2. In order for the machine to determine which direction it should count you need to specify transition conditions for every transition in the diagram. Note that each transition assumes that you are in the state from which you will be transitioning and a clock has occurred. Thus, you should not ever need to include the clock in your transition condition. Double click each transition and add a transition condition. For transitions that result in the count being incremented make the condition UPCNT (1), for those that result in the count be decremented make the condition !UPCNT (0).

Aside: If we happened to have a 4 bit input, say WXYZ, we could use the notation W&X&Y&Z for 1111 and !(W&X&Y&Z) for 0000 as our conditions. In addition !W&X&Y&Z represents 0111.

  1. The last thing you need to do is create a reset. To do this, change to the reset drawing tool and click the diagram near STATE0. Next click STATE0. State CAD will ask you what type of reset you want, say “No” to specify synchronous. Your diagram should now look similar to the one below.
  2. You will now want to test you state machine. To do this start State Bench by clicking on it’s icon in the button bar at the top of the State CAD window. To have State Bench exhaustively test the design, click the Automatic Testbench button (third button in the fifth group of buttons in the toolbar at the top of the State Bench window) and click the Begin button in the dialog that pops up. You can close the State CAD HDL Browser window that appears and then examine the operation of your machine. If you would like to test the operation in a particular way you can create your own State Bench waveform and run it. Note that State Bench asserted RESET at the start of the simulation, you must do this as well if you create your own test pattern. You may encounter several warning while trying to do this, but you can ignore them for now. Just because you receive warnings while using State Bench does not necessarily mean your circuit is flawed. Continue through this tutorial, and you will discover an easier and more familiar way to run a test waveform, but either way you test your design RESET must be asserted HIGH then taken LOW.
  1. At this point you should be able to assign the appropriate I/O ports by connecting I/O markers to the state diagram symbol. After doing so you will have to assign pin number to these I/Os. We are going to use the 7 Segment display mounted on the XC2S50 FPGA board to display out current count. Because the 7 Segment display is hard wired to the board certain pins have already been assigned to it. These pins are connected internally so you will not need to physically wire these connections.

s0 p67 (d) s1 p39 (c) s2 p62 (e) s3 p62 (g) s4 p60 (b) s5 p57 (f) s6 p49 (a)

If the configuration of the 7-Segemnt displays seems ackward, that’s because it is. If you look back at the figure in step 16 you’ll see SEGMENT=1110111 is used to display 0. That’s because of the relationship between s0..s6 and a…g as shown

above. If you were connecting to an external 7-segment the figure below could be used directly.

  1. In addition we must assign the Clear & Upcount inputs and the remaining outputs c0 & c1. We can use any of the available pins to assign these. The following can be used here.

Clear p Upcount p c0 p c1 p clock p

The pin assignments can be make by going to User Constraints > Edit Implementation Constraints (Constraints Editor) and selecting the Ports tab in the center of the screen as shown. The only additional pin assignment that must be made is p41 that you will need to tie to Vcc in your schematic. Note that pin 41 (Flash_CE) does not get physically connected by you, its an internal thing. To do this select and place the symbol Vcc in the schematic window and attach an output marker to it.