4 Bit Ring Counter Program
4 Bit Ring Counter Program
4 Bit Ring Counter Program
Program:
module four_bit_ring_counter (
input clock,
input reset,
output [3:0] q
);
reg[3:0] a;
if (reset)
a = 4'b0001;
else
begin
a[0]<=a[3];
end
assign q = a;
endmodule
Test bench:
`timescale 1ns / 1ps
module stimulus;
reg clock;
reg reset;
wire[3:0] q;
four_bit_ring_counter r1 (
.clock(clock),
.reset(reset),
.q(q)
);
initial begin
clock = 0;
reset = 0;
#5 reset = 1;
#20 reset = 0;
#500 $finish;
end
initial begin
end
endmodule
BCD counter
Program:
Program:
module BCD_Counter ( clk ,reset ,dout );
input clk ;
wire clk ;
input reset ;
wire reset ;
initial dout = 0 ;
if (reset)
dout <= 0;
else if (dout<=9) begin
dout <= 0;
end
end
endmodule
SR flip flop: