User Defined Primitives:: Primitives Are Declared Outside The Module
User Defined Primitives:: Primitives Are Declared Outside The Module
Verilog has built in primitives like gates, transmission gates and switches.
If we want to go for complex primitives then Verilog provides UDP.
UDP are used to model sequential and combinational logic
Syntax:
Primitive <name_of_primitive> (Output_port, input_port 1, input_port 2. input_port 10)
Output <port_name>
Input <port_name>
//UDP Function
..
..
Endprimitive
PS:
Primitives are declared outside the module
UDP Port rules:
UDP Function:
The Function of the UDP starts by Verilog keywords table and ends with keyword endtable.
The functionality of the primitive must be defined in table.
Syntax:
table
//Functionality of the table
endtable
Example1:
Output:
Testbench:
Initial Statement:
In the table we can use special symbols like rising edge, falling edge . To represent the functionality of the
table.
Symbol
Interpretation
Explanation
0
0
Logic 0 on input or output
1
1
Logic 1 on input or output
x or X
x or X
Logic x or X on input or output
No change on output (Used in sequential UDP)
?
0 or 1 or x(X)
? can be 0 or 1 or x(X)
b or B
0 or 1
B or B can be 0 or 1 (X not included)
(vw)
(01), (10), (0X), (X0),
Input transition from logic v to logic w
(1,X), (X,1)
r or R
(01)
Rising input transition (rising edge on input)
f or F
(10)
Falling input transition (falling edge on input)
p or P
(01), (0X), (X1)
Positive input transition (Include x and z)
n or N
(10), (X0), (1X)
Negative input transition (Include x and z)
*
(??)
Any possible input transition
Combinational UDP:
endtable
endprimitive
Note:
The port order is very important in UDP.
The order of inputs in the table must corresponds to order of inputs in the port list of UDP in UDP header not
the port (Input) declaration.
Explicit declaration of ports cant be used in combinational UDP.
Sequential UDP:
Level sensitive:
The level sensitive sequential UDP is represented same as combinational UDP except the Output declaration.
Output in a sequential UDP is represented as reg
The output declared as reg means thats there is an internal state. Output of UDP is always same as internal
state
In level sensitive sequential UDP an extra field is inserted between input and output. The additional field
represents current state of UDP and considered equivalent to current output value.
Example 3:
Negative D latch
Output:
Positive D latch:
Output:
Different input
Edge sensitive:
Edge sensitive behaviour is similar to level sensitive behaviour except that raising or falling edge must be
specified on one of the input
It is illegal to specify more than one edge per line in table
Positive edge:
Output:
Negative edge:
Output:
Output:
Errors: