Synthesis:
Behavioral description of a 7-segment decoder
I. Introduction
The XS40 board uses a seven segment display. The inputs to the display correspond to each of the LEDs (Light Emitting Diodes). Therefore, we need a way to decode (ie translate) binary numbers to 7 bit numbers that correspond to the number being decoded. For example, if we wanted to display the number seven on the display, we would send the number 0111 to the decoder, and it determines which LEDs to turn on. We are going to display 16 numbers (zero through F), so we will need a four bit input. The purpose of this lab is to write code
so that the 7-segment decoder is described behaviorally. To do
this a distinction must be made between a behavioral description
and a structural description.
Here is an example to get you started, and describe the difference between structural and behavioral:
Suppose we want to construct the above circuit. We can describe the
circuit in several ways.
STRUCTURAL DESCRIPTION
If we were to describe the above circuit structurally we would first
have to construct entities which act as AND2 and OR2 gates. Then we
would plug our input values into these entities to get our result.
...
entity NAND2 is
port ( input1, input2: in STD_LOGIC;
output1: out STD_LOGIC
);
end NAND2;
architecture beh_nand2 of nAND2 is
begin
output1 <= input1 nand input2;
end beh_nand2;
entity XOR2 is
port ( input1, input2: in STD_LOGIC;
output1: out STD_LOGIC
);
end XOR2;
architecture beh_xor2 of XOR2 is
begin
output1 <= input1 xor input2;
end beh_xor2;
entity CIRCUIT is
port ( a, b, c : in STD_LOGIC;
f: out STD_LOGIC;
);
end CIRCUIT;
architecture struct of CIRCUIT is
signal e: STD_LOGIC;
component NAND2
port ( input1, input2: in STD_LOGIC;
output1: out STD_LOGIC
);
end component;
component XOR2
port ( input1, input2: in STD_LOGIC;
output1: out STD_LOGIC
);
end component;
begin
X1: NAND2 port map(A, B, E);
X2: XOR2 port map(E, D, F);
end struct;
...
BEHAVIORAL DESCRIPTION
If we were to describe the above circuit behaviorally we would not have
to worry about mimicing the gates. Instead we can describe the result
at a more abstract level which greatly simplifies things as seen below:
...
entity CIRCUIT is
port ( a, b, d: in STD_LOGIC;
f: out STD_LOGIC
);
end CIRCUIT;
architecture beh of CIRCUIT is
begin
f <= (a nand b) xor d;
end beh;
...
II. Procedure
Implement the entity
- Write your decoder behaviorally, and check it using Aldec Active-HDL. Refer to previous labs to help you get started using Aldec Active-HDL. You will be using this code in later labs, so make sure it is neat and easy to read.
- Write a testbench that checks all sixteen possible situations. If it is working correctly, demonstrate it to the TA.
- Make sure to copy both your design VHDL file and your testbench to your home directory or a disk.
- Open up Xilinx Foundation and start a design using your design VHDL file as the only file (you will not need the testbench here).
Creating and simulating the output of Xilinx
Xilinx synthesizes your design down to a level of basic building
blocks. It will create a VHDL file that represents what it thinks you
want. Conveniently, you can test this file with the same test-bench you
created for your behavioral code.
- Create a new Project in Xilinx paying close attention to what directory it
will be put in AND make sure to check the button for HDL
- Add your VHDL file to the project (don't add your testbench)
- Click on the Synthesis Block in the window on the right side (the
top-level should be your top entity)
- Click "Run"
- Now click on the Implementation Block
- That should bring up a settings window. At the bottom of it, click
on "Options"
- For "Simulation" select "GenericVHDL"
- Click "OK" then click on "Run"
- After Xilinx finishes the process of placing and routing your design, look
in the directory where your project is for a file named "time_sim.vhd"
- This part may get a little tricky: You need to copy this file (time_sim)
to your ActiveHDL project
- Now that it is in your ActiveHDL project add it to your design and look at
the code. It should be very long and look nothing like what you made
- Note the name of the new entity and change it in your testbench if
necessary (it should still have the same inputs and outputs)
- re-simulate with this VHDL and there should be some very small
differences.
- Show this simulation to your TA
Generate the bit file and download unto an XS40 board
- Check out an XS40 board.
- Open up your project under Xilinx. Make sure that the names of
your variables match exactly with those in the UCF (User Constraints File).
- Right click on the root of your project and select "Edit
Constraints" and replace it with decoder.ucf.
- Now you can run through the Implementation stage and generate
a bit file as previously done in Lab 2a.
- Save the .bit file to your root directory.
- Make sure your XS40 board is powered up and connected to the
computer.
- Use putty to connect to "Local Machine"
- Type "export XSTOOLS_BIN_DIR=/bin/."
- Load you bit file by typing "xsload decoder.bit" on the
prompt (or whatever the name of your bit file is) and hit
"enter". Verify your results.
- Test your code by toggling the dip switches and making sure the correct number appears on the display.
- If it is working, demonstrate it to your TA
- E-mail your lab report and code for both your design and testbench to your TA.