Ses2 Notes
Ses2 Notes
o compile directives
guildines to the compiler
ex: model sim,questa, vcs
`define SIZE 20
reg [`SIZE-1:0]a;
o macros can also have arguments
we can have same macros with diffrent reqirements
ex:
`define SIZE 20
`define SIZE 15// we cannot write teh same macro with
doffrent values
reg [`SIZE-1:0]a;
reg [`SIZE-1:0]b;
o `timescale
giving guildines to compiler how the simulation events to be executed
for ex:
it timestep is 10 ns
event execution interval is 10ns
o timestep
specifs the base unit of time for
each delay in the module
o timepresion
specifs the presion or the smallest
step of the time that can be simulated
for ex:
`timescale 1ns/1ps
#5; // defaukt time scale ,is 1ns
i.e 5 * 1ns
timeunit/timestep
every delay is interuppeted in ns
timeprecision
if the time precision is set to 1ps ,any delay
less than 1 ps will be roudeed of to zero , other cas eif it is larger than
1ps ,is roudeed to the nearest ps
ex:
// example for 2x1 mux in all abstraction levels(ecept switch level )
module compile_direct(i0,i1,s,y);
input i0,i1,s;
`ifdef BEHAV
output reg y;
`else
output y;
`endif
`ifdef BEHAV// bhv
always @(*)begin
y=s?i1:i0;
end
`elsif DATA//data
assign y=s?i1:i0;
`else
//gate
not g1(n1,s);
and g2(n2,n1,i0);
and g3(n3,s,i1);
or g4(y,n2,n3);
`endif
endmodule
o function
-> function must be executes in zero time only
-> function can enable(call) other function but not task
-> function can have only input arguments , and alleast one argument
-> function can return any value
-> syntax
function return_type func_name(i/p arguments );
begin
// statments
func_name=expression;
end
endfunction
=> guildines
-> decalaration must be outside the procedural block
-> call must be done from in procedural block
-> logic must be present between begin and end
o write a logic to get alu operation for two operands based on 2 bit control
signal using function
o Automatic
- if same task/ function is called multiple time ,executes happens in
diffrent memory location
- Generally used for where recursive function /task is required
o Static
- if same task/ function is called multiple time ,executes happens in same
memory location,existing values gets overriden
o by default task and functions are in static in nature in verilog
o to get automatic task/function we use automatic keyword in decaration
Q . fork join
statements inside procedural block executes sequentilly
all procedural will be executes in parallel
all procedural will be starts at zero time
ex:
#5;
initial begin
#5 a=10;
$display("");
end
o how many proceses?
-2
o how many statements inside proceses?
-2
o at what time display statements will executes?\
- 5 ns
o at what time a value is assigned ?
- 0ns
ex:
#5;
initial begin
fork
#5 a=10;
$display("");
join
end:P1
initial begin
fork
#5; b=10;
$display("");
join
end:P2
initial begin
fork
begin
#5;
end
b=10;
$display("");
join
end:P3
o at what time display statements will executes?\
- 0 ns
o at what time a value is assigned ?
- 5 ns
o at what time b value is assigned ?
- 0 ns
o how many statements inside p2?
-3
o what is the total time taken by p2?
- 5ns
o how many statements inside p3?
-3
o what is the total time taken by p3?
- 5ns
o how many proceses in p3?
-3