Hello,
I am designing a vhdl quadrature decoder. The result of the decoder should be set in a register called "slv_reg2". Because the device can turn both ways i will cast the signed value to a std_logic_vector one (so my software can directly see which way is has turned).
The design works perfect exept if I turn de shaft clockwise first and then counter-clockwise (and vice versa). When this happens i see the following on hyperterminal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6 -4543453453. I've already spend 2 days finding the bug, but I really can't find it. Can the clock speed be to fast ??
Here is my vhdl source:
signal last_quad : std_logic_vector(0 to 1);
signal look_up : std_logic_vector(0 to 3);
signal signed_slv_reg2 : signed(0 to 31);
begin
slv_reg2 <= std_logic_vector(signed_slv_reg2);
look_up <= quadrature & last_quad;
p0:
process(Bus2IP_Clk)
begin
if(Bus2IP_Clk'EVENT and Bus2IP_Clk = '1') then -- sample @ every rising clock cycle
last_quad <= quadrature;
signed_slv_reg2 <= signed_slv_reg2;
if(slv_reg0(31) = '1') then -- check for reset events in control reg
signed_slv_reg2 <= to_signed(0,32); -- if reset then empty register
else
case look_up is
-- no change
when "0000" | "1010" | "0101" | "1111" =>
signed_slv_reg2 <= signed_slv_reg2;
-- error
when "0011" | "1100" | "1001"| "0110" =>
signed_slv_reg2 <= signed_slv_reg2;
-- turn ClockWise
when "0010" | "0100" | "1011" | "1101" =>
signed_slv_reg2 <= signed_slv_reg2 + to_signed(1,32);
-- turn Counter - ClockWise
when "0001" | "0111" | "1000" | "1110" =>
signed_slv_reg2 <= signed_slv_reg2 - to_signed(1,32);
-- not necessary because all states covered
when others => null;
end case;
end if;
end if;
end process p0;
I am designing a vhdl quadrature decoder. The result of the decoder should be set in a register called "slv_reg2". Because the device can turn both ways i will cast the signed value to a std_logic_vector one (so my software can directly see which way is has turned).
The design works perfect exept if I turn de shaft clockwise first and then counter-clockwise (and vice versa). When this happens i see the following on hyperterminal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6 -4543453453. I've already spend 2 days finding the bug, but I really can't find it. Can the clock speed be to fast ??
Here is my vhdl source:
signal last_quad : std_logic_vector(0 to 1);
signal look_up : std_logic_vector(0 to 3);
signal signed_slv_reg2 : signed(0 to 31);
begin
slv_reg2 <= std_logic_vector(signed_slv_reg2);
look_up <= quadrature & last_quad;
p0:
process(Bus2IP_Clk)
begin
if(Bus2IP_Clk'EVENT and Bus2IP_Clk = '1') then -- sample @ every rising clock cycle
last_quad <= quadrature;
signed_slv_reg2 <= signed_slv_reg2;
if(slv_reg0(31) = '1') then -- check for reset events in control reg
signed_slv_reg2 <= to_signed(0,32); -- if reset then empty register
else
case look_up is
-- no change
when "0000" | "1010" | "0101" | "1111" =>
signed_slv_reg2 <= signed_slv_reg2;
-- error
when "0011" | "1100" | "1001"| "0110" =>
signed_slv_reg2 <= signed_slv_reg2;
-- turn ClockWise
when "0010" | "0100" | "1011" | "1101" =>
signed_slv_reg2 <= signed_slv_reg2 + to_signed(1,32);
-- turn Counter - ClockWise
when "0001" | "0111" | "1000" | "1110" =>
signed_slv_reg2 <= signed_slv_reg2 - to_signed(1,32);
-- not necessary because all states covered
when others => null;
end case;
end if;
end if;
end process p0;