Sequential Statements in VHDL

VHDL Programming



Sequential statements exist inside the boundaries of a process statement as well as in subprograms. In this chapter, we are most concerned with sequential statements inside process statements. In Other post , we will discuss subprograms and the statements contained within them.


The sequential statements that we discuss are:

  • IF
  •  CASE
  • LOOP
  • EXIT
  • WAIT 

IF Statements : 


The description of the IF statement looks like this:


IF statement starts with the keyword IF and ends with the keywords END IF spelled out as two separate words. There are also two optional clauses: the ELSIF clause and the ELSE clause. The ELSIF clause is repeatable—more than one ELSIF clause is allowed; but the ELSE clause is optional, and only one is allowed. The condition construct in all cases is a boolean expression. This is an expression that evaluates to either true or false. Whenever a condition evaluates to a true value, the sequence of statements following is executed. If no condition is true, then the sequence of statements for the ELSE clause is executed, if one exists.

Let’s analyze a few examples to get a better understanding of how the it relates to the VHDL code.
The first example shows how to write a simple IF statement:


The IF statement starts with the keyword IF. Next is the condition (x < 10), followed by the keyword THEN. The condition is true when the value of x is less than 10; otherwise it is false. When the condition is true, the statements between the THEN and END IF are executed. In this example, the assignment statement (a := b) is executed whenever x is less than 10. What happens if x is greater than or equal to 10 ? In this example, there is no ELSE clause, so no statements are executed in the IF statement. Instead,control is transferred to the statement after the END IF.

Let’s look at another example where the ELSE clause is useful:


In this example, there are two variables—weekend and weekday—that are set depending on the value of a signal called day. Variable weekend is set to TRUE whenever day is equal to saturday or sunday. Otherwise, variable
weekday is set to TRUE. The execution of the IF statement starts by checking to see if variable day is equal to sunday. If this is true, then the next statement is executed and control is transferred to the statement following END IF. Otherwise, control is transferred to the ELSIF statement part, and day is checked for saturday. If variable day is equal to Saturday, then the next statement is executed and control is again transferred to the statement following the END IF statement. Finally, if day is not equal to sunday or saturday, then the ELSE statement part is executed. The IF statement can have multiple ELSIF statement parts, but only one ELSE statement part. More than one sequential statement can exist between each statement part.



CASE Statements :

The CASE statement is used whenever a single expression value can be used to select between a number of actions.


A CASE statement consists of the keyword CASE followed by an expression and the keyword IS. The expression either returns a value that matches one of the CHOICES in a WHEN statement part, or matches an OTHERS clause. If the expression matches the CHOICE part of a WHEN choices => clause, the sequence_of_statements following is executed. After these statements are executed, control is transferred to the statement following the END CASE
clause. Either the CHOICES clause must enumerate every possible value of the type returned by the expression, or the last choice must contain an OTHERS clause.

Examples :

The CASE statement executes the proper statement depending on the value of input instruction. If the value of instruction is one of the choices listed in the WHEN clauses, then the statement following the WHEN clause is executed. Otherwise, the statement following the OTHERS clause is executed. In this example, when the value of instruction is load_accum, the first assignment statement is executed. If the value of instruction is load or store, the process_IO procedure is called. If the value of instruction is outside the range of the choices given, then the OTHERS clause matches the expression and the statement following the OTHERS clause is executed. It is an error if an OTHERS clause does not exist, and the choices given do not cover every possible value of the expression type.

Example :

This example shows one way to convert an array of bits into an integer. When both bits of variable bit_vec contain ‘0’ values, the first choice “00” matches and the value 0 is returned. When both bits are ‘1’ values, the value 3, or “11”, is returned. This CASE statement does not need an OTHERS clause because all possible values of variable bit_vec are enumerated by the choices.



LOOP Statements :

The LOOP statement is used whenever an operation needs to be repeated. LOOP statements are used when powerful iteration capability is needed to implement a model.


The LOOP statement has an optional label, which can be used to identify the LOOP statement. The LOOP statement has an optional iteration_scheme that determines which kind of LOOP statement is being used. The iteration_scheme includes two types of LOOP statements: a WHILE condition LOOP statement and a “FOR identifier IN discrete_range” statement. The FOR loop loops as many times as specified in the discrete_range, unless the loop is exited. The WHILE condition LOOP statement loops as long as the condition expression is TRUE.

