Forum Discussion

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

Error (10822) a code that dosent work

i will be thankful if somebody will can help me..my aim is to make a block that get 3 inputs:a clc that change every 0.1 seca input that get '1' every time i press key0and reset button that reset my countthe aim is to count the number of time i press and when there is 3 secs that i dont press i get the count of the time i pressedi tried to it with this code:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use ieee.std_logic_arith.all;

entity CLAPNUM is

port(

resetN, clk : in std_logic;

key0 : in std_logic ;

sinus : out std_logic_vector(4 downto 0));

end CLAPNUM ;

architecture arc_CLAPNUM of CLAPNUM is

signal countera : std_logic_vector(4 downto 0) :="00000" ;

signal counterb : std_logic_vector(4 downto 0) :="00000" ;

signal cinout : std_logic := '0' ;

signal moda : std_logic := '0' ;

begin

process ( resetN key0, clk)

begin

if resetN = '0' then

countera<="00000" ;

counterb<="11110";

elsif (key0 ='1') and moda='0' then

countera<= countera+"00001" ;

counterb<="11110";

elsif (rising_edge(clk)) then

if counterb/="00000" and (key0 ='0') then

counterb <= counterb-"00001";

else

moda <= '1';

end if;

elsif moda='1' then

sinus<= countera;

end if;

end process;

end arc_CLAPNUM;

but clearly it dosent work...can someone help me plz?

1 Reply

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

    Yes- because you have control signal attempting to do increment a counter not on a clock edge.

    You need to follow this template:

    
    process(resetN, clk)
    begin
      if resetN = '0' then
        --do resets here
      elsif rising_edge(clk)
        --ALL other code goes in here
      end if;
    end process;
    

    If you dont follow the template above, you are trying to create extra analogue control paths. For example - if key0 = '1' and moda = '0', it is trying to increment the counter an infinite number of times in 0 time (in reality there will be some tiny propogation delay - still it will count up ALOT). This is an analogue feedback path - and is not a good idea.

    I suggest you draw your circuit on paper before you try and write the code. Then when you have a good idea of the circuit, you can use the known templates to copy your circuit into code.

    I also suggest you write a testbench to test the code.