Featured post

Top 5 books to refer for a VHDL beginner

VHDL (VHSIC-HDL, Very High-Speed Integrated Circuit Hardware Description Language) is a hardware description language used in electronic des...

Sunday, 9 September 2012

min:typ:max Delays

Formal Definition

Delays can be specified for minimum, typical, and maximum propagation times.

Simplified Syntax

#(min:typ:max)

#(min:typ:max, min:typ:max)

#(min:typ:max, min:typ:max, min:typ:max)

Description

Delays can be specified with three values for each delay. These values describe minimum, typical and maximum propagation times (Example 1).

The min:typ:max values can be any constant value.

The min:typ:max values can be specified for delay control in procedural statements (Example 2).

Examples

Example 1

assign #(1:2:3) out = in1 & in2;
assign #(1:2:3,2:3:4) b = ~a;
assign #(1:5:7,2:3:4,3:5:7) w_or = |bus;

The min:typ:max values specified for one, two and three delay values.

Example 2

initial #(1:2:3) a = 5;

Important Notes

· There is no relation between min, typ, and max value.

· A simulation switch selects which of the three values is to be used. The default is typ.


Memories

Formal Definition

Memories are arrays of registers.

Simplified Syntax

reg memory_width memory_identifier memory_depth;

integer memory_identifier memory_length;

time memory_identifier memory_length;

Description

Memories can be declared only for reg, integer and time data types. Depth of memory should be declared by specifying a range following the memory identifier (Example 1). Registers and memories can be declared in the same line (Example 2). Elements of memory type can be accessed by memory index (Example 3). An assignment to a memory identifier without specified memory index is illegal. Bit-selects and part-selects on memory elements are not allowed. If access to individual bits of memory is needed, then a word containing that bit should be assigned to a register with the same width. All operations should then be done on this register and the result should be assigned back to the memory word (Example 5). Memory words can be accessed individually, but bit-select and part-select operations cannot be done on memories or memory words directly.

Vector declaration and memory declaration are not the same. If a variable is declared as a vector, all bits can be assigned a value in one statement. If a variable is declared as memory then a value to each element should be assigned separately (Example 4).

Examples

Example 1

reg [7:0] mem[1023:0];
integer i_mem[8:1];

The 'mem' variable is a memory that contains 1024 8-bit words.

The 'i_mem' variable has 8 words (each word is an integer register).

Example 2

reg [3:0] mem[255:0], r;

This line a declares 4-bit register 'r' and memory 'mem', which contains 256 4-bit words.

Example 3

reg [7:0] mem [3:0], r;
mem[0] = 7;
r = mem[3];
mem[1] = r;

Example 4

reg [7:0] vect;
reg array[7:0];
vect = 8'b11001010;
array[7] = 1'b1;
array[6] = 1'b1;
array[5] = 1'b0;
array[4] = 1'b0;
array[3] = 1'b1;
array[2] = 1'b0;
array[1] = 1'b1;
array[0] = 1'b0;

If the variable is declared as a vector (variable vect), then the new value can be assigned to all bits at the same time. If a variable is declared as a memory (variable array) type, then the new value should be assigned to each element of memory separately.

Example 5

reg [7:0] mem[255:0], r;
r = mem[135];
r[3:1] = 3'b100;
mem[135] = r;

This example shows how to access particular bits of memory.

Important Notes

· Memories can be declared only for reg, integer and time registers types.

· Bit-selects and part-selects on memory elements are prohibited.


Loop Statements

Formal Definition

Loop statements provide a means of modeling blocks of procedural statements.

Simplified Syntax

forever statement;

repeat (expression) statement;

while (expression) statement;

for (assignment; expression; assignment) statement;

Description

There are four types of loop statements: forever, repeat, while, and for statements.

The forever instruction (Example 1) continuously repeats the statement that follows it. Therefore, it should be used with procedural timing controls (otherwise it hangs the simulation).

The repeat instruction (Example 2) executes a given statement a fixed number of times. The number of executions is set by the expression, which follows the repeat keyword. If the expression evaluates to unknown, high-impedance, or a zero value, then no statement will be executed.

The while instruction (Example 3) executes a given statement until the expression is true. If a while statement starts with a false value, then no statement will be executed.