Let’s look at a couple of examples to see how these statements work:

This example uses the WHILE condition form of the LOOP statement. The condition is checked each time before the loop is executed. If the condition is TRUE, the LOOP statements are executed. Control is then transferred back to the beginning of the loop. The condition is checked again. If TRUE, the loop is executed again; if not, statement execution continues on the statement following the END LOOP clause.
The other version of the LOOP statement is the FOR loop:

This loop executes 10 times whenever execution begins. Its function is to calculate the squares from 1 to 10 and insert them into the i_squared signal array. The index variable i starts at the leftmost value of the range and is incremented until the rightmost value of the range. In some languages, the loop index (in this example, i) can be assigned a value inside the loop to change its value. VHDL does not allow any assignment to the loop index. This also precludes the loop index existing as the return value of a function, or as an out or inout parameter of a procedure.
Another interesting point about FOR LOOP statements is that the index value i is locally declared by the FOR statement. The variable “i” does not need to be declared explicitly in the process, function, or procedure. By virtue of the FOR LOOP statement, the loop index is declared locally. If  another variable of the same name exists in the process, function, or procedure, then these two variables are treated as separate variables and are accessed by context.

Let’s look at an example to illustrate this

Whenever the value of the signal i in the process sensitivity list changes value, the process will be invoked. The first statement schedules the value i + 1 on the signal x. Next, the FOR loop is executed. The index value i is not the same object as the signal i that was used to calculate the new value for signal x.



NEXT Statement :

There are cases when it is necessary to stop executing the statements in the loop for this iteration and go to the next iteration. VHDL includes a construct that accomplishes this. The NEXT statement allows the designer to stop processing this iteration and skip to the successor. When the NEXT statement is executed, processing of the model stops at the current point and is transferred to the beginning of the LOOP statement. Execution begins with the first statement in the loop, but the loop variable is incremented to the next iteration value. If the iteration limit has been reached, processing stops. If not, execution continues.
Following is an example showing this behavior:


The process statement contains one LOOP statement. This LOOP statement logically “and”s the bits of arrays a and b and puts the results in array q. This behavior continues whenever the flag in array done is not true. If the done flag is already set for this value of index i, then the NEXT statement is executed. Execution continues with the first statement of the loop, and index i has the value i + 1. If the value of the done array is not true, then the NEXT statement is not executed, and execution continues with the statement contained in the ELSE clause for the IF statement. The NEXT statement allows the designer the ability to stop execution of this iteration and go on to the next iteration. There are other cases when the need exists to stop execution of a loop completely. This capability is provided with the EXIT statement.



EXIT Statement :

During the execution of a LOOP statement, it may be necessary to jump out of the loop. This can occur because a significant error has occurred during the execution of the model or all of the processing has finished early. The VHDL EXIT statement allows the designer to exit or jump out of a LOOP statement currently in execution. The EXIT statement causes execution to halt at the location of the EXIT statement. Execution continues at the statement following the LOOP statement.
Example :


Inside this process statement, the value of int_a is always assumed to be a positive value greater than 0. If the value of int_a is negative or zero, then an error condition results and the calculation should not be completed. If the value of int_a is less than or equal to 0, then the IF statement is true and the EXIT statement is executed. The loop is immediately terminated, and the next statement executed is the assignment statement to y after the LOOP statement.



ASSERT Statement :

The ASSERT statement is a very useful statement for reporting textual strings to the designer. The ASSERT statement checks the value of a boolean expression for true or false. If the value is true, the statement does nothing. If the value is false, the ASSERT statement outputs a userspecified text string to the standard output to the terminal.

ASSERT condition
[REPORT expression]
[SEVERITY expression];

The keyword ASSERT is followed by a boolean-valued expression called a condition. The condition determines whether the text expression specified by the REPORT clause is output or not. If false, the text expression is output; if true, the text expression is not output.
There are two optional clauses in the ASSERT statement. The first is the REPORT clause. The REPORT clause gives the designer the ability to specify the value of a text expression to output. The second is the SEVERITY clause.
The SEVERITY clause allows the designer to specify the severity level of the ASSERT statement. If the REPORT clause is not specified, the default value for the ASSERT statement is assertion violation. If the SEVERITY clause is not specified, the default value is error.





