Exercise #1: Introduction to simulators and Synthesis


Course Home

Exercise Home

General Instruction

Before we start

Important part of this lab is to first read through the General instructions which should consist of all important notes about lab class, how to access the programs at home, coding conventions, defense of the lab and report requirements. Attending the lab means that you have agreed to the letter of commitment (so please read it carefully).

Important Note:

Please make sure you read Jiri Gaisler's "A structured VHDL design method". This document would be used as our coding reference throughout the labs.


Format of Exercises

Before coming into the exercise sessions, students are required to understand prerequisites for each session.

When the students arrive in the laboratory, they can be tested for following concepts for work,

Tools user guides and manuals

You can find the user guides and manuals for these labs here: One will be tested for these concepts. The list of all the required concepts will be given as part of the exercise session.

Simulation: multiplexer code modification

Task description: The purpose of this task is to become acquainted with simulation tool
ModelSim.To get familiar with a VHDL files mux.vhd and mux_tb.vhd which are offered to you.

Mux.vhd file is design file of multiplexer, which behavior is presented in Table 1. If the control signal CONT_SIG is '1' then the input A_IN is propagated to the output OUT_SIG, if the CONT_SIG is '0' then input B_IN is propagated to the output. The schematic of multiplexer is on Figure 1.

Also testbench for the multiplexer is available in the mux_tb.vhd. The idea of the testbench is to test the behavioral design in simulation by forcing input signals and observe output values.

Table 1: Behaviour of Mux.vhd
CONT_SIG value OUT_SIG value
1 A_IN
0 B_IN




Simulation Example

Figure 1. Multiplexer diagram

Simulation Example
Simulation example

Tasks

  1. Take the guide for ModelSim simulator and try to compile first design file mux.vhd. Also take the testbench file mux_tb.vhd. Simulate the design and check the behavior.

  2. Design mux.vhd contains errors. Fix the errors and make sure that the behavior of the design is correct.

  3. Repeat the simulations using: Xilinx ISE guide.

  4. Change the code so that instead of sensitivity list the process uses wait command. Make sure the code is correct by simulation. Choose a simulator you like best (ISE or ModelSim).

  5. Answer the questions.

  6. Continue with the Counter exercise.

Questions

  1. Explain the errors.

  2. What is the difference of entity and architecture?

  3. Can one entity have more than one architecture? Explain.

  4. Is it possible to get right waveforms of the signals during the simulation, even when your design contains behavioral errors? Give an example based on the lab.


Synthesis : Counter exercise for Blinking LED

Task description: The aim of this exercise is to understand how the flow of synthesis works. For this exercise following files are provided. Consider a counter as shown in the figure .
  1. counter.vhd: has the vhdl code for a 32 counter
  2. counter_tb.vhd: has the testbench to test the counter
  3. counter.ucf: has the pin configuration which are needed by the FPGA board. But the values are wrong. You have to change them to correct values before implementation otherwise it will destroy the board. Determine the input and output pins.

You are expected to learn how to synthesize a peice of code on an FPGA. You will learn how to do pin assignments on a FPGA. The counter used in this excercise has following signals:
  1. One bit input signal to reset the counter
  2. One bit input signal to enable the counter
  3. One bit input signal for the clock
  4. 32 bit internal signal for counter (which is not an I/O signal and hence will not be mentioned in UCF file).
  5. 1 bit output signal for blinking the LED
The UCF file only deals with Inputs and outputs description of the signals is explained in Table 2.

Simulate the counter and try to understand the code. The choice of the simulator is free.



Figure 1: Counter with enable and reset



Table 2: Counter I/O
Signal Type Description
clk input Clock signal. Counter counts on the rising edge of the clock signal.
rstr_n input When '0' then resets the counter to zero
ENABLE input If the enable signal is 1, counter is counting up, Otherwise counter is stopped.
LED output Represents the current output value of the counter (31st bit).
Assume that the counter is functionally verified so you can go straight to synthesis.

Tasks

  1. Create a new Project in Xilinx ISE and import the given VHDL files for counter. (counter.vhd, counter_tb.vhd, counter.ucf) A refrence guide on how to make a project is available here.
  2. Make a UCF file such that enable is connected to FPGA switches, rst_n is connected to button switch, led is connected to LED of the board and clk is connected to the clock pin of the FPGA board. To figure out what should be the correct pin use the NEXYS2 user manual . Specially look at page 4 and page 5. OR FPGA manual for Digilent Spartan 3E stater page 15,16, 19 and 20.
  3. You are free to choose any of the button, switches and LEDs available on the board. Change the properties of the project and change the family, device and package based on the board. HINT: look at the chip titled Xilinx.
  4. Synthesize the design
  5. As it can be seen there are a few warning. Resolve them by entering the correct signal in the sensitivity list. led signal needs to be assigned, assign the 24th bit of counter to it.
  6. Synthesize the design again, you will see few more warnings. This is because the bits of counter beyond the led output have no use and the synthesis tool realizes it. Change the dimentions of the counter to fix it.
  7. Once all the warnings are eliminated then implement the design.
  8. Before generating the bit file go

    right click on "Generate Programming File → Process Properties → Startup Options → Change FPGA startup clock to JTAG Clock.

  9. Generate the programming File (bit file). The process window in ise will look like the following screen shot. Then you will need to write the bitfile (counter.bit) into the FPGA using this guide.

    Figure 2: screenshot of finished implementation

  10. Read the FPGA manual for nexy2 specially look at the figure 8 (in the manual) or FPGA manual for Digilent Spartan 3E stater page 15,16, 19 and 20, to see how the buttons work. Now open the counter code and look at rst_n signal.
    1. Will the counter reset when the button is pressed?
      1. if yes, then press the button while the enable switch is on and explain the behaviour?
      2. if no, what should be changed to fix it?

  11. what is the clock frequency of the FPGA. Now change the vhdl code for counter.vhd which assigns led to look as follows
    led <= counter(22);
  12. Save the changes and repeat steps from 6 onwards. And try to answer the following questions.
    1. why did the LED frequency change?
    2. Can we make the LED blink Every one second?
      1. if yes, then why change should we do to the code to achieve it?
      2. if no, why? then what is the closest frequency to the requirement.

  13. Defend the lab orally and write a report. Requirements can be found here . The report must include both exercises (multiplexer and counter).