The for instruction (Example 4) executes a given statement until the expression is true. At the initial step, the first assignment will be executed. At the second step, the expression will be evaluated. If the expression evaluates to an unknown, high-impedance, or zero value, then the for statement will be terminated. Otherwise, the statement and second assignment will be executed. After that, the second step is repeated.

Examples

Example 1

always begin
  counter = 0;
  forever #10 counter = counter + 1;
end

Example 2

initial begin
  repeat (10) a = a + ~b;
end

Example 3

module test;
parameter MSB = 8;
reg [MSB-1:0] Vector;
integer t;
initial

begin
  t = 0;
  while (t < MSB)
    begin
      //Initializes vector elelments
      Vector[t] = 1'b0;
      t = t + 1;
    end
end
endmodule

Example 4

initial begin
  for (index=0; index < 10; index = index + 2)
  mem[index] = index;
end

Important Notes

· The forever statement should contain at least one procedural timing control.


Keywords

Formal Definition

Keywords are reserved identifiers, which are used to define language constructs.

List of keywords

always
and
assign
begin
buf
bufif0
bufif1
case
casex
casez
cmos
deassign
default
defparam
disable
edge
else
end
endcase
endfunction
endmodule
endprimitive
endspecify
endtable
endtask
event
for
force
forever
fork
function
highz0
highz1

if
initial
inout
input
integer
join
large
macromodule
medium
module
nand
negedge
nmos
nor
not
notif0
notif1
or
output
pmos
posedge
primitive
pull0
pull1
pulldown
pullup
rcmos
reg
release
repeat
rnmos
rpmos
rtran

rtranif0
rtranif1
scalared
small
specify
specparam
strong0
strong1
supply0
supply1
table
task
time
tran
tranif0
tranif1
tri
tri0
tri1
triand
trior
vectored
wait
wand
weak0
weak1
while
wire
wor
xnor
xor

Description

The keywords are reserved identifiers, which contain only lowercase letters. The user cannot redefine any of them.


Intra-assignment Timing Controls

Formal Definition

The intra-assignment timing controls are procedural timing controls, which can be used inside procedural assignments.

Simplified Syntax

register = delay_control expression;

register <= delay_control expression;

register = event_control expression;

register <= event_control expression;

register = repeat (expression) @(event) expression;

register <= repeat (expression) @(event) expression;

Description

All intra-assignment timing controls should be used with procedural assignments. They can be used with blocking and non-blocking assignments. If a statement with intra-assignment timing controls is encountered during simulation, an expression will be evaluated and its value will be stored. Then, the execution of the statement will be suspended until the time specified by the delay control expires or an event specified by the event control occurs. Changes in the expression value up to the time of the event will be ignored. Next, the stored value will be assigned to the register.

Type

Assignment

Equivalent

Delay with assignment

#5 a = b;

#5;
a = b;

Intra-assignment

a = #5 b;

temp = b;
#5;
a = temp;

Table 7 Differences beetwen delays and intra-assignment timing control

A delay with an assignment works differently. An assignment will be delayed and then the current value of expression will be assigned.

The repeat expression specifies how many occurrences of an event should appear before the assignment takes place (Example 3).

Examples

Example 1

r_out = #10 inputA;

This is the same as:

temp = inputA;
#10;
r_out = temp;

Example 2

q = @(posedge clk) d;

This is the same as:

temp = d;
@(posedge clk);
q = temp;

Example 3

a = repeat (5) @(ready) b & c;

This is the same as:

Temp = b & c;
@(ready);
@(ready);
@(ready);
@(ready);
@(ready);
a = temp;

Important Notes

  • If a statement contains intra-assignment timing controls, its right hand side expression is evaluated and its value is assigned after the time specified by the delay control or after an event specified by event control.

Integer Constants

Formal Definition

The integer constants are used to specify numbers.

Simplified Syntax

sign size 'base number

Description

