johnson counter
A Johnson counter is a digital circuit with a series of flip flops connected in a feedback manner.
The circuit is a special type of shift register where the last flip flop's complement output is fed back to the first flip flop's input. This is almost similar to the ring counter with a few extra advantages.
The Johnson counter's main advantage is that it only needs half the number of flip-flops compared to the standard ring counter, and then it's modulo number is halved. So an n-stage Johnson counter will circulate a single data bit, giving a sequence of 2n different states and can therefore be considered a mod-2n counter.
Verilog code:
module johnson_counter(clk,reset,count);
//Johnson counter can be implement for any number of bits by changing Width Parameter.Initially it was 4.
parameter WIDTH=4;
//inputs
input clk,reset;
//outputs
output reg [WIDTH-1:0] count;
always@(posedge clk)
begin
if(reset)
count={~count[0],count[WIDTH-1:1]};
else
count=1;
end
endmodule
Test bench code:
module johnson_counter_tb();
parameter WIDTH=4;
reg clk,reset;
wire [WIDTH-1:0] count;
johnson_counter dut(clk,reset,count);
always #10 clk=~clk;
initial
begin
reset=0;
clk=0;
$monitor ("T=%0t out=%b", $time, count);
#50 reset=1;
end
endmodule
#verilog #rtlcoding #Johnsoncounter
Comments
Post a Comment