This may or may not be the cause of your problem.... Does your IF statement compare floating point numbers? Sometimes they do not act as expected. For instance, 2 might be stored as 1.9999999999999, and the computer might print it as 2 onscreen. So we think it's stored as 2.
However the computer calls it 'unequal' if we execute a comparison to an integer 2. Sometimes we need to try various programming tricks to get around such behavior.
Code VHDL - [expand] 1 2 3 4 5 6 7 if inc = '1' then cnt <= cnt + 1; elsif dec = '1' then cnt <= cnt - 1; elsif shf = '1' then cnt <= cnt(cnt'left-1 downto 0) & '0'; end if;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 -- inc: sel="00" -- dec: sel="01" -- shf: sel="10" -- sel="11" - do nothing if sel = "00" then cnt <= cnt + 1; elsif sel = "01" then cnt <= cnt - 1; elsif sel = "10" then cnt <= cnt(cnt'left-1 downto 0) & '0'; end if;
I don't understand that if this is the case why the order should matter for e.g. If sel = 10 is put before sel = 01 then shouldn't it expected to work and vice versa.
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity test is port( reset : in STD_LOGIC; clk : in STD_LOGIC; sel : in STD_LOGIC_VECTOR (1 downto 0); cnt : buffer SIGNED(3 downto 0) ); end test; architecture rtl of test is begin process (reset, clk) begin if reset = '1' then cnt <= (others => '0'); elsif rising_edge(clk) then If sel = "00" then Cnt <= cnt + 1; Elsif sel = "01" then Cnt <= cnt - 1; Elsif sel = "10" then Cnt <= cnt(cnt'left-1 downto 0) & '0'; End if; end if; end process; end rtl;
I set up a minimal test entity around the said code snippet.
Changing the order of the second and third condition results in exactly the same gate level net list, so it won't behave different, even when facing timing violations of input signals.
Thanks everyone
I find the bit order reversed while looking at the RTL Viewer (Quartus). Has this anything to do with it not working as expected??
Thanks
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?