Integer constants can be specified as unsized numbers (Example 1) or as sized numbers (Example 2). Sign, size and base are optional and they can be separated by white spaces. If none are used, then a number is positive and a decimal. Size should be a positive constant value (decimal number) and it specifies number of bits used for the integer. The base format should contain two characters: apostrophe (') and a base identifier. The base identifier and apostrophe cannot be separated by any white space. Legal base specifications are d and D for decimal numbers, h and H for hexadecimal numbers, o and O for octal numbers, b and B for binary numbers.

Decimal numbers can contain only digits and underscores (_). Binary numbers can contain only 0, 1, unknown values (x and X), high-impedance values (z and Z) and underscores. Each character in a binary number has 1 bit. Octal numbers can be specified using 0, 1, 2, 3, 4, 5, 6, 7, unknown values (x and X), high-impedance values (z and Z) and underscores. Each character in an octal number has a 3 bit equivalent. Legal characters for hexadecimal numbers are unknown values (x and X), high-impedance values (z and Z), digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), letters (a, A, b, B, c, C, d, D, e, E, f, F) and underscores. Each character in a hexadecimal number has a 4 bit equivalent.

Decimal numbers without the base format and size specified are treated as signed integers, but decimal numbers with base format are treated as unsigned integers (see Arithmetic expressions with registers and integers for more details).

If a specified number is bigger than a specified size constant, then the most significant bits of numbers will be truncated. If number is smaller than the size constant, then it will be padded to the left with zeros. If the most significant bit of a specified number has an unknown (x) or high-impedance (z) value, then that value will be used to pad to the left (Example 3).

Underscore character (_) is ignored and can be used to enhance readability. It cannot be the first character in number.

The question mark (?) can be used in specifying numbers with high-impedance value (z) and is very useful in case statements.

Examples

Example 1

15
'h f
'o 17
'd 15
'b 1111
'b 1_1_1_1

All the above numbers are equal. The first number is a decimal number without the base specified, the second one is a hexadecimal number, the third is an octal number, the fourth is a decimal number with base specified, and the fifth and sixth are binary numbers.

Example 2

-5'b1_1011
10 'd 20
8'h z
6'o 71

Examples of sized integers.

Example 3

8'b0 is equal to 8'b00000000
8'b1 is equal to 8'b00000001
8'bz is equal to 8'bzzzzzzzz
8'bx is equal to 8'bxxxxxxxx

Examples of padding to the left.

Important Notes

· Decimal numbers without specified size and base format are treated as signed integers.

· Decimal numbers with the base format specified are treated as unsigned integers.


If Statement

Formal Definition

The if statement is used to choose which statement should be executed depending on the conditional expression.

Simplified Syntax

if (conditional expression)

  statement1;

else

  statement2;

if (conditional expression)

  statement1;

else if (conditional expression)

  statement2;

else

  statement3;

Description

The 'if' statement can be used in two ways: as a single 'if-else' statement (Example 1) or as a multiple 'if-else-if' statement (nested if statement - Example 2).

In the first case when the conditional expression is evaluated to true (or non-zero), then statement1 is executed and if condition is false (or zero), then statement2 is executed.

In the second case, if the first conditional expression is evaluated to be true, then statement1 is executed. Otherwise, the second conditional expression is evaluated and depending on its values, statement2 or statement3 is executed.

Every statement can be a group of statements (enclosed in a begin-end block - Example 3) or a null statement (; - Example 4). The conditional expression can be any valid expression.

Examples

Example 1

if (a == 5)
  b = 15;
else
  b = 25;

If 'a' is 5 then 'b' will be 15. Otherwise 'b' will be 25.

Example 2

if (a)
  b = 4;
else if (d)
  b = 5;
else
  b = 1;

If 'a' has non-zero value then 'b' will be 4.

If 'a' is 0 and 'd' has non-zero value then 'b' will be 5.

If 'a' is 0 and 'd' is 0 then 'b' will be 1.

Example 3

if (a)
  begin
  counter = counter + 1;
  data_out = counter;
  end
else
  data_out = 8'bz;

If 'a' has non-zero value then the counter variable will be incremented and a new counter value will be assigned to data_out variable. Otherwise, data_out bits will be assigned a high-impedance value.

Example 4

if ( counter > 10)
;
else
counter = counter + 1;

If counter value is bigger than 10, then it will stop (execute a null statement - ;). If the counter value is less than 10 then it will be incremented by 1.

Important Notes

  • The if statement can be nested.