The process makes use of three local variables to record the time and last value of signal din as well as the value of the clk signal. By storing the last value of clk and din, we can determine if the signal has changed value or not. By recording the last time that din changed, we can measure from the current time to the last din transition to see if the setup time has been violated or not. Whenever din or clk changes, the process is invoked. The first step in the process is to see if the din signal has changed. If it has, the time of the transition is recorded using the predefined function NOW. This function returns the current simulation time. Also, the latest value of din is stored for future checking. The next step is to see if signal clk has made a transition. If the last_clk_value variable is not equal to the current value of clk, then we know that a transition has occurred. If signal clk is a ‘1’ value, then we know that a rising edge has occurred. Whenever a rising edge occurs on signal clk, we need to check the setup time for a violation. If the last transition on signal d was less than 20 nanoseconds ago, then the expression:

(NOW – last_D_change)
returns a value that is less than 20 nanoseconds. The ASSERT statement triggers and reports the assertion message setup violation as a warning to the designer. If the last transition on signal d occurred more than 20 nanoseconds in the past, then the expression returns a value larger than 20 nanoseconds and the ASSERT statement does not write out the message. Remember, the ASSERT statement writes out the message when the assert
condition is false.



WAIT Statements :

The WAIT statement gives the designer the ability to suspend the sequential execution of a process or subprogram. The conditions for resuming execution of the suspended process or subprogram can be specified by the following three different means:
WAIT ON signal changes
WAIT UNTIL an expression is true
WAIT FOR a specific amount of time

WAIT statements can be used for a number of different purposes. The most common use today is for specifying clock inputs to synthesis tools. The WAIT statement specifies the clock for a process statement that is read by synthesis tools to create sequential logic such as registers and flip-flops. Other uses are to delay process execution for an amount of time or to modify the sensitivity list of the process dynamically. Let’s take a look at a process statement with an embedded WAIT statement that is used to generate sequential logic:

This process is used to generate a flip-flop that clocks the value of d into q when the clock input has a rising edge. The attribute ‘EVENT attached to input clock is true whenever the clock input has had an event during the current delta timepoint.  The combination of looking for a ‘1’ value and a change on clock creates the necessary functionality to look for a rising edge on input clock. The effect is that the process is held at the WAIT statement until the clock has a rising edge. Then the current value of d is assigned to q. Reading this description into a synthesis tool creates a D flip-flop without a set or reset input. A synchronous reset can be created by the following:

When the clock occurs, the reset signal is tested first. If it is active, then the reset value (‘0’) is assigned to q; otherwise, the d input is assigned. Finally, an asynchronous reset can be added as follows:


This process statement contains a WAIT ON statement that causes the process to halt execution until an event occurs on either reset or clock. The IF statement is then executed and, if reset is active, the flip-flop is
asynchronously reset; otherwise, the clock is checked for a rising edge with which to transfer the d input to the q output of the flip-flop. A WAIT statement can also be used to control the signals a process or subprogram
is sensitive to at any point in the execution.

Here is an example:


Check This Post also for WAIT Statement :

VHDL – WAIT ON Signal 

VHDL – WAIT UNTIL Expression

VHDL – WAIT FOR Time Expression 


You Need "Sequential Statements in VHDL" ???

"Sequential Statements in VHDL" (Source Code / Report / PPT) Totally belong to CodingTalks Team and We always ready to Share our Stuff with our users. If you are Very Much Interested on This Topic Then you must Leave a Comment what Exactly you Looking For Or Send us Email to get Full Information.

Coding Talks

Filed in: VHDL Tags: , , , , , , , , , ,

Get Updates

Share This Post

Related Posts

One Response to "Sequential Statements in VHDL"

Leave a Reply

Submit Comment

© 5453 CodingTalks. All rights reserved.

Warning: filemtime(): stat failed for /home/codingtalks/public_html/wp-content/plugins/floating-social-share-bar//js/waypoints.min.js in /home/codingtalks/public_html/wp-content/plugins/floating-social-share-bar/floatingshare.php on line 213