FPGA Center



  * JK Flip-Flop

   * Example

BINARY COUNTER

We designed a binary counter by using JK flip flops in this example.

The capacity of the counter is defined as generic in order to allow user to change it. The N-bit counter starts from 0 then counts until (2eN-1) then comes back to 0.


VHDL Code


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity binary_sayici is
    generic(N:integer:=5);
    Port ( Clk : in  STD_LOGIC;
                B   : out  STD_LOGIC_VECTOR(N-1 downto 0));
    end binary_sayici;

architecture Behavioral of binary_sayici is

    COMPONENT jk_flip_flop
     PORT( J        : IN std_logic;
                  K        : IN std_logic;
                  Clk     : IN std_logic;         
                  Q_out : OUT std_logic );
    END COMPONENT;

signal A:std_logic_vector(N-1 downto 0):=(others=>'0');
signal Q:std_logic_vector(N-1 downto 0):=(others=>'0');
begin
  U1: for I in B'range generate
             begin
             U2:  if I = B'right generate
                        begin
                             A(I)<= Q(I) and '1';
                             U2: jk_flip_flop PORT MAP(J =>'1' ,K =>'1' ,Clk =>Clk ,Q_out =>Q(I));
                        end generate;
             U3: if I>B'right  generate
                       begin
                            A(I)<= Q(I) and Q(I-1);
                            U4: jk_flip_flop PORT MAP(J =>A(I-1) ,K =>A(I-1) , Clk => Clk, Q_out =>Q(I) );
                       end generate;
            end generate;
    B<=Q;
end Behavioral;

After simulating this code with ModelSim, you will get a plot below.

                                                                                                                                 

project                                                                                                                                                                                                                                                                      

 

                                                                                                                                                                                                                                                                   

Home | Fpga | VHDL | VHDL Dictionary | Digital Design | Simulation | PCB | Examples | Contact Us
Copyright © 2010 - 2013 FPGAcenter. All Rights Reserved.