Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

help please.......how to catch number

can someone help me how to design coding that catch number 8 and it will increment the counter..i've done the coding but cannot catch number 8..it will catch random number....

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    can someone help me how to design coding that catch number 8 and it will increment the counter..i've done the coding but cannot catch number 8..it will catch random number....

    --- Quote End ---

    Why don't you post what you've tried so far.

    In VHDL the code would look something like;

    
    constant WIDTH : integer := 4;
    signal match : std_logic;
    signal match_value : std_logic_vector(WIDTH-1 downto 0) := X"8";
    ...
    match <= '1' when (count = match_value) else '0';
    
    Cheers,

    Dave
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    if Reset='0' then

    level<="0000";else

    if PUSH'event and PUSH='1' then if X=8 then

    if (level < 10) then

    level <= level +1;

    else

    level <= "0000";

    end if;

    end if;

    --can i do like this?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    --can i do like this?

    --- Quote End ---

    No, probably not.

    You need to use a proper clock and separate the logic into functional blocks;

    1) Push button interface, with debounce logic

    * synchronize the push-button to the clock

    * detect an edge, and then ignore the input for a while

    2) A counter

    3) Synchronized push-button and match control logic

    Create a testbench for your logic, eg., something that contains a clock and a noisy push-button press, and use that to confirm that you only see one button press.

    If you don't know how 'noisy' to make your button press, create a simple design and download it into your hardware. Add a SignalTap II instance and capture a trace from a push-button press. You will see that the signal generates multiple transitions when you click on the button. Your debounce logic needs to convert the ugly push-button signal into a nice clean logic level.

    Cheers,

    Dave