I am designing a shift key detector.I wrote a test bench. The test showed that my implementation was incorrect.
Here is the simulation in ModelSim.
The red line indicated UNDEFINED. This behavior only occurred twice.
What puzzled me is: why is there such a big gap between those two values? If you look at the test bench, the 3rd and 4th procedures are using the format used for the 1st and 2rd.
Test bench is here: http://pastebin.com/BJVFFgGr
The detector code is here: http://pastebin.com/di42FLqT
As you can see. I have two states in my design. PS2 receiver will filter and generate clean 8-bit make code when a key is pressed (or released). The break code is simply F0 follow by the make code of the key just released. My state machine uses two extra bits to keep track of which shift key has been pressed.
I went through debug, and when we entered the 3rd test values, SHIFT = U instead of 1 from the previous value.
-- release left shift
hex <= "11110000";
wait for 5 ns;
clk <= NOT clk;
wait for 50 ns;
clk <= NOT clk;
wait for 50 ns;
hex <= "00010010"; <----- when I am here shift is already U
wait for 5 ns;
clk <= NOT clk;
wait for 50 ns;
clk <= NOT clk;
wait for 50 ns;
if (shift /= '0')then
error <= '1';
end if;
left_pressed and right_pressed are signals, not variables. So they should have the a value at any instance. If one of them changes, the connection to shift signal will be updated automatically.
Can someone please help me? Thanks.
Thanks.