Lab7 - Behavioral Modeling and Timing Constraints
Lab7 - Behavioral Modeling and Timing Constraints
Objectives
After completing this lab, you will be able to:
• Use various language constructs using behavioral modeling
• Communicate timing expectations through timing constraints
process begin
target <= ‘1’;
wait for 20 ns;
target <= ‘0’;
end process;
Below is the example that illustrates the effect of the inter-statement delay:
process begin
wait for 5 ns; SIG1 <= 3;
wait for 4 ns; SIG1 <= 7;
wait for 2 ns; SIG1 <= 4;
end process;
The SIG1 signal will get the value of 3 at 5 ns, value of 7 at 9 ns, and value of 4 at 11 ns.
The above process statement will execute only when there is a change in value (an event) on a signal
test. The change in value defined in the std_logic type will trigger the block. When the event occurs, the
logical value of CLK will be flipped after 5 ns.
In the above examples, SUM is assigned 0 only when SUM is greater than 22, and DATA is assigned
whatever the value is on BUS when DATA_READY is asserted.
In RTL VHDL code, the assignment operator “<=” used is called non-blocking. The statement that uses
the non-blocking operator does not block the execution; however the assignment is scheduled to occur in
the future. When the non-blocking assignment is executed, the right-hand side expression is evaluated at
that time and its value is scheduled to be assigned to the left-hand side target and the execution
continues with the next statement. The non-blocking statements are widely used for content transfer
across multiple registers (often in parallel) when a desired clock event occurs.
So far we have seen constructs which allow generation of stimulus unconditionally. However, many times
we like to have different stimulus generation upon certain conditions. VHDL provides control altering
statements such as if, if … else, and if … elsif. All variations of the if statement need to
end with an end if. The general syntax of an if statement is:
if (condition-1) then
procedural_statement
[ elsif (condition-2) then
procedural_statement ]
[ else
procedural_statement ]
end if;
A begin…end block is not necessary for if statements. Any statements between if, if … else,
and if … elsif are considered to be part of the block
It is possible to have nested if statements. In such case, the else part is associated to the closest if
part. For example, below, the else part is associated to the if (RESET) condition,
The if statement is commonly used to create a priority structure, giving higher priority to the condition
listed first.
1-2. Write a behavioral model to design a 1-bit 4-to-1 mux using the if-else-if
statement. Develop a testbench to verify the design.
Another widely used statement is a case statement. The case statement is generally used when we
want to create a parallel structure (unlike priority). Case statements are commonly used in creating finite
state machines. The syntax of the case statement is:
case [ case_expression] is
when case_item_expression => procedural_statement;
…
…
when others => procedural_statement;
end case;
The case_expression is evaluated first (whenever there is an event on it), and the value is matched with
the case_item_expr in the order they are listed. When the match occurs, the corresponding
procedural_statement is executed. Like the if statement, multiple procedural statements are enclosed
between “=>” and the next “when” statement, no begin … end blocks are needed. The others case
covers all values that are not covered by any of the case_item_expr.
1-3. Design a gray code generator using the case statement. The design will
take a 4-bit BCD input through SW3-SW0 and will output the corresponding
gray code value on the four LEDS, LED3-LED0, provided that the enable
input on SW4 is TRUE. If the enable input is FALSE or the input is not BCD
then LED3-LED0 should all be turned ON and LED4 should also be turned
ON. Look at the Project Summary report and make sure that no latches or
registers resources are used.
VHDL testbenches also support various loop statements to do the same function a number of times. The
supported loop statements are:
basic loop
while loop
for loop
The basic loop statement is used when the procedural statement(s) need to be executed continuously.
Some kind of timing control must be used within the procedural statement if a periodic output is desired.
For example, to generate a clock of 20 units period, the following code can be used:
The while loop statement’s procedural statement(s) are executed until certain conditions become false.
1-4. Write a model of a counter which counts in the sequence mentioned below.
The counter should use behavioral modeling and a case statement.
Develop a testbench to test it. The testbench should display the counter
output in the simulator console output. Simulate using the clock period of
10 units for 200 ns. 000, 001, 011, 101, 111, 010, (repeat 000). The counter
will have an enable signal (SW2), a reset signal (SW1), and a clock signal
(SW15). The output of the counter will be on LED2-LED0.
set_property CLOCK_DEDICATED_ROUTE FALSE [get_nets { clk }];
Add the above code to the XDC file and set the clock as SW15.
In the above figure, the paths which are covered between ADATA input and D port of FLOP1, BUS input
and D port of FLOP4 can be constrained by a constraint called SET_INPUT_DELAY command. The
set_input_delay command indicates how much time is spent between the Q output of a FF in the
upstream device, the routing delay in the upstream device as well as the board delay. The tools will
subtract that delay from the clock period of the clock signal listed in the command and will use the
resulting delay to place and route the path between the input and the D input of FF. It will also consider
delay experienced by the clock arriving to the clock port of the destination FF (e.g. FLOP1 in the above
diagram). The max and min qualifiers are used for the setup and hold checks.
The paths between the port Q of FLOP3 and output OUT1, Q port of FLOP5 and OUT1, Q port of FLOP5
and OUT2 can be constrained by SET_OUTPUT_DELAY command. Again, the delay mentioned
indicates how much delay is spent in the board delay, routing delay and the setup delay of the FF in the
downstream device.
The paths between CDATA and OUT2 can be constrained by the SET_MAX_DELAY constraint.
The paths between Q port of FLOP1 and D port of FLOP2, Q port of FLOP2 and D port of FLOP3, Q port
of FLOP4 and D port of FLOP5 can be constrained by the period constraint. The period constraint is
created using the create_clock command. The create_clock command may refer ot a pin of the FPGA
design or may not refer any pins. When the clock pin is not referred, a virtual clock will be created. When
the pin is referred, the period parameter indicates rising to rising edge delay and waveform option
indicates when the rising edge occurs and the second number indicates when the falling edge occurs.
The waveform option can be used to create clocks of non-50% duty cycle and/or phase delayed clock
signal.
Note that the clock period is defined at 10 ns. This is applied throughout the example for consistency.
Further details on the syntax of each constraint type can be found in UG903, the Vivado Using
Constraints Guide.
Conclusion
In this lab you learned about various constructs available in behavioral modeling. You also learned about
blocking and non-blocking operators as well as concepts and the need of timing constraints. Providing
the timing constraints to the implementation tools the generated output can be made to meet the design’s
timing specifications.