Rev 3243 Rev 3690
1 ---------------------------------------------------------------------------------- 1 ----------------------------------------------------------------------------------
2 -- Company: www.mlab.cz 2 -- Company: www.mlab.cz
3 -- Based on code written by MIHO. 3 -- Based on code written by MIHO.
4 -- 4 --
5 -- Design Name: S3AN01A 5 -- Design Name: S3AN01A
6 -- Project Name: PulseGen 6 -- Project Name: PulseGen
7 -- Target Devices: XC3S50AN-4 7 -- Target Devices: XC3S50AN-4
8 -- Tool versions: ISE 13.3 8 -- Tool versions: ISE 13.3
9 -- Description: Sample of Pulse Generator at S3AN01A MLAB board. 9 -- Description: Sample of Pulse Generator at S3AN01A MLAB board.
10 -- 10 --
11 -- Dependencies: External PS/2 Keyboard has to be connected. 11 -- Dependencies: External PS/2 Keyboard has to be connected.
12 -- 12 --
13 -- Version: $Id: PulseGen.vhd 2534 2012-09-02 13:40:37Z kakl $ 13 -- Version: $Id: PulseGen.vhd 2534 2012-09-02 13:40:37Z kakl $
14 -- 14 --
15 ---------------------------------------------------------------------------------- 15 ----------------------------------------------------------------------------------
16   16  
17 library IEEE; 17 library IEEE;
18 use IEEE.STD_LOGIC_1164.ALL; 18 use IEEE.STD_LOGIC_1164.ALL;
19 use IEEE.numeric_std.ALL; 19 use IEEE.numeric_std.ALL;
20 use WORK.PS2_pkg.ALL; 20 use WORK.PS2_pkg.ALL;
21   21  
22 library UNISIM; 22 library UNISIM;
23 use UNISIM.vcomponents.all; 23 use UNISIM.vcomponents.all;
24   24  
25 entity PulseGen is 25 entity PulseGen is
26 generic ( 26 generic (
27 -- Top Value for 100MHz Clock Counter 27 -- Top Value for 100MHz Clock Counter
28 MAXCOUNT: integer := 30_000_000; 28 MAXCOUNT: integer := 30_000_000;
29 MUXCOUNT: integer := 100_000 -- LED Display Multiplex Clock Divider 29 MUXCOUNT: integer := 100_000 -- LED Display Multiplex Clock Divider
30 ); 30 );
31 port ( 31 port (
32 -- Main Clock 32 -- Main Clock
33 CLK100MHz: in std_logic; 33 CLK100MHz: in std_logic;
34   34  
35 -- Mode Signals (usualy not used) 35 -- Mode Signals (usualy not used)
36 M: in std_logic_vector(2 downto 0); 36 M: in std_logic_vector(2 downto 0);
37 VS: in std_logic_vector(2 downto 0); 37 VS: in std_logic_vector(2 downto 0);
38   38  
39 -- Dipswitch Inputs 39 -- Dipswitch Inputs
40 DIPSW: in std_logic_vector(7 downto 0); 40 DIPSW: in std_logic_vector(7 downto 0);
41   41  
42 -- Push Buttons 42 -- Push Buttons
43 PB: in std_logic_vector(3 downto 0); 43 PB: in std_logic_vector(3 downto 0);
44   44  
45 -- LED Bar Outputs 45 -- LED Bar Outputs
46 LED: out std_logic_vector(7 downto 0); 46 LED: out std_logic_vector(7 downto 0);
47   47  
48 -- LED Display (8 digit with 7 segments and ddecimal point) 48 -- LED Display (8 digit with 7 segments and ddecimal point)
49 LD_A_n: out std_logic; 49 LD_A_n: out std_logic;
50 LD_B_n: out std_logic; 50 LD_B_n: out std_logic;
51 LD_C_n: out std_logic; 51 LD_C_n: out std_logic;
52 LD_D_n: out std_logic; 52 LD_D_n: out std_logic;
53 LD_E_n: out std_logic; 53 LD_E_n: out std_logic;
54 LD_F_n: out std_logic; 54 LD_F_n: out std_logic;
55 LD_G_n: out std_logic; 55 LD_G_n: out std_logic;
56 LD_DP_n: out std_logic; 56 LD_DP_n: out std_logic;
57 LD_0_n: out std_logic; 57 LD_0_n: out std_logic;
58 LD_1_n: out std_logic; 58 LD_1_n: out std_logic;
59 LD_2_n: out std_logic; 59 LD_2_n: out std_logic;
60 LD_3_n: out std_logic; 60 LD_3_n: out std_logic;
61 LD_4_n: out std_logic; 61 LD_4_n: out std_logic;
62 LD_5_n: out std_logic; 62 LD_5_n: out std_logic;
63 LD_6_n: out std_logic; 63 LD_6_n: out std_logic;
64 LD_7_n: out std_logic; 64 LD_7_n: out std_logic;
65   65  
66 -- VGA Video Out Port 66 -- VGA Video Out Port
67 VGA_R: out std_logic_vector(1 downto 0); 67 VGA_R: out std_logic_vector(1 downto 0);
68 VGA_G: out std_logic_vector(1 downto 0); 68 VGA_G: out std_logic_vector(1 downto 0);
69 VGA_B: out std_logic_vector(1 downto 0); 69 VGA_B: out std_logic_vector(1 downto 0);
70 VGA_VS: out std_logic; 70 VGA_VS: out std_logic;
71 VGA_HS: out std_logic; 71 VGA_HS: out std_logic;
72   72  
73 -- Bank 1 Pins - Inputs for this Test 73 -- Bank 1 Pins - Inputs for this Test
74 B: inout std_logic_vector(24 downto 0); 74 B: inout std_logic_vector(24 downto 0);
75 75
76 -- PS/2 Bidirectional Port (open collector, J31 and J32) 76 -- PS/2 Bidirectional Port (open collector, J31 and J32)
77 -- PS2_CLK1: inout std_logic; 77 -- PS2_CLK1: inout std_logic;
78 -- PS2_DATA1: inout std_logic; 78 -- PS2_DATA1: inout std_logic;
79 PS2_CLK2: inout std_logic; 79 PS2_CLK2: inout std_logic;
80 PS2_DATA2: inout std_logic; 80 PS2_DATA2: inout std_logic;
81   81  
82 -- Diferencial Signals on 4 pin header (J7) 82 -- Diferencial Signals on 4 pin header (J7)
83 DIF1P: inout std_logic; 83 DIF1P: inout std_logic;
84 DIF1N: inout std_logic; 84 DIF1N: inout std_logic;
85 DIF2P: inout std_logic; 85 DIF2P: inout std_logic;
86 DIF2N: inout std_logic; 86 DIF2N: inout std_logic;
87 87
88   88  
89 -- I2C Signals (on connector J30) 89 -- I2C Signals (on connector J30)
90 I2C_SCL: inout std_logic; 90 I2C_SCL: inout std_logic;
91 I2C_SDA: inout std_logic; 91 I2C_SDA: inout std_logic;
92   92  
93 -- Diferencial Signals on SATA like connectors (not SATA capable, J28 and J29) 93 -- Diferencial Signals on SATA like connectors (not SATA capable, J28 and J29)
94 SD1AP: inout std_logic; 94 SD1AP: inout std_logic;
95 SD1AN: inout std_logic; 95 SD1AN: inout std_logic;
96 SD1BP: inout std_logic; 96 SD1BP: inout std_logic;
97 SD1BN: inout std_logic; 97 SD1BN: inout std_logic;
98 SD2AP: inout std_logic; 98 SD2AP: inout std_logic;
99 SD2AN: inout std_logic; 99 SD2AN: inout std_logic;
100 SD2BP: inout std_logic; 100 SD2BP: inout std_logic;
101 SD2BN: inout std_logic; 101 SD2BN: inout std_logic;
102   102  
103 -- Analog In Out 103 -- Analog In Out
104 ANA_OUTD: out std_logic; 104 ANA_OUTD: out std_logic;
105 ANA_REFD: out std_logic; 105 ANA_REFD: out std_logic;
106 ANA_IND: in std_logic; 106 ANA_IND: in std_logic;
107   107  
108 -- SPI Memory Interface 108 -- SPI Memory Interface
109 SPI_CS_n: inout std_logic; 109 SPI_CS_n: inout std_logic;
110 SPI_DO: inout std_logic; 110 SPI_DO: inout std_logic;
111 SPI_DI: inout std_logic; 111 SPI_DI: inout std_logic;
112 SPI_CLK: inout std_logic; 112 SPI_CLK: inout std_logic;
113 SPI_WP_n: inout std_logic 113 SPI_WP_n: inout std_logic
114 ); 114 );
115 end entity PulseGen; 115 end entity PulseGen;
116   116  
117   117  
118 architecture PulseGen_a of PulseGen is 118 architecture PulseGen_a of PulseGen is
119   119  
120 function to_bcd ( bin : std_logic_vector(7 downto 0) ) return std_logic_vector is 120 function to_bcd ( bin : std_logic_vector(7 downto 0) ) return std_logic_vector is
121 variable i : integer:=0; 121 variable i : integer:=0;
122 variable mybcd : std_logic_vector(11 downto 0) := (others => '0'); 122 variable mybcd : std_logic_vector(11 downto 0) := (others => '0');
123 variable bint : std_logic_vector(7 downto 0) := bin; 123 variable bint : std_logic_vector(7 downto 0) := bin;
124 begin 124 begin
125 for i in 0 to 7 loop -- repeating 8 times. 125 for i in 0 to 7 loop -- repeating 8 times.
126 mybcd(11 downto 1) := mybcd(10 downto 0); --shifting the bits. 126 mybcd(11 downto 1) := mybcd(10 downto 0); --shifting the bits.
127 mybcd(0) := bint(7); 127 mybcd(0) := bint(7);
128 bint(7 downto 1) := bint(6 downto 0); 128 bint(7 downto 1) := bint(6 downto 0);
129 bint(0) :='0'; 129 bint(0) :='0';
130   130  
131   131  
132 if(i < 7 and mybcd(3 downto 0) > "0100") then --add 3 if BCD digit is greater than 4. 132 if(i < 7 and mybcd(3 downto 0) > "0100") then --add 3 if BCD digit is greater than 4.
133 mybcd(3 downto 0) := std_logic_vector(unsigned(mybcd(3 downto 0)) + 3); 133 mybcd(3 downto 0) := std_logic_vector(unsigned(mybcd(3 downto 0)) + 3);
134 end if; 134 end if;
135   135  
136 if(i < 7 and mybcd(7 downto 4) > "0100") then --add 3 if BCD digit is greater than 4. 136 if(i < 7 and mybcd(7 downto 4) > "0100") then --add 3 if BCD digit is greater than 4.
137 mybcd(7 downto 4) := std_logic_vector(unsigned(mybcd(7 downto 4)) + 3); 137 mybcd(7 downto 4) := std_logic_vector(unsigned(mybcd(7 downto 4)) + 3);
138 end if; 138 end if;
139   139  
140 if(i < 7 and mybcd(11 downto 8) > "0100") then --add 3 if BCD digit is greater than 4. 140 if(i < 7 and mybcd(11 downto 8) > "0100") then --add 3 if BCD digit is greater than 4.
141 mybcd(11 downto 8) := std_logic_vector(unsigned(mybcd(11 downto 8)) + 3); 141 mybcd(11 downto 8) := std_logic_vector(unsigned(mybcd(11 downto 8)) + 3);
142 end if; 142 end if;
143 end loop; 143 end loop;
144 144
145 return mybcd; 145 return mybcd;
146 end to_bcd; 146 end to_bcd;
147   147  
148   148  
149 -- O1: ____|^^^^^^^|______ 149 -- O1: ____|^^^^^^^|______
150 -- O2: _________|^^|______ 150 -- O2: _________|^^|______
151 -- t1 t2 151 -- t1 t2
152 -- t1/t2 is from 0 to 2000 ns; repeating frequency is cca 1,6 kHz 152 -- t1/t2 is from 0 to 2000 ns; repeating frequency is cca 1,6 kHz
153   153  
154 signal T1: unsigned(15 downto 0) := X"000a"; -- Time t1 to Impuls at O2 154 signal T1: unsigned(15 downto 0) := X"000a"; -- Time t1 to Impuls at O2
155 signal T2: unsigned(15 downto 0) := X"0001"; -- Duration t2 of impuls at O2 155 signal T2: unsigned(15 downto 0) := X"0001"; -- Duration t2 of impuls at O2
156 signal CT0: unsigned(15 downto 0) := X"0000"; -- Timer 156 signal CT0: unsigned(15 downto 0) := X"0000"; -- Timer
157 signal O1: std_logic := '0'; -- Output 1 157 signal O1: std_logic := '0'; -- Output 1
158 signal O2: std_logic := '0'; -- Output 2 158 signal O2: std_logic := '0'; -- Output 2
159 signal CTburst: unsigned(15 downto 0) := X"0000"; -- Pulse counter 159 signal CTburst: unsigned(15 downto 0) := X"0000"; -- Pulse counter
160 160
161 -- LED Demo Signals 161 -- LED Demo Signals
162 -- ---------------- 162 -- ----------------
163   163  
164 signal Counter: unsigned(31 downto 0) := X"00000000"; -- Main Counter (binary) 164 signal Counter: unsigned(31 downto 0) := X"00000000"; -- Main Counter (binary)
165 signal Bar: unsigned(7 downto 0) := X"00"; -- Counter for Bar output (binary) 165 signal Bar: unsigned(7 downto 0) := X"00"; -- Counter for Bar output (binary)
166   166  
167 signal FastBlink: std_logic; -- Signal mask for half intensity LED output (several kHz) 167 signal FastBlink: std_logic; -- Signal mask for half intensity LED output (several kHz)
168   168  
169 -- LED Display 169 -- LED Display
170 -- ----------- 170 -- -----------
171   171  
172 signal Number: std_logic_vector(32 downto 0); -- LED Display Input 172 signal Number: std_logic_vector(32 downto 0); -- LED Display Input
173 signal MuxCounter: unsigned(31 downto 0) := (others => '0'); -- LED Multiplex - Multiplex Clock Divider 173 signal MuxCounter: unsigned(31 downto 0) := (others => '0'); -- LED Multiplex - Multiplex Clock Divider
174 signal Enable: std_logic; 174 signal Enable: std_logic;
175 signal Digits: std_logic_vector(7 downto 0) := X"01"; -- LED Multiplex - Digit Counter - LED Digit Output 175 signal Digits: std_logic_vector(7 downto 0) := X"01"; -- LED Multiplex - Digit Counter - LED Digit Output
176 signal Segments: std_logic_vector(0 to 7); -- LED Segment Output 176 signal Segments: std_logic_vector(0 to 7); -- LED Segment Output
177 signal Code: std_logic_vector(3 downto 0); -- BCD to 7 Segment Decoder Output 177 signal Code: std_logic_vector(3 downto 0); -- BCD to 7 Segment Decoder Output
178   178  
179 -- PS/2 Port 179 -- PS/2 Port
180 -- --------- 180 -- ---------
181   181  
182 -- Interface Signals 182 -- Interface Signals
183 signal PS2_Code: std_logic_vector(7 downto 0); -- Key Scan Code 183 signal PS2_Code: std_logic_vector(7 downto 0); -- Key Scan Code
184 signal PS2_Attribs: std_logic_vector(7 downto 0); -- State of Shifts for Scan Code 184 signal PS2_Attribs: std_logic_vector(7 downto 0); -- State of Shifts for Scan Code
185 signal PS2_Valid: boolean; -- Valid Data (synchronous with Main Clock) 185 signal PS2_Valid: boolean; -- Valid Data (synchronous with Main Clock)
186 signal PS2_Shifts: std_logic_vector(9 downto 0); -- Immediate (life) State of Shifts for Scan Code 186 signal PS2_Shifts: std_logic_vector(9 downto 0); -- Immediate (life) State of Shifts for Scan Code
187   187  
188 -- Result 188 -- Result
189 signal PS2_Result: std_logic_vector(15 downto 0); -- Result (memory) 189 signal PS2_Result: std_logic_vector(15 downto 0); -- Result (memory)
190   190  
191 -- signal Key: std_logic_vector(7 downto 0); -- Cislo na klavese 191 -- signal Key: std_logic_vector(7 downto 0); -- Cislo na klavese
192 192
193 -- VGA Demo Signals 193 -- VGA Demo Signals
194 -- ---------------- 194 -- ----------------
195   195  
196 signal CLK: std_logic; -- Main Clock - global distribution network 196 signal CLK: std_logic; -- Main Clock - global distribution network
197 signal CLKVGAi: std_logic; -- DCM Clock Out (40MHz Pixel Clock) - internal connection from DCM to BUFG 197 signal CLKVGAi: std_logic; -- DCM Clock Out (40MHz Pixel Clock) - internal connection from DCM to BUFG
198 signal CLKVGA: std_logic; -- DCM Clock Out (40MHz Pixel Clock) - global distribution network 198 signal CLKVGA: std_logic; -- DCM Clock Out (40MHz Pixel Clock) - global distribution network
199 signal VGA_Blank: boolean; -- Blank 199 signal VGA_Blank: boolean; -- Blank
200 signal VGA_Hsync: boolean; -- Horisontal Synchronisation 200 signal VGA_Hsync: boolean; -- Horisontal Synchronisation
201 signal VGA_Vsync: boolean; -- Vertical Synchronisation 201 signal VGA_Vsync: boolean; -- Vertical Synchronisation
202   202  
203 signal VCounter: unsigned(9 downto 0) := "0000000000"; -- Vertical Counter 203 signal VCounter: unsigned(9 downto 0) := "0000000000"; -- Vertical Counter
204 signal HCounter: unsigned(10 downto 0) := "00000000000"; -- Horisontal Counter 204 signal HCounter: unsigned(10 downto 0) := "00000000000"; -- Horisontal Counter
205   205  
206 signal PinState: std_logic; -- For IB1 Port Test 206 signal PinState: std_logic; -- For IB1 Port Test
207 signal Red: std_logic_vector(1 downto 0); 207 signal Red: std_logic_vector(1 downto 0);
208 signal Green: std_logic_vector(1 downto 0); 208 signal Green: std_logic_vector(1 downto 0);
209 signal Blue: std_logic_vector(1 downto 0); 209 signal Blue: std_logic_vector(1 downto 0);
210   210  
211 -- ADDA 211 -- ADDA
212 signal ADDA_DataIn: std_logic_vector(7 downto 0); 212 signal ADDA_DataIn: std_logic_vector(7 downto 0);
213   213  
214 begin 214 begin
215   215  
216 -- Basic LED Blinking Test 216 -- Basic LED Blinking Test
217 -- ======================= 217 -- =======================
218   218  
219 -- LED Bar Counter 219 -- LED Bar Counter
220 process (CLK100MHz) 220 process (CLK100MHz)
221 begin 221 begin
222 if rising_edge(CLK100MHz) then 222 if rising_edge(CLK100MHz) then
223 if Counter < MAXCOUNT-1 then 223 if Counter < MAXCOUNT-1 then
224 Counter <= Counter + 1; 224 Counter <= Counter + 1;
225 else 225 else
226 Counter <= (others => '0'); 226 Counter <= (others => '0');
227 Bar <= Bar + 1; 227 Bar <= Bar + 1;
228 end if; 228 end if;
229 end if; 229 end if;
230 end process; 230 end process;
231   231  
232 LED <= std_logic_vector(Bar); -- LED Bar Connected to Counter 232 LED <= std_logic_vector(Bar); -- LED Bar Connected to Counter
233   233  
234 FastBlink <= Counter(13) and Counter(14) and Counter(15) and Counter(16); -- 1/16 intensity 234 FastBlink <= Counter(13) and Counter(14) and Counter(15) and Counter(16); -- 1/16 intensity
235   235  
236 -- LED Display (multiplexed) 236 -- LED Display (multiplexed)
237 -- ========================= 237 -- =========================
238   238  
239 -- Connect LED Display Output Ports (negative outputs) 239 -- Connect LED Display Output Ports (negative outputs)
240 LD_A_n <= not (Segments(0) and Enable); 240 LD_A_n <= not (Segments(0) and Enable);
241 LD_B_n <= not (Segments(1) and Enable); 241 LD_B_n <= not (Segments(1) and Enable);
242 LD_C_n <= not (Segments(2) and Enable); 242 LD_C_n <= not (Segments(2) and Enable);
243 LD_D_n <= not (Segments(3) and Enable); 243 LD_D_n <= not (Segments(3) and Enable);
244 LD_E_n <= not (Segments(4) and Enable); 244 LD_E_n <= not (Segments(4) and Enable);
245 LD_F_n <= not (Segments(5) and Enable); 245 LD_F_n <= not (Segments(5) and Enable);
246 LD_G_n <= not (Segments(6) and Enable); 246 LD_G_n <= not (Segments(6) and Enable);
247 LD_DP_n <= not (Segments(7) and Enable); 247 LD_DP_n <= not (Segments(7) and Enable);
248   248  
249 LD_0_n <= not Digits(0); 249 LD_0_n <= not Digits(0);
250 LD_1_n <= not Digits(1); 250 LD_1_n <= not Digits(1);
251 LD_2_n <= not Digits(2); 251 LD_2_n <= not Digits(2);
252 LD_3_n <= not Digits(3); 252 LD_3_n <= not Digits(3);
253 LD_4_n <= not Digits(4); 253 LD_4_n <= not Digits(4);
254 LD_5_n <= not Digits(5); 254 LD_5_n <= not Digits(5);
255 LD_6_n <= not Digits(6); 255 LD_6_n <= not Digits(6);
256 LD_7_n <= not Digits(7); 256 LD_7_n <= not Digits(7);
257   257  
258 -- Time Multiplex 258 -- Time Multiplex
259 process (CLK100MHz) 259 process (CLK100MHz)
260 begin 260 begin
261 if rising_edge(CLK100MHz) then 261 if rising_edge(CLK100MHz) then
262 if MuxCounter < MUXCOUNT-1 then 262 if MuxCounter < MUXCOUNT-1 then
263 MuxCounter <= MuxCounter + 1; 263 MuxCounter <= MuxCounter + 1;
264 else 264 else
265 MuxCounter <= (others => '0'); 265 MuxCounter <= (others => '0');
266 Digits(7 downto 0) <= Digits(6 downto 0) & Digits(7); -- Rotate Left 266 Digits(7 downto 0) <= Digits(6 downto 0) & Digits(7); -- Rotate Left
267 Enable <= '0'; 267 Enable <= '0';
268 end if; 268 end if;
269 if MuxCounter > (MUXCOUNT-4) then 269 if MuxCounter > (MUXCOUNT-4) then
270 Enable <= '1'; 270 Enable <= '1';
271 end if; 271 end if;
272 end if; 272 end if;
273 end process; 273 end process;
274   274  
275 -- BCD to 7 Segmet Decoder 275 -- BCD to 7 Segmet Decoder
276 -- -- A 276 -- -- A
277 -- | | F B 277 -- | | F B
278 -- -- G 278 -- -- G
279 -- | | E C 279 -- | | E C
280 -- -- D H 280 -- -- D H
281 -- ABCDEFGH 281 -- ABCDEFGH
282 Segments <= "11111100" when Code="0000" else -- Digit 0 282 Segments <= "11111100" when Code="0000" else -- Digit 0
283 "01100000" when Code="0001" else -- Digit 1 283 "01100000" when Code="0001" else -- Digit 1
284 "11011010" when Code="0010" else -- Digit 2 284 "11011010" when Code="0010" else -- Digit 2
285 "11110010" when Code="0011" else -- Digit 3 285 "11110010" when Code="0011" else -- Digit 3
286 "01100110" when Code="0100" else -- Digit 4 286 "01100110" when Code="0100" else -- Digit 4
287 "10110110" when Code="0101" else -- Digit 5 287 "10110110" when Code="0101" else -- Digit 5
288 "10111110" when Code="0110" else -- Digit 6 288 "10111110" when Code="0110" else -- Digit 6
289 "11100000" when Code="0111" else -- Digit 7 289 "11100000" when Code="0111" else -- Digit 7
290 "11111110" when Code="1000" else -- Digit 8 290 "11111110" when Code="1000" else -- Digit 8
291 "11110110" when Code="1001" else -- Digit 9 291 "11110110" when Code="1001" else -- Digit 9
292 "11101110" when Code="1010" else -- Digit A 292 "11101110" when Code="1010" else -- Digit A
293 "00111110" when Code="1011" else -- Digit b 293 "00111110" when Code="1011" else -- Digit b
294 "10011100" when Code="1100" else -- Digit C 294 "10011100" when Code="1100" else -- Digit C
295 "01111010" when Code="1101" else -- Digit d 295 "01111010" when Code="1101" else -- Digit d
296 "10011110" when Code="1110" else -- Digit E 296 "10011110" when Code="1110" else -- Digit E
297 "10001110" when Code="1111" else -- Digit F 297 "10001110" when Code="1111" else -- Digit F
298 "00000000"; 298 "00000000";
299   299  
300 Code <= Number( 3 downto 0) when Digits="00000001" else 300 Code <= Number( 3 downto 0) when Digits="00000001" else
301 Number( 7 downto 4) when Digits="00000010" else 301 Number( 7 downto 4) when Digits="00000010" else
302 Number(11 downto 8) when Digits="00000100" else 302 Number(11 downto 8) when Digits="00000100" else
303 Number(15 downto 12) when Digits="00001000" else 303 Number(15 downto 12) when Digits="00001000" else
304 Number(19 downto 16) when Digits="00010000" else 304 Number(19 downto 16) when Digits="00010000" else
305 Number(23 downto 20) when Digits="00100000" else 305 Number(23 downto 20) when Digits="00100000" else
306 Number(27 downto 24) when Digits="01000000" else 306 Number(27 downto 24) when Digits="01000000" else
307 Number(31 downto 28) when Digits="10000000" else 307 Number(31 downto 28) when Digits="10000000" else
308 "0000"; 308 "0000";
309   309  
310 -- Key <= "00000000" when PS2_Result(7 downto 0)=X"70" else -- Digit 0 310 -- Key <= "00000000" when PS2_Result(7 downto 0)=X"70" else -- Digit 0
311 -- "00000001" when PS2_Result(7 downto 0)=X"69" else -- Digit 1 311 -- "00000001" when PS2_Result(7 downto 0)=X"69" else -- Digit 1
312 -- "00000010" when PS2_Result(7 downto 0)=X"72" else -- Digit 2 312 -- "00000010" when PS2_Result(7 downto 0)=X"72" else -- Digit 2
313 -- "11111111"; 313 -- "11111111";
314 314
315 -- Number(31 downto 28) <= Key(3 downto 0); 315 -- Number(31 downto 28) <= Key(3 downto 0);
316   316  
317 -- Number( 7 downto 0) <= std_logic_vector(BAR); 317 -- Number( 7 downto 0) <= std_logic_vector(BAR);
318 -- Number(31 downto 24) <= DIPSW; 318 -- Number(31 downto 24) <= DIPSW;
319   319  
320 -- PS/2 Port 320 -- PS/2 Port
321 -- ========= 321 -- =========
322   322  
323 -- Instantiate PS/2 Keyboard Interface Handler 323 -- Instantiate PS/2 Keyboard Interface Handler
324 PS2_Keyboard: PS2 generic map( 324 PS2_Keyboard: PS2 generic map(
325 CLKFREQ => 100_000_000 325 CLKFREQ => 100_000_000
326 ) 326 )
327 port map( 327 port map(
328 -- Main Clock 328 -- Main Clock
329 Clk => CLK100MHz, 329 Clk => CLK100MHz,
330   330  
331 -- PS/2 Port 331 -- PS/2 Port
332 PS2_Clk => PS2_CLK2, 332 PS2_Clk => PS2_CLK2,
333 PS2_Data => PS2_DATA2, 333 PS2_Data => PS2_DATA2,
334   334  
335 -- Result - valid when PS2_Valid 335 -- Result - valid when PS2_Valid
336 PS2_Code => PS2_Code, 336 PS2_Code => PS2_Code,
337 PS2_Attribs => PS2_Attribs, 337 PS2_Attribs => PS2_Attribs,
338 PS2_Valid => PS2_Valid, 338 PS2_Valid => PS2_Valid,
339   339  
340 -- Immediate State of Shifts 340 -- Immediate State of Shifts
341 PS2_Shifts => PS2_Shifts 341 PS2_Shifts => PS2_Shifts
342 ); -- PS2 342 ); -- PS2
343   343  
344 process (CLK100MHz) 344 process (CLK100MHz)
345 begin 345 begin
346 if rising_edge(CLK100MHz) then 346 if rising_edge(CLK100MHz) then
347 if PS2_Valid and PS2_Attribs(7)='0' then 347 if PS2_Valid and PS2_Attribs(7)='0' then
348 -- Valid Scan Code with no Break Attribute 348 -- Valid Scan Code with no Break Attribute
349 PS2_Result( 7 downto 0) <= PS2_Code; 349 PS2_Result( 7 downto 0) <= PS2_Code;
350 PS2_Result(15 downto 8) <= PS2_Attribs; 350 PS2_Result(15 downto 8) <= PS2_Attribs;
351 end if; 351 end if;
352 352
353 if PS2_Valid and PS2_Attribs(7)='0' then 353 if PS2_Valid and PS2_Attribs(7)='0' then
354 if PS2_Code = X"74" and T1<2000 then T1<=T1+1; end if; 354 if PS2_Code = X"74" and T1<2000 then T1<=T1+1; end if;
355 if PS2_Code = X"6b" and T1>0 then T1<=T1-1; end if; 355 if PS2_Code = X"6b" and T1>0 then T1<=T1-1; end if;
356 if PS2_Code = X"75" and T2<200 then T2<=T2+1; end if; 356 if PS2_Code = X"75" and T2<200 then T2<=T2+1; end if;
357 if PS2_Code = X"72" and T2>0 then T2<=T2-1; end if; 357 if PS2_Code = X"72" and T2>0 then T2<=T2-1; end if;
358 CT0<=X"0000"; 358 CT0<=X"0000";
359 O1<='0'; 359 O1<='0';
360 O2<='0'; 360 O2<='0';
361 CTburst<=X"0000"; 361 CTburst<=X"0000";
362 end if; 362 end if;
363   363  
364 if PB(0)='1' then 364 if PB(0)='1' then
365 T1<=X"0000"; 365 T1<=X"0000";
366 T2<=X"0000"; 366 T2<=X"0000";
367 end if; 367 end if;
368 368
369 if DIPSW(0)='1' then 369 if DIPSW(0)='1' then
370 if CT0>X"F000" then 370 if CT0>X"F000" then
371 CT0<=X"0000"; 371 CT0<=X"0000";
372 else 372 else
373 CT0<=CT0+1; 373 CT0<=CT0+1;
374 end if; 374 end if;
375 else 375 else
376 if CT0>X"0200" then 376 if CT0>X"0200" then
377 CT0<=X"0000"; 377 CT0<=X"0000";
378 else 378 else
379 CT0<=CT0+1; 379 CT0<=CT0+1;
380 end if; 380 end if;
381 end if; 381 end if;
382 382
383 if CTburst>2000 then 383 if CTburst>2000 then
384 CTburst<=X"0000"; 384 CTburst<=X"0000";
385 end if; 385 end if;
386   386  
387 if (CTburst<1000) or (DIPSW(1)='0') then 387 if (CTburst<1000) or (DIPSW(1)='0') then
388 if CT0=X"0000" then 388 if CT0=X"0000" then
389 O1<='1'; 389 O1<='1';
390 end if; 390 end if;
391 391
392 if CT0=T1+X"0000" then 392 if CT0=T1+X"0000" then
393 O2<='1'; 393 O2<='1';
394 end if; 394 end if;
395 end if; 395 end if;
396 396
397 if CT0=T2+T1+X"0000" then 397 if CT0=T2+T1+X"0000" then
398 O1<='0'; 398 O1<='0';
399 O2<='0'; 399 O2<='0';
400 CTburst<=CTburst+1; 400 CTburst<=CTburst+1;
401 end if; 401 end if;
402 402
403 end if; 403 end if;
404 404
405 end process; 405 end process;
406   406  
407 -- Display Result on LED 407 -- Display Result on LED
408 Number(3 downto 0) <= (others=>'0'); 408 Number(3 downto 0) <= (others=>'0');
409 Number(15 downto 4) <= to_bcd(std_logic_vector(T2)); 409 Number(15 downto 4) <= to_bcd(std_logic_vector(T2));
410 Number(19 downto 16) <= (others=>'0'); 410 Number(19 downto 16) <= (others=>'0');
411 Number(31 downto 20) <= to_bcd(std_logic_vector(T1)); 411 Number(31 downto 20) <= to_bcd(std_logic_vector(T1));
412 412
413   413  
414 -- Test Diferencial In/Outs 414 -- Test Diferencial In/Outs
415 -- ======================== 415 -- ========================
416   416  
417 -- Output Signal on SATA Connector 417 -- Output Signal on SATA Connector
418 SD1AP <= Bar(0); 418 SD1AP <= Bar(0);
419 SD1AN <= Bar(1); 419 SD1AN <= Bar(1);
420 SD1BP <= Bar(2); 420 SD1BP <= Bar(2);
421 SD1BN <= Bar(3); 421 SD1BN <= Bar(3);
422   422  
423 -- Input Here via SATA Cable 423 -- Input Here via SATA Cable
424 SD2AP <= 'Z'; 424 SD2AP <= 'Z';
425 SD2AN <= 'Z'; 425 SD2AN <= 'Z';
426 SD2BP <= 'Z'; 426 SD2BP <= 'Z';
427 SD2BN <= 'Z'; 427 SD2BN <= 'Z';
428   428  
429 -- Copy SATA Connector Input to 4 pin header (J7) - Connect these signals to B port input to visualize them 429 -- Copy SATA Connector Input to 4 pin header (J7) - Connect these signals to B port input to visualize them
430 -- !!!!!!!!!!!! Pulse Generator Outputs !!!!!!!!!!!!!!!!!!!!! 430 -- !!!!!!!!!!!! Pulse Generator Outputs !!!!!!!!!!!!!!!!!!!!!
431 DIF1P <= O1; 431 DIF1P <= O1;
432 B(0) <= O1; 432 B(0) <= O1;
433 DIF1N <= not O1; 433 DIF1N <= not O1;
434 B(1) <= not O1; 434 B(1) <= not O1;
435 DIF2P <= O2; 435 DIF2P <= O2;
436 B(2) <= O2; 436 B(2) <= O2;
437 DIF2N <= not O2; 437 DIF2N <= not O2;
438 B(3) <= not O2; 438 B(3) <= not O2;
439 439
440 VGA_R(0) <= O1; 440 VGA_R(0) <= O1;
441 VGA_R(1) <= O2; 441 VGA_R(1) <= O2;
442   442  
443 -- Unused Signals 443 -- Unused Signals
444 -- ============== 444 -- ==============
445   445  
446 -- I2C Signals (on connector J30) 446 -- I2C Signals (on connector J30)
447 I2C_SCL <= 'Z'; 447 I2C_SCL <= 'Z';
448 I2C_SDA <= 'Z'; 448 I2C_SDA <= 'Z';
449   449  
450 -- SPI Memory Interface 450 -- SPI Memory Interface
451 SPI_CS_n <= 'Z'; 451 SPI_CS_n <= 'Z';
452 SPI_DO <= 'Z'; 452 SPI_DO <= 'Z';
453 SPI_DI <= 'Z'; 453 SPI_DI <= 'Z';
454 SPI_CLK <= 'Z'; 454 SPI_CLK <= 'Z';
455 SPI_WP_n <= 'Z'; 455 SPI_WP_n <= 'Z';
456   456  
457 ANA_OUTD <= 'Z'; 457 ANA_OUTD <= 'Z';
458 ANA_REFD <= 'Z'; 458 ANA_REFD <= 'Z';
459   459  
460 VGA_R <= "ZZ"; 460 VGA_R <= "ZZ";
461 VGA_G <= "ZZ"; 461 VGA_G <= "ZZ";
462 VGA_B <= "ZZ"; 462 VGA_B <= "ZZ";
463 VGA_VS <= 'Z'; 463 VGA_VS <= 'Z';
464 VGA_HS <= 'Z'; 464 VGA_HS <= 'Z';
465   465  
466 end architecture PulseGen_a; 466 end architecture PulseGen_a;