This website uses cookies. By using this site, you consent to the use of cookies. For more information, please take a look at our Privacy Policy.
Home > FPGA Technical Tutorials > Design Recipes for FPGAs Using Verilog and VHDL > Counters > The Johnson Counter

TABLE OF CONTENTS

Xilinx FPGA FPGA Forum

The Johnson Counter

FONT SIZE : AAA

The Johnson counter is a counter that is a simple extension of the shift register. The only difference between the two is that the Johnson counter has its least significant bit inverted and fed back into the most significant bit of the register. In contrast to the classical binary counter with 2n states, the Johnson counter has 2 n states. While this has some specific advantages, a disadvantage is that the Johnson counter has what is called a parasitic counter in the design. In other words, while the 2 n counter is operating, there is another state machine that also operates concurrently with the Johnson counter using the unused states of the binary counter. A potential problem with this counter is that if, due to an error, noise or other glitch, the counter enters a state NOT in the standard Johnson counting sequence, it cannot return to the correct Johnson counter without a reset function. The normal Johnson counter sequence is shown in the following table: 

1.png

The VHDL implementation of a simple Johnson counter can then be made by modifying the next stage logic of the internal shift_register function as shown in the following listing:

1 library ieee;

2 use ieee.std_logic_1164.all;

3

4 entity johnson_counter is

5 generic (

6 n : integer := 4;

7 port (

8 clk : in std_logic;

9 rst : in std_logic;

10 din : in std_logic;

11 q : out std_logic_vector((n−1) downto 0)

12 );

13 end entity;

14

15 architecture simple of Johnson_counter is

16 begin

17 process(clk, rst)

18 variable j_state : std_logic_vector((n−1) downto 0);

19 begin

20 if rst = ’0’ then

21 j_state:= (others => ’0’);

22 elsif rising_edge(clk) then

23 j_state:= not j_state(0) & j_state(n−1 downto 1);

24 end if;

25 q <= j_state;

26 end process;

27 end architecture simple;

Notice that the concatenation is now putting the inverse (NOT) of the least significant bit of the internal state variable (j_state(0)) onto the next state most significant bit, and then shifting the current state down by one bit. 

It is also worth noting that the counter does not have any checking for the case of an incorrect state. It would be sensible in a practical design to perhaps include a check for an invalid state and then reset the counter in the event of that occurrence. The worst-case scenario would be that the counter would be incorrect for a further 7 clock cycles before correctly resuming the Johnson counter sequence. 

In a similar manner we can implement a Johnson counter in Verilog using the code given here: 

1 module johnson_counter (

2 clk, / clock input

3 rst, / reset (active low)

4 johnsonreg / shift register

5 );

6

7 input clk;

8 input rst;

9

10 output [7:0] johnsonreg;

11

12 wire clk;

13 wire rst;

14

15 reg [7:0] johnsonreg ;

16

17 always @ (posedge clk)

18 begin : count

19 if (rst == 1’b0) begin

20 johnsonreg <= #1 4’b00000000;

21 end

22 else begin

23 johnsonreg <= #1 {!johnsonreg[0], johnsonreg[7:1]};

24 end

25 end

26

27 endmodule

Figure 24.6 Johnson counter simulation.

and test it using the same basic counter test bench created for the simple counter, giving the simulation results as shown in Figure 24.6. We can see that the counter variable “ripples” through till it gets to all 1s and then carries back on until it is all 0s. 

  • XC2V2000-4FF896I

    Manufacturer:Xilinx

  • FPGA Virtex-II Family 2M Gates 24192 Cells 650MHz 0.15um Technology 1.5V 896-Pin FCBGA
  • Product Categories: FPGAs (Field Programmable Gate Array)

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC2V2000-4FG676I

    Manufacturer:Xilinx

  • FPGA Virtex-II Family 2M Gates 24192 Cells 650MHz 0.15um Technology 1.5V 676-Pin FBGA
  • Product Categories: FPGAs (Field Programmable Gate Array)

    Lifecycle:Obsolete -

    RoHS:

  • XC4028XLA-08BG352C

    Manufacturer:Xilinx

  • FPGA XC4000XLA Family 28K Gates 2432 Cells 263MHz 0.35um Technology 3.3V 352-Pin Metal BGA
  • Product Categories:

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC3090-125PQ160C

    Manufacturer:Xilinx

  • FPGA XC3000 Family 6K Gates 320 Cells 125MHz 5V 160-Pin PQFP
  • Product Categories:

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC5VLX110-2FFG1136C

    Manufacturer:Xilinx

  • Xilinx BGA1136
  • Product Categories:

    Lifecycle:Any -

    RoHS:

Need Help?

Support

If you have any questions about the product and related issues, Please contact us.