Search This Blog

Monday, July 22, 2013

Design of 2 Bit Binary Counter using Behavior Modeling Style (VHDL Code).






Design of 2 Bit Binary Counter using Behavior Modeling Style -


Output Waveform :  2 Bit Binary Counter.




VHDL Code -



-------------------------------------------------------------------------------
--
-- Title       : counter_2bit
-- Design      : vhdl_upload2
-- Author      : Naresh Singh Dobal
-- Company     : nsdobal@gmail.com
-- VHDL Programs &  Exercise with Naresh Singh Dobal.
--
-------------------------------------------------------------------------------
--
-- File        : Design of 2 bit counter using behavior modeling style.vhd


library IEEE;
use IEEE.STD_LOGIC_1164.all;  
use IEEE.STD_LOGIC_ARITH.all;
use IEEE.STD_LOGIC_UNSIGNED.all;

entity counter_2bit is
     port(
         clk : in STD_LOGIC;
         reset : in STD_LOGIC;
         dout : out STD_LOGIC_VECTOR(1 downto 0)
         );
end counter_2bit;

architecture counter_2bit_arc of counter_2bit is
begin

    counting : process (clk,reset) is
    variable m : std_logic_vector (1 downto 0) := "00";
    begin
        if (reset='1') then
            m := "00";
        elsif (rising_edge (clk)) then
            m := m + 1;
        end if;
        dout <= m;
    end process counting;

end counter_2bit_arc;

3 comments:

  1. This code is not working.
    Its showing error in m:=m + 1;

    ReplyDelete
  2. of course it does no work...m is declared as a signal not as a variable...the code in general is false

    ReplyDelete
  3. sorry wrong...m is declared as a variable but is being treated as signal at one point

    ReplyDelete