Escolar Documentos
Profissional Documentos
Cultura Documentos
Mano 3-9
Hardware Description Language
J.J. Shann
2 leading HDLs:
Verilog ()
VHDL
J.J. Shann HDL-6
Verilog
file name: .v
SystemVerilog: (*)
Modules
Module
(a block of
hardware)
..
.
Outputs
Module:
Inputs
..
.
Design entry
Timing verification
Logic synthesis
Fault simulation
Logic Simulation
Simulation:
inputs
output
Figure 4.1 Simulation waveforms
J.J. Shann HDL-10
Logic Synthesis
Synthesis:
y = abc + abc
+ abc
= bc + ab
Figure 4.2 Synthesized circuit
Outputs
Testbench:
contains code to apply inputs to a module, check whether
the output results are correct, and print discrepancies b/t
expected and actual outputs.
* Testbench code is intended only for simulation and cannot
be synthesized.
A. Module Declaration
Gate-level modeling:
Verilog Model
Verilog model:
Keywords:
Comments:
// : single-line comment
/* */ : multiline comments
Module
Module:
.v
and
G1(w1,A,B);//Optionalgateinstancename
not
G2(E,C);
or
G3(D,w1,E);
endmodule
* Concurrence
J.J. Shann HDL-16
Identifiers:
are names given to modules, variables, and other elements
of the language for reference in the design
are composed of alphanumeric characters and the
underscore _ , but can not start w/ a number.
are case sensitive
* Choose meaningful names for modules.
Gate Delays
.v
and
#(30)G1(w1,A,B);
not
#(10)G2(E,C);
or
#(20)G3(D,w1,E);
endmodule
Testbench
Outputs
Stimuli
..
.
Instantiation
of module(s)
..
. Response
J.J. Shann HDL-21
HDL
Example 3.3 :
Testbench
(p.130)
Testbench of
HDL
Example 3.2
module t_Simple_Circuit_prop_delay;
wire D,E;
The inputs to the ckt are declared w/ reg
reg A,B,C; & the outputs are declared w/ wire.
//instantiatedeviceundertest
Simple_Circuit_prop_delay M1(A,B,C,D,E);
an instantiation of the
.v
a signal generator
* The statements are
executed in sequence.
J.J. Shann HDL-22
initial statement:
executes the statements
in its body at the start of
simulation
* should be used only in
testbenches for
simulation
begin, end
$finish: terminate the simulation
reg: declares signals in initial statements
30
10
20
Simulation waveforms:
B. Boolean Expressions
Logic operators:
Operator
bitwise
logical
AND
&
&&
OR
||
NOT
E.g.:
assignD=(A&&B)||(!C);
J.J. Shann HDL-25
AND
&
&&
OR
||
NOT
.v
assign E= A||(B&&C)||((!B)&&D);
assign F= ((!B)&&C)||(B&&(!C)&&(!D));
endmodule
assign statement: describe combinational logic
* The simulator detects when the test bench changes a value of
one or more of the inputs and updates the vales of the outputs.
system primitives:
HDL Example
3.5: User-Defined
Primitive
(p.133)
Define UPD_02467
D(A, B, C)
= m(0, 2, 4, 6, 7)
.v
primitive UDP_02467(D,A,B,C);
output D;
input
A,B,C;
//TruthtableforD=f(A,B,C)=m(0,2,4,6,7);
table
// A B C : D //Columnheadercomment
0 0 0 : 1;
0 0 1 : 0;
0 1 0 : 1;
0 1 1 : 0;
1 0 0 : 1;
1 0 1 : 0;
1 1 0 : 1;
1 1 1 : 1;
endtable
endprimitive
J.J. Shann HDL-29
.v
//Verilogmodel:CircuitinstantiationofCircuit_UDP_02467
module Circuit_with_UDP_02467(e,f,a,b,c,d);
output e,f;
input
a,b,c,d;
UDP_02467 M0(e,a,b,c);
and (f,e,d);
//Optiongateinstancenameomitted
endmodule
J.J. Shann HDL-30
Mano 4-12
HDL Models of Combinational
Circuits
J.J. Shann
Module:
describes a ckt by specifying its gates and how they are connected w/
each other
Figure 4.31
Relationship of Verilog
constructs to truth tables,
Boolean equations, and
schematics
A. Gate-Level Modeling
Gate-level modeling:
* The output of a
primitive is always listed
first in the port list,
followed by the inputs.
4-Valued System
0
1
x: unknown
z: high impedance
HDL Example
4.1: 2-to-4 Line
Decoder
enable
gate-level
description of
Fig 4.19
module decoder_2x4_gates(D,A,B,enable);
output [0:3] D;
input
A,B;
input
enable;
wire
A_not,B_not,enable_not;
not
The keyword not may
be written only once for
G1(A_not,A),
the three gates.
G2(B_not,B),
G3(enable_not,enable);
nand
G4(D[0],A_not,B_not,enable_not),
G5(D[1],A_not,B,enable_not),
G6(D[2],A,B_not,enable_not),
G7(D[3],A,B,enable_not);
J.J. Shann HDL-37
endmodule
vector:
E.g.:
Half adder (HA): add two bits, 1 XOR gate + 1 AND gate
Full adder (FA): add three bits, 2 HAs + 1 OR gate
n-bit ripple-carry adder (RCA): add 2 n-bit numbers, n FAs
E.g.:
n-bit ripple-carry adder (RCA) n full adders (FAs)
Full adder 2 half adders (HAs) + 1 OR gate
Half adder 1 XOR gate + 1 AND gate
J.J. Shann HDL-39
gate-level description
bottom-up
hierarchical
description:
HA FA RCA
HA: Fig 4.5(b)
//Descriptionofhalfadder
//modulehalf_adder (S,C,x,y);
// output S,C;
// input
x,y;
//AlternativeVerilog2005syntax:
module half_adder (output S,C,input x,y);
//Instantiateprimitivegates
xor (S,x,y);
and (C,x,y);
endmodule
J.J. Shann HDL-40
S1
C1
C2
HA module
//Descriptionoffulladder
//modulefull_adder (S,C,x,y,z);
// output S,C;
// input
x,y,z;
//alternativeVerilog2005syntax:
module full_adder (output S,C,input x,y,z);
wire
S1,C1,C2;
//Instantiatehalfadders
half_adder HA1(S1,C1,x,y);
half_adder HA2(S,C2,S1,z);
or G1(C,C2,C1);
J.J. Shann HDL-41
endmodule
4-bit RCA:
Fig 4.9
FA module
//Descriptionof4bitadder(seeFig49)
//moduleripple_carry_4_bit_adder(Sum,C4,A,B,C0);
// output[3:0] Sum;
// output
C4;
// input[3:0] A,B;
// input
C0;
//AlternativeVerilog2005syntax:
B. Three-State Gates
Three-state gate:
has a control input that can place the gate into a highimpedance state (z).
bufif1, bufif0,
notif1, notif0
are instantiated w/ the statement
gate name (output, input, control);
In simulation, the output can result in 0, 1, x, or z.
The outputs of 3-state gates can be connected together to
form a common output line.
J.J. Shann HDL-44
bufif1 (m_out,A,select);
Instantiate of a 3-state
bufif0 (m_out,B,select);
gate:
endmodule
gate name (output, input, control);
J.J. Shann HDL-45
wired-AND
ground (0)
Bitwise Logical
C. Dataflow Modeling
Dataflow modeling:
AND
&
&&
OR
||
NOT
Bitwise Logical
AND
&
&&
OR
||
NOT
Bitwise Logical
AND
&
&&
OR
||
NOT
OR
||
NOT
Y SA S B
J.J. Shann HDL-53
enable
Bitwise Logical
AND
&
&&
OR
||
NOT
assign D[0]=!((!A)&&(!B)&&(!enable)),
D[1]=!((!A)&&B&(!enable)),
D[2]=!(A&&(!B)&&(!enable)),
D[3]=!(A&B&&(!enable));
endmodule
J.J. Shann HDL-54
B
m_out
select
//Verilog2001,2005syntax
modulemux_2x1_df(m_out,A,B,select);
output
m_out;
input
A,B;
input
select;
assign m_out = (select)? A: B;
endmodule
conditional operator: ?:
condition ? true-expression : false-expression
D. Behavioral Modeling
Behavioral modeling:
B
A
select
Behavioral
description of 4-to-1
line MUX
//Verilog2001,2005syntax
modulemux_4x1_beh
(outputreg m_out,
input
in_0,in_1,in_2,in_3,
input[1:0] select
);
always@(in_0,in_1,in_2,in_3,select)
case(select)
2b00: m_out =in_0;
2b01: m_out =in_1;
2b10: m_out =in_2;
2b11: m_out =in_3;
endcase
case items, have implied
endmodule
priority (top
bottom)
J.J.to
Shann
HDL-61
case Construct
Numbers
NBvalue
size in bits
base
N: the size in bits, leading zeros are inserted to reach this size
NBvalue
size in bits
base
Bits
3
?
8
8
3
6
8
?
Base
2
2
2
2
10
8
16
10
Val
5
3
3
171
6
34
171
42
Stored
101
0000011
00000011
10101011
110
100010
10101011
000101010
J.J. Shann 1-64
Summary
Gate-level modeling
Dataflow modeling:
Behavioral modeling:
assign y= s?d1:d2;
always @(*)
begin
p= a^b;//blocking
q= a&b;//blocking
s= p^cin;
cout = q|(p&cin);
end
Test bench:
Inputs
..
.
Synthesizable
module
..
.
Outputs
Stimuli
..
.
Instantiation
of module(s)
..
. Response
always@ (eventcontrolexpression)begin
//proceduralassignmentstatements
end
Example:
stimulus
(t = 0)
(t = 10)
(t = 30)
Example:
A
0
1
0
B
0
0
1
Initial
begin
A=0;B=0;
#10 A=1;
#20 A=0;B=1;
end
Initial
begin
D= 3b000;
repeat (7)
#10D=D+3b001;
end
stimulus D
(t = 0)
000
(t = 10) 001
(t = 70) 111
repeat: specifies a looping statement
Example:
generate periodic clock pulse (period = 10 time units)
10 time units
always
begin
clock=1;#5;clock=0;#5;
end
Format specification:
Argument list:
uses the symbol % to specify the radix of the numbers that are
displayed : %b, %d, %h, %o (%B, %D, %H, %O)
man have a string enclosed in quotes ()
No commas in the format specification.
has commas b/t the variables.
E.g.s:
$display(%d%b%b,C,A,B);
$display(time=%0dA=%bB =%b,$time,A,B);
format specification
argument list
Testbench
moduletest_module_name;//noportlist
//Declarelocalreg andwire identifiers.
//Instantiatethedesignmoduleundertest.
//Specifyastopwatch,using$finishtoterminatethesimulation.
//Generatestimulus,usinginitialandalways statements.
//Displaytheoutputresponse(textorgraphics,orboth).
endmodule
HDL
Example 4.9:
Test bench w/
stimulus for
mux_2x1_df
B
m_out
module t_mux_2x1_df;
wire
t_m_out;
parameter: a keyword,
reg
t_A,t_B;
defines constant
reg
t_select;
parameter stop_time =50;
//Instantiationofcircuittobetested
mux_2x1_dfM1(t_m_out,t_A,t_B,t_select);
initial # stop_time $finish;
select
Simulation log:
Select = 1 A = 0
Select = 1 A = 1
Select = 0 A = 1
Select = 0 A = 0
module t_mux_2x1_df;
//Declarationoflocalidentifiers
//Instantiationofcircuittobetested
//Stimulusgenerator
B=1
B=0
B=0
B=1
OUT = 0
OUT = 1
OUT = 0
OUT = 1
time = 0
time = 10
time = 20
time = 30
T2
9
T1
1
7
3
4
E3
F2_not
E1
E2
T3
module Circuit_of_Fig_4_2(
output F1,F2,
input A,B,C);
wire T1,T2,T3,F2_not,E1,E2,E3;
or G1 (T1,A,B,C);
and G2 (T2,A,B,C);
and G3 (E1,A,B);
$finish: terminates
and G4 (E2,A,C);
the simulation
and G5 (E3,B,C);
or G6 (F2,E1,E2,E3);
not G7 (F2_not,F2);
and G8 (T3,T1,F2_not);
or G9 (F1,T2,T3);
endmodule
J.J. Shann HDL-77
Simulation log:
ABC = 000 F1 = 0
ABC = 001 F1 = 1
ABC = 010 F1 = 1
module t_Circuit_of_Fig_4_2; ABC = 011 F1 = 0
ABC = 100 F1 = 1
reg [2:0]D;
ABC = 101 F1 = 0
ABC = 110 F1 = 0
wire F1,F2;
parameter stop_time =100; ABC = 111 F1 = 1
Stimulus to analyze
the ckt of Fig 4.2
F2 = 0
F2 = 0
F2 = 0
F2 = 1
F2 = 0
F2 = 1
F2 = 1
F2 = 1
Circuit_of_Fig_4_2M1(F1,F2,D[2],D[1],D[0]);
initial # stop_time $finish;
initial begin
//Stimulusgenerator
D=3'b000;
$finish: terminates
repeat (7)#10D=D+1'b1;
the simulation
end
initial begin
//Responsemonitor
$display("ABCF1F2");
$monitor("%b%b%b%b%b",D[2],
D[1],D[0],F1,F2);
end
J.J. Shann HDL-78
endmodule
Mano 5-6
Synthesizable HDL Models of
Sequential Circuits
J.J. Shann
A. Behavioral Modeling
Behavioral models:
initial statement
* The 3 behavioral
statements can be
written in any order.
Initial
begin
clock=1b0;
end
Initial #300$finish;
always #10clock=~clock;
Initial
begin
clock=1b0;
forever #10clock=~clock;
end
an indefinite loop
always statement
always @(eventcontrolexpression)begin
//Proceduralassignmentstatementsthatexecute
whentheconditionismet
end
The variables in the left-hand side of the procedural
statements must be declared as the reg data type.
event control expression: sensitivity list
i. level sensitive events (in comb ckts and in latches)
Procedural assignment:
Procedural Assignments
General rule:
(p.236)
assign y= s?d1:d2;
Use continuous assignments
assign to model simple
always @(*)
combinational logic.
begin
Use always@(*)and blocking
p= a^b;//blocking
assignments to model more
q= a&b;//blocking
complicated combinational logic
s= p^cin;
where the always statement is
cout = q|(p&cin);
helpful.
end
Use always@(posedge clk)and
always @(posedge clk)
nonblocking assignments to
model synchronous sequential
begin
logic.
n1<= d;//nonblocking
q<= n1;//nonblocking
Do not make assignments to the
end
same signal in more than one
always statement or continuous
assignment statement.
J.J. Shann HDL-89
Flip-Flop:
responses only to a transition of a triggering input called
the clock.
Positive-edge trigger: 0 1
Negative-edge trigger: 1 0
//DescriptionofDlatch(transparentlatch),Fig.56
//moduleD_latch (Q,D,enable);
//outputQ;
//input D,enable;
//reg
Q;
//Verilog2001,2005
module D_latch (output reg Q,input D,enable);
always @(enable,D)
if(enable)Q<= D;
endmodule
//(enableorD)
//(enable==1)
D flip-flop
w/o async
reset
//DescriptionofDflipflop
//withactivelowasynchronousreset
module D_flip_flop_AR (Q,D,Clk,rst);
output Q;
input D,Clk,rst;
reg
Q;
always @(posedge Clk,negedge rst)
if (!rst)Q<= 1'b0;//if(rst ==0)
else Q<= D;
endmodule
J.J. Shann HDL-93
module t_D_flip_flops;
wire Q,Q_AR;
reg D,Clk,rst;
Testbench of
Example 5.2(a)(b):
Q
D_flip_flop M0(Q,D,Clk);
D_flip_flop_AR M1(Q_AR,D,Clk,rst);
initial #100$finish;
initial begin Clk =0;forever #5Clk =~Clk;end
initial fork
D=1;
rst =1;
#20D=0;
* Statements within the
#40D=1;
fork join block
#50D=0;
execute in parallel.
#60D=1;
#70D=0;
#42rst =0;
#72rst =1;
join
endmodule
J.J. Shann HDL-94
//DescriptionofToggle(T)flipflop
module Toggle_flip_flop_1(Q,T,Clk,rst);
output Q;
input
T,Clk,rst;
reg
Q;
always @(posedge Clk,negedge rst)
if (!rst)Q<= 1'b0;
(T)Q<=!Q;
!Q;
else ifif(T)Q<=
endmodule
J.J. Shann HDL-95
DT
Q
DT = T Q
D w/
flip-flop
w/ asnc
reset
D f-f
active-low
async
reset
//TflipflopfromDflipflopandgates
module T_flip_flop_2(Q,T,Clk,rst);
output Q;
input
T,Clk,rst;
wire
DT;
assign DT= T^Q;
D_flip_flop_AR M0(Q,DT,Clk,rst);
endmodule
J.J. Shann HDL-96
JK = JQ + KQ
D w/
flip-flop
w/ asnc
reset
D f-f
active-low
async
reset
//JKflipflopfromDflipflopandgates
module JK_flip_flop (Q,J,K,Clk,rst);
output Q;
input
J,K,Clk,rst;
wire
JK;
assign JK= (J&~Q)|(~K&Q);
D_flip_flop_AR JK1(Q,JK,Clk,rst);
endmodule
J.J. Shann HDL-97
//FunctiondescriptionofJKflipflop
HDL Example 5.4: module JK_flip_flop_2(Q,Q_not,J,K,Clk);
output
Q,Q_not;
JK flip-flop
input
J,K,Clk;
Q
function description
reg
Q;
of JK flip-flop
assign Q_not =~Q;
Q
next_state
y_out
x_in
clock Clock
reset
state
//Formstatetransition StateRegister
always @(posedge clock,negedge reset)
//Formthenextstate NextStateCombinationalLogic
always @(state,x_in)
//Formtheoutput OutputCombinationalLogic
always @(state,x_in)
S0
S2
S1
S3
always @(state,x_in)
//Formtheoutput
case (state)
S0: y_out = 0;
S1,S2,S3:y_out = ~x_in;
endcase
endmodule
J.J. Shann HDL-102
state register
next state
combinational logic
output
combinational logic
J.J. Shann HDL-103
module t_Mealy_Zero_Detector;
wire t_y_out;
reg t_x_in,t_clock,t_reset;
Testbench of HDL
Example 5.5:
Mealy_Zero_Detector M0(t_y_out,
t_x_in,t_clock,t_reset);
initial #200$finish;
//Generatestimulusfort_clock
initial
begin
t_clock =0;
forever#5t_clock =~t_clock;
end
//Generatestimulusfort_x_in,treset
initial fork
join
endmodule
J.J. Shann HDL-104
//Generatestimulusfort_x_in,treset
initial fork
t_reset =0;
#2 t_reset =1;
#87 t_reset =0;
#89 t_reset =1;
#10 t_x_in =1;
#30 t_x_in =0;
#40 t_x_in =1;
#50 t_x_in =0;
#52 t_x_in =1;
#54 t_x_in =0;
#70 t_x_in =1;
#80 t_x_in =1;
#70 t_x_in =0;
#90 t_x_in =1;
#100 t_x_in =0;
#120 t_x_in =1;
#160 t_x_in =0;
#170 t_x_in =1;
join
J.J. Shann HDL-105
endmodule
* Testbench: p.HDL-66
write stimuli that will test a
ckt thoroughly
Simulation output of
Mealy_Zero_Detector:
p.242, Fig 5.22
y_out
x_in
clock Clock
reset
state
Simulation output of
Moore_Model_Fig_5_19:
* No glitch
State-diagram-based
model
p.231, Fig 5.20(b)
output y_out,
input x_in,clock,reset
HDL Example
5.7(b):
Structural model
p.231, Fig 5.20(a)
TA
TB
module Moore_Model_STR_Fig_5_20(
output y_out,A,B,
input x_in,clock,reset
);
wire TA,TB;
//Flipflopinputequations
assign TA= x_in &B;
assign TB= x_in;
//outputequation
assign y_out = A&B;
//InstantiateToggleflipflops
Toggle_flip_flop_3M_A(A,TA,clock,reset);
Toggle_flip_flop_3M_B(B,TB,clock,reset);
endmodule
J.J. Shann HDL-113
T flip-flop module
for the circuit
module Toggle_flip_flop_3(Q,T,Clk,rst);
output Q;
input
T,Clk,rst;
reg
Q;
always @(posedge Clk,negedge rst)
if (!rst)Q<= 1'b0;
else Q<=
Q<=Q^T;
Q^T;
endmodule
J.J. Shann HDL-114
Testbench of HDL
Example 5.7(a)(b):
module t_Moore_Fig_5_20;
wire t_y_out_2,t_y_out_1;
reg t_x_in,t_clock,t_reset;
Moore_Model_Fig_5_20M1
(t_y_out_1,t_x_in,t_clock,t_reset);
Moore_Model_STR_Fig_5_20M2
(t_y_out_2,A,B,t_x_in,t_clock,t_reset);
initial #200$finish;
initial begin
t_reset =0;
t_clock =0;
#5 t_reset =1;
repeat (16)
#5 t_clock =~t_clock;
end
initial begin
t_x_in =0;
#15t_x_in =1;
repeat (8)
#10t_x_in =~t_x_in;
end
J.J. Shann HDL-115
endmodule
Simulation output of
HDL Example 5.7:
Mano 6-6
HDL for Registers and Counters
J.J. Shann
A. Shift Register
Function table
module Shift_Register_4_beh(
output reg [3:0] A_par,
input
[3:0] I_par,
input
s1,s0,
MSB_in,LSB_in,
CLK,Clear_b
);
//V2001,2005
//Registeroutput
//Parallelinput
//Selectinputs
//Serialinputs
//ClockandClear_b
J.J. Shann HDL-120
module Shift_Register_4_beh(
output reg [3:0] A_par,
input
[3:0] I_par,
input
s1,s0,
MSB_in,LSB_in,
CLK,Clear_b
);
//V2001,2005
//Registeroutput
//Parallelinput
//Selectinputs
//Serialinputs
//ClockandClear_b
MSB_in
module Shift_Register_4_str(
output [3:0] A_par,
input [3:0] I_par,
input
s1,s0,
input
MSB_in,LSB_in,CLK,Clear_b
);
LSB_in
//V2001,2005
//Paralleloutput
//Parallelinput
//Modeselect
//Serialinputs,clock,clear
J.J. Shann HDL-122
module Shift_Register_4_str(
output [3:0] A_par,
input [3:0] I_par,
MSB_in
input
s1,s0,
input
MSB_in,LSB_in,CLK,Clear_b
);
//V2001,2005
//Paralleloutput
//Parallelinput
LSB_in
//Modeselect
//Serialinputs,clock,clear
//busformodecontrol
wire [1:0] select={s1,s0};
//Instantiatethefourstages
stageST0(A_par[0],A_par[1],LSB_in,I_par[0],A_par[0],select,CLK,Clear_b);
stageST1(A_par[1],A_par[2],A_par[0],I_par[1],A_par[1],select,CLK,Clear_b);
stageST2(A_par[2],A_par[3],A_par[1],I_par[2],A_par[2],select,CLK,Clear_b);
stageST3(A_par[3],MSB_in,A_par[2],I_par[3],A_par[3],select,CLK,Clear_b);
J.J. Shann HDL-123
endmodule
Q
Q
Clr_b
mux_out
CLK
module stage(i0,i1,i2,i3,Q,select,CLK,Clr_b);
input
i0, //circulationbitselection select
i1, //datafromleftneighbororserialinputforshiftright
i2, //datafromrightneighbororserialinputforshiftleft
i3; //datafromparallelinput
output
Q;
input [1:0] select;
//stagemodecontrolbus
input
CLK,Clr_b; //Clock,Clearforflipflops
wire
mux_out;
//instantiatemuxandflipflop
Mux_4_x_1 M0(mux_out,i0,i1,i2,i3,select);
D_flip_flop M1(Q,mux_out,CLK,Clr_b);
endmodule
41
MUX
3 2 1 0
i3 i2 i1 i0
Q
Q
Clr_b
C
CLK
module Mux_4_x_1(mux_out,i0,i1,i2,i3,select);
output
mux_out;
select
input
i0,i1,i2,i3;
input [1:0] select;
reg
mux_out;
always @(select,i0,i1,i2,i3)
case (select)
2'b00: mux_out = i0;
2'b01: mux_out = i1;
2'b10: mux_out = i2;
2'b11: mux_out = i3;
endcase
endmodule
41
MUX
3 2 1 0
i3 i2 i1 i0
Q
Q
Clr_b
C
CLK
select
41
MUX
3 2 1 0
i3 i2 i1 i0
B. Synchronous Counter
Synchronous counter:
module Binary_Counter_4_Par_Load(
output reg [3:0] A_count, //Dataoutput
output
C_out,
//Outputcarry
input [3:0]
Data_in,
//Datainput
input
Count,
//Activehightocount
Load,
//Activehightoload
CLK,
//Positiveedgesensitive
Clear_b
//Activelow
J.J. Shann HDL-128
);
module Binary_Counter_4_Par_Load(
output reg [3:0] A_count, //Dataoutput
output
C_out,
//Outputcarry
input [3:0]
Data_in,
//Datainput
input
Count,
//Activehightocount
Load,
//Activehightoload
CLK,
//Positiveedgesensitive
Clear_b
//Activelow
);
assign C_out =Count&(~Load)&(A_count ==4'b1111);
always @(posedge CLK,negedge Clear_b)
if (~Clear_b)
A_count <= 4'b0000;
elseif(Load) A_count <= Data_in;
elseif(Count) A_count <= A_count +1'b1;
else
A_count <= A_count; //redundantstatement
endmodule
J.J. Shann HDL-129
C. Ripple Counter
Ripple counter:
Summary of HDL
Mano 7-2
Random-Access Memory:
Memory Description in HDL
J.J. Shann
# of words in memory
memory depth
Address 6
Enable
ReadWrite
DataIn
Memory unit
26 words
4 bits per word
DataOut
Enable
ReadWrite
Memory operation
0
1
1
x
0
1
Enable
ReadWrite
Memory operation
DataOut Hi-Z
Mem[Address] DataIn
DataOut Mem[Address]
module memory(Enable,ReadWrite,Address,DataIn,DataOut);
input
Enable,ReadWrite;
input [3:0] DataIn;
input [5:0] Address;
output[3:0] DataOut;
reg
[3:0] DataOut;
reg
[3:0] Mem[0:63];
//64x4memory
always @(EnableorReadWrite)
if (Enable)
if (ReadWrite)DataOut =Mem[Address]; //Read
else Mem[Address]=DataIn;
//Write
else DataOut =4'bz;
//Highimpedancestate
J.J. Shann HDL-140
endmodule