VHDL Counter Problem (Please Help)

Discussion in 'Homework Help' started by IcyIcy, Nov 6, 2014.

  1. IcyIcy

    Thread Starter Member

    Nov 17, 2012
    32
    0
    I am not able to do the increment and the testbench for this code.

    Question:

    A system has a 3-bit input D_IN which is read in at every positive edge of a clock input CLK. If the current D_IN is greater than the previous D_IN by at least 2, a 3-bit output Count is incremented. If D_IN is 0 for 3 consecutive CLK cycles, the count is reset. When Count reaches 6, the system will assert an output Alarm and the Count will not increase further, till it is reset by giving 0s at D_IN for 3 consecutive cycles.

    Test case:

    Clk 1 2 3 4 5 6 7 8 9 1 0 11 12 13 14 15 16 17 18

    D_IN 0 0 0 2 4 7 6 0 2 4 6 3 5 7 0 0 0 0
    code

    library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.NUMERIC_STD.ALL;

    entity johnson_counter isport(
    D_in :instd_logic_vector(2downto0);
    alarm :eek:utstd_logic;
    CLK_I :instd_logic);end johnson_counter;

    architecture Behavioral of johnson_counter is

    signal xnew, xold, count1, count2:unsigned(2downto0):=(others=>'0');

    begin


    process(CLK_I)beginif( rising_edge(CLK_I))then
    xnew <=std_logic_vector(unsigned(D_in));
    xnew <= xnew -"010";if(xnew => xold)then
    count1 <= count1 +"1";if(xnew =0)then
    count2 <= count2 +"1";if(xnew /=0)then
    count2 <="0";if(count2 ="011")then
    alarm <="1";endif;endif;endif;endif;endif;endprocess;
     
  2. WBahn

    Moderator

    Mar 31, 2012
    17,777
    4,805
    So you've made a statement, namely that you can't do your homework. What's your question? More to the point, what have you done to attempt to do your homework?
     
  3. upopads2

    Member

    Sep 20, 2014
    52
    1
    Bahn some people do not know where to begin.
     
  4. bertus

    Administrator

    Apr 5, 2008
    15,649
    2,348
    Hello,

    @upopads2 , please stop trolling WBahn.
    He knows what he is doing.

    Bertus
     
  5. JoeJester

    AAC Fanatic!

    Apr 26, 2005
    3,373
    1,159
    Can you do a flowchart of your program?
     
Loading...