Hello again, i hope you are doing well. so in this blog we will design Onehot counter also known as Ring counter and johnson counter.In ring counter if there are N flip flop then number of stages will be N, while in johnson counter if number of flip flop is N then number of stages wiil be 2xN.
If N=4 in ring counter then number of stages = 4, and in johnson counter number of stages are 2x4=8.
In ring counter output of last flip flop is fed back to first flip flop and in johnson counter output of last flip flop is first inverted and then fed back to input of first flip flop.
Verilog Code for ring and johnson counter
TestBench for DUT
In design there is concept of conditional compilation. if `define ONEHOT is define then testbench will test ring counter otherwise(if we remove `define ONEHOT) testbench will test johnson counter.
Output of Ring Counter
count=xxxx // here reset is low and there for output is unknown.
count=0001
count=0010
count=0100
count=1000
count=0001
count=0010
count=0100
count=1000
Link for Code : https://www.edaplayground.com
Parameterized N bit Ring Counter : https://www.edaplayground.com/x/jxf4
Key compiler directives
`include -> include another file here
`define -> define a macro[symbole]
`undef -> undefine a symbol
`ifdef -> These three are conditional compilation directives
`else
`endif
`timescale -> Define the timescale to be used for the subsequent part of design
Example
Output:
5
Hello world!
4
4
No feature
Thank you for reading.
Keep smiling, have a nice day 😊😊.