Altera_Forum
Honored Contributor
16 years agoCounter Problems
Hi,
im trying to implement a counter which counts positive, negative, or both edges of an incoming signal. It works, but if I give 10000pulses to it it counts only between 9980...9997. The internal FPGA clk is 10MHz and the signal to count comes along with 1kHz and a ontime of 50usec. Here is the counter part: Detect_Edges : FOR i IN 1 TO nbr_of_Counters GENERATE PROCESS(Clk_I, reset_I, Enable_S, CntEdge_S, DIO_Stati_I, CountPort_S) VARIABLE was_on : boolean; VARIABLE cnt : integer; BEGIN IF reset_I = '1' THEN cnt := 0; was_on := TRUE; ELSIF rising_edge(clk_I) THEN IF ResetCounter_S(i) = '1' THEN cnt := 0; was_on := TRUE; ELSIF Set_Counter_S(i) = '1' THEN cnt := CONV_INTEGER(unsigned(CntSet_value_S)); ELSIF Enable_S(i) = '0' THEN NULL; ELSIF DIO_Stati_I(CountPort_S(i)) = '1' AND was_on = FALSE THEN was_on := TRUE; IF CntEdge_S(i) /= COUNT_ON_FALLING_EDGE THEN IF CntDir_S(i) = '1' THEN cnt := cnt + 1; ELSE cnt := cnt - 1; END IF; END IF; ELSIF DIO_Stati_I(CountPort_S(i)) = '0' AND was_on = TRUE THEN was_on := FALSE; IF CntEdge_S(i) /= COUNT_ON_RISING_EDGE THEN IF CntDir_S(i) = '1' THEN cnt := cnt + 1; ELSE cnt := cnt - 1; END IF; END IF; END IF; CntValues_S(i) <= CONV_STD_LOGIC_VECTOR(cnt,32); END IF; END PROCESS; END GENERATE; Has anyone an idea? If i count the pulses with an other counter the# is correct