Ob es funktioniert zeigt dir die Simulation...
Aber hier mal ein paar kurze Anmerkungen:
1 | --syncronize external signals
|
2 | process(clk)
|
3 | begin
|
4 | if rising_edge(clk) then
|
5 | ps2_clk_int <= ps2_clk;
|
6 | ps2_data_int <= ps2_data;
|
7 | end if;
|
8 | end process;
|
Nur 1 FF zum einsynchronisieren ist (abhängig vom Systemtakt) u.U. zu
wenig. Aber besser eins als keins... ;-)
1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 | USE ieee.STD_LOGIC_UNSIGNED.all;
|
Nimm statt der alten Synopsys-Lib (fehlt da nicht noch die use
IEEE.STD_LOGIC_ARITH.ALL) bessere die genormte numeric_std:
1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 | USE ieee.NUMERIC_STD.all;
|
Und dann machst du am besten (getreu dem Motto: Mit Vektoren rechnet man
nicht!) deinen Zähler gleich in integer, dann ist er natürlichsprachig
lesbar:
1 | signal count: integer range 0 to 10:=0;
|
2 | :
|
3 | begin
|
4 |
|
5 | --detect start bit
|
6 | process(clk)
|
7 | begin
|
8 | if rising_edge(clk) then
|
9 | :
|
10 | if count = 10 then
|
11 | started <= '0';
|
12 | end if;
|
13 | end if;
|
14 | end process;
|
15 |
|
16 | --shift in data
|
17 | process(clk)
|
18 | begin
|
19 | if rising_edge(clk) then
|
20 | if ps2_clk_falling_edge = '1' and started = '1' then
|
21 | count <= count + 1;
|
22 | :
|
23 | end if;
|
24 |
|
25 | if count = 10 then
|
26 | count <= 0;
|
27 | end if;
|
28 | end if;
|
29 | end process;
|
30 |
|
31 | --decode scancode
|
32 | process(clk)
|
33 | begin
|
34 | if rising_edge(clk) then
|
35 | :
|
36 | if count = 10 and data(9) = '1' then
|