Altera_Forum
Honored Contributor
14 years agoHelp on VHDL
Just want to design a mod-12 counter counting from 0 to 12, but when I use the following code, it always set q as 0 to 7 instead of 0 to 11 (Under QSim simulator).
====================================== Library ieee; Use ieee.std_logic_1164.all; Entity CounterTest is port (cp, reset: in std_logic; q: buffer integer range 0 to 64); end CounterTest ; Architecture logicfunction of CounterTest is begin process (reset, cp, q) begin if((reset = '0') OR (q > 11)) Then q <= 0; elsif (cp'Event AND cp='1') Then q <= q + 1; end if; end process; end logicfunction; ====================================== But if I change the following line in process from: "if((n_rd = '0') OR (q > 11)) Then" to "if((n_rd = '0') OR (q >= 12)) Then" or "if((n_rd = '0') OR (q = 12)) Then" Then it works fine under QSim simulator. Have not tried on real FPGA yet though. Is there any thing wrong or I missed something? Thanks.