Board Work
Board Work
Board Work
Sequential Circuits
Play with the circuit here
http://www.facweb.iitkgp.ac.in/~avishek/DigitalElectronics2024.html
4-bit down counter with the provision for loading the initial values
Now we use the above counter to make a digital metronome with variable number of beats
We can use the above circuit as a PISO register. If we connect the SO output back to SI input, then it would be possible
to read-out the data more than once.
Verilog HDL through examples
HDL : Hardware Description Language
Most used HDLs : (1) Verilog, (2) System Verilog, and (3) VHDL
Half adder
module HalfAdder(input X, input Y, output S, output Cout);
xor(S,X,Y);//S=X xor Y
and(Cout,X,Y);
endmodule
Example Problems: Just describe what to do to the computer and leave the design to the compueter
Design a logic circuit to convert BCD to Excess-3 for the numbers zero to nine
module BCDtoExcess3(input [3:0] BCD, output [3:0] Excess3);
assign Excess3 = BCD+3;
endmodule
Design a three-input circuit that yields an output 1 when exactly one of its inputs is 1
module DFF(input wire clk, input wire D, output reg Q); module DFF(input clk, input D, output reg Q);
always @(posedge clk) always @(posedge clk)
Q <= D; Q <= D;
endmodule endmodule
module TB_DFF();
reg clk = 0;
reg D = 0;
wire Q;
initial begin
#3 D= ~D;
#3 D = ~D;
#2 D = 1;
#4 D = 0;
#6 D = 1;
#3 D = 0;
#5 D = 1;
#4 D = 0;
#2 D = 1;
end
endmodule
module JKFF(input clk, input J, input K, output reg Q = 0);
always @(posedge clk) begin
if(J==1 && K==0) begin
Q <= 1;
end
else if(J==0 && K==1) begin
Q <= 0;
end
else if(J==1 && K==1) begin
Q <= ~Q;
end
else begin
Q <= Q;
end
end
endmodule
module TB_TFF();
reg myclk = 0;
reg T = 0;
wire myQ;
initial begin
$dumpfile("dump.vcd");
$dumpvars(1);
#3 T= ~T;
#3 T = ~T;
#2 T = 1;
#4 T = 0;
#6 T = 1;
#3 T = 0;
#5 T = 1;
#4 T = 0;
#2 T = 1;
#5 $finish();
end
endmodule
4-bit Up Counter
`timescale 1ns / 1ps module UpCounter(input clk, output reg [3:0] Q = 0);
always @(posedge clk) begin
module TB_UpCounter(); Q <= Q+1;
reg clk = 0; end
wire [3:0] Q; endmodule
UpCounter uut(.clk(clk), .Q(Q));
always begin
#5 clk <= ~clk;
end
endmodule
Modulo 10 Counter
module Mod10Counter(input clk, output reg [3:0] Q = 0);
always @(posedge clk) begin
if(Q<9)begin
Q <= Q+1;
end
else begin
Q <= 0;
end
end
endmodule
A ring counter
module RingCounter(input clk, output reg [3:0] Q = 1); module RingCounter(input clk, output reg [3:0] Q = 1);
always @(posedge clk) begin always @(posedge clk) begin
Q[0] <= Q[1]; Q[3] <= Q[0];
Q[1] <= Q[2]; Q[2] <= Q[3];
Q[2] <= Q[3]; Q[1] <= Q[2];
Q[3] <= Q[0]; Q[0] <= Q[1];
end end
endmodule
endmodule
module RingCounter(input clk, output reg [3:0] Q = 1); module RingCounter(input clk, output reg [3:0] Q = 1);
always @(posedge clk) begin always @(posedge clk) begin
Q[0] = Q[1]; Q[3] = Q[0];
Q[1] = Q[2]; Q[2] = Q[3];
Q[2] = Q[3]; Q[1] = Q[2];
Q[3] = Q[0]; Q[0] = Q[1];
end end
endmodule endmodule
module RingCounter(input clk, output reg [3:0] Q = 1); module RingCounter(input clk, output reg [3:0] Q = 1);
always @(posedge clk) begin always @(posedge clk) begin
Q[0] <= Q[1]; Q[0] = Q[1];
Q[1] <= Q[2]; Q[1] = Q[2];
Q[2] <= Q[3]; Q[2] = Q[3];
Q[3] <= Q[0]; Q[3] = Q[0];
end
end
endmodule
endmodule
Outputs
Qn, ...................., Q0 Qn, ...................., Q0 Ym, .........., Y0
Memory or Latch or Memory or Latch or
Clocked PIPO register Outputs Clocked PIPO register
Dn, ....................,D0 Ym, .........., Y0 Dn, ....................,D0 PIPO registe
Combinational Combinational
circuit circuit
Qn, ..., Q0 are called state variables Here the next state is a function of the present state and inputs.
Outputs are functions of inputs and state variables Outputs are functions of inputs and state variables.
The next state is a function of the present state and inputs Here outputs are synchronous (or clocked or registered)
This structure is called a Mealy machine and can change only at a clock edge
Here outputs are not synchronous (not clocked) This structure is called a
and can change anytime without requiring a clock edge Synchronous or Registered Mealy machine
Outputs
Ym, .........., Y0
Combinational
circuit
Qn, ...................., Q0
Memory or Latch or
Clocked PIPO register
Dn, ....................,D0
Combinational
circuit
Xp, .........., X0
Inputs