当前位置:网站首页>[notes] take notes again -- learn by doing Verilog HDL – 008
[notes] take notes again -- learn by doing Verilog HDL – 008
2022-06-29 20:01:00 【51CTO】
lab08—PS/2 decode
DE2 There's one on PS/2 Interface , It can be connected to keyboard or mouse , This experiment uses PS/2 A keyboard is attached to the interface , And decode the keys , Press down X key ,DE2 Upper LEDG3-0 Move right ; Press down W key ,LEDG3-0 Move left , Press down Ctrl, reverse .
1. PS/2 brief introduction
Research PS/2 decode , Just care about the data and clock pins . The picture below is PS/2 Sequence diagram of the protocol , Read data is valid on the falling edge of the clock .PS/2 The clock for is approximately 10khz.
PS/2 Yizhen yes 11 position , Decoding it , Just focus on 1-8 Digit bit .
Keyboard code :
Keyboard coding is divided into pass code and break code , Press to pass the code , Release as broken code . such as , Press down W Don't put , About output per second 10 individual 0x1d. Release W, Output 0xf0 0x1d. Encoding rules , Only one valid output at a time .
2. Design
ps2_module.v Including level detection module detect_module.v and ps2 Decoding module ps2_decode_module.v.detect_module.v Used to detect ps2 The falling edge of the clock ,ps2_decode_module.v For each frame of data (11 position ) Decoding and filtering , Output 8 Bit ps2_data And a high pulse ps2_done, Indicates that decoding is complete .
detect_module.v
1 /**
2 * File name: detect_module.v
3 *
4 */
5
6 module detect_module
7 (
8 clk, rst_n,
9 ps2_clk,
10 h2l_sig
11 );
12
13 input clk;
14 input rst_n;
15 input ps2_clk;
16 output h2l_sig;
17
18 reg h2l_f1;
19 reg h2l_f2;
20
21 always @(posedge clk or negedge rst_n)
22 if (!rst_n)
23 begin
24 h2l_f1 <= 1'b1;
25 h2l_f2 <= 1'b1;
26 end
27 else
28 begin
29 h2l_f1 <= ps2_clk;
30 h2l_f2 <= h2l_f1;
31 end
32
33 assign h2l_sig = h2l_f2 & !h2l_f1;
34
35 endmodule
36
- 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.
- 32.
- 33.
- 34.
- 35.
- 36.
ps2_decode_module.v
1 /**
2 * File name : ps2_decode_module.v
3 *
4 */
5
6 module ps2_decode_module
7 (
8 clk, rst_n,
9 h2l_sig, ps2_data_in,
10 ps2_data, ps2_done
11 );
12
13 input clk;
14 input rst_n;
15 input h2l_sig;
16 input ps2_data_in;
17 output [7:0] ps2_data;
18 output ps2_done;
19
20 reg [7:0] rdata;
21 reg [4:0] i;
22 reg isshift;
23 reg isdone;
24
25 always @(posedge clk or negedge rst_n)
26 if (!rst_n)
27 begin
28 rdata <= 8'd0;
29 i <= 5'd0;
30 isdone <= 1'b0;
31 end
32 else
33 case (i)
34 5'd0:
35 if (h2l_sig) i <= i + 1'b1;
36
37 5'd1, 5'd2, 5'd3, 5'd4, 5'd5, 5'd6, 5'd7, 5'd8:
38 if (h2l_sig)
39 begin
40 i <= i + 1'b1;
41 rdata[i-1] <= ps2_data_in;
42 end
43
44 5'd9, 5'd10:
45 if (h2l_sig)
46 i <= i + 1'b1;
47
48 5'd11:
49 if (rdata == 8'hf0)
50 i <= 5'd12;
51 else
52 i <= 5'd23;
53
54 5'd12, 5'd13, 5'd14, 5'd15, 5'd16, 5'd17, 5'd18, 5'd19, 5'd20, 5'd21, 5'd22:
55 if (h2l_sig)
56 i <= i + 1'b1;
57
58 5'd23:
59 begin
60 i <= i + 1'b1;
61 isdone <= 1'b1;
62 end
63
64 5'd24:
65 begin
66 i <= 5'd0;
67 isdone <= 1'b0;
68 end
69 endcase
70
71 assign ps2_data = rdata;
72 assign ps2_done = isdone;
73
74 endmodule
75
76
77
- 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.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
ps2_decode_module.v The trick is to ignore irrelevant data bits directly , utilize i <= i + 1 skip , The first 48 Line to determine whether it is a general code , Ignore the general code after code break .
ps2_module.v
1 /**
2 * File name: ps2_module.v
3 *
4 */
5
6 module ps2_module
7 (
8 clk, rst_n,
9 ps2_clk, ps2_data_in,
10 ps2_data, ps2_done
11 );
12
13 input clk;
14 input rst_n;
15 input ps2_clk;
16 input ps2_data_in;
17 output [7:0] ps2_data;
18 output ps2_done;
19
20 wire h2l_sig;
21
22 detect_module U1
23 (
24 .clk (clk),
25 .rst_n (rst_n),
26 .ps2_clk (ps2_clk),
27 .h2l_sig (h2l_sig)
28 );
29
30 ps2_decode_module U2
31 (
32 .clk (clk),
33 .rst_n (rst_n),
34 .h2l_sig (h2l_sig),
35 .ps2_data_in (ps2_data_in),
36 .ps2_data (ps2_data),
37 .ps2_done (ps2_done)
38 );
39
40 endmodule
41
- 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.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
cmd_control_module.v
1 /**
2 * File name: cmd_control_module.v
3 *
4 */
5
6 module cmd_control_module
7 (
8 clk, rst_n,
9 ps2_done, ps2_data,
10 data_out
11 );
12
13 input clk;
14 input rst_n;
15 input ps2_done;
16 input [7:0] ps2_data;
17 output [3:0] data_out;
18
19 reg [3:0] rdata;
20
21 always @(posedge clk or negedge rst_n)
22 if (!rst_n)
23 begin
24 rdata <= 4'b0001;
25 end
26 else if (ps2_done)
27 case (ps2_data)
28 8'h1d: //W
29 rdata <= {rdata[2:0], rdata[3]};
30
31 8'h22: //X
32 rdata <= {rdata[0], rdata[3:1]};
33
34 8'h14: //Ctrl
35 rdata <= {rdata[0], rdata[1], rdata[2], rdata[3]};
36
37 endcase
38
39 assign data_out = rdata;
40
41 endmodule
42
- 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.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
exp08_module.v
1 /**
2 * File name: exp08_module.v
3 * Function: use the ps/2 keyboard to test the de2's ps/2
4 * interface.
5 * x--right shift
6 * w--left shift
7 * ctrl--turn back
8 * Pins: PS2_DAT--X,W,Ctrl;
9 * KEY0--reset;
10 * LEDG3-0--data_out.
11 *
12 * yf.x
13 * 07-30-2011
14 *
15 */
16
17 module exp08_module
18 (
19 CLOCK_50, KEY,
20 PS2_CLK, PS2_DAT,
21 LEDG
22 );
23
24 input CLOCK_50;
25 input [0:0] KEY;
26 input PS2_CLK;
27 input PS2_DAT;
28 output [3:0] LEDG;
29
30 wire [7:0] ps2_data;
31 wire ps2_done;
32
33 ps2_module U1
34 (
35 .clk (CLOCK_50),
36 .rst_n (KEY),
37 .ps2_clk (PS2_CLK),
38 .ps2_data_in (PS2_DAT),
39 .ps2_data (ps2_data),
40 .ps2_done (ps2_done)
41 );
42
43 cmd_control_module U2
44 (
45 .clk (CLOCK_50),
46 .rst_n (KEY),
47 .ps2_done (ps2_done),
48 .ps2_data (ps2_data),
49 .data_out (LEDG)
50 );
51
52 endmodule
53
- 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.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
3. RTL chart
4. Summary
PS/2 decode , The most important thing is to use the general code , Edit the general code as a valid command or trigger event . Output is just a way , Whether you want to display characters or commands .
边栏推荐
- Notepad++ -- macro (record operation process)
- NLP - GIZA++ 实现词对齐
- Community interview -- jumpserver open source fortress in the eyes of an it newcomer
- Sword finger offer 41 Median in data stream
- CorelDRAW最新24.1.0.360版本更新介绍讲解
- Finally, Amazon~
- Freemaker template framework generates images
- Flume配置1——基础案例
- Nacos problem
- A great open source image watermarking solution
猜你喜欢

Flume configuration 3 - interceptor filtering
![[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design](/img/ad/0efd744334bf648b149aa1841b58af.png)
[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design

File contains vulnerability
![[network orientation training] - Enterprise Park Network Design - [had done]](/img/12/17f95378fcc6d0fef15feb99cc4f49.png)
[network orientation training] - Enterprise Park Network Design - [had done]

Flume配置3——拦截器过滤

npm ERR! fatal: early EOF npm ERR! fatal: index-pack failed

【U盘检测】为了转移压箱底的资料,买了个2T U盘检测仅仅只有47G~
![[USB flash disk test] in order to transfer the data at the bottom of the pressure box, I bought a 2T USB flash disk, and the test result is only 47g~](/img/c3/e0637385d35943f1914477bb9f2b54.png)
[USB flash disk test] in order to transfer the data at the bottom of the pressure box, I bought a 2T USB flash disk, and the test result is only 47g~

npm ERR! fatal: early EOF npm ERR! fatal: index-pack failed

Flume配置2——监控之Ganglia
随机推荐
Flume配置2——监控之Ganglia
剑指 Offer 59 - II. 队列的最大值
【摸鱼神器】UI库秒变低代码工具——表单篇(一)设计
Flume theory
【网络方向实训】-企业园区网络设计-【Had Done】
The list of winners in the classic Smurfs of childhood: bluedad's digital collection was announced
关于印发宝安区重点产业项目和总部项目遴选及用地保障实施细则(2022修订版)的通知
[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design
Notepad++ -- macro (record operation process)
Zotero journal automatic matching update influence factor
Lock4j -- distributed lock Middleware -- customize the logic of lock acquisition failure
1404萬!四川省人社廳關系型數據庫及中間件軟件系統昇級采購招標!
如何设置 Pod 到指定节点运行
剑指 Offer 66. 构建乘积数组
JVM(2) 垃圾回收
Real time tracking of bug handling progress of the project through metersphere and dataease
剑指 Offer 41. 数据流中的中位数
Luoqingqi: has high-end household appliances become a red sea? Casati took the lead in breaking the game
How to solve the problem of insufficient memory space in Apple iPhone upgrade system?
第二章(物理层)
![image [ note ] Re note -- Learn by doing Verilog HDL –008_d3](/img/1b/f359bebbd3b866dbfdee1d7abca66b.png)
![image [ note ] Re note -- Learn by doing Verilog HDL –008_sed_02](/img/67/0ca1f4fb51b8c41eabf3b61e859b8f.png)
![image [ note ] Re note -- Learn by doing Verilog HDL –008_d3_03](/img/7f/0ca73446247455ac4d8f9667083a87.png)
![image [ note ] Re note -- Learn by doing Verilog HDL –008_ data _04](/img/3c/26b7ad88f2359819e5515eb98311cb.png)
![image [ note ] Re note -- Learn by doing Verilog HDL –008_ data _05](/img/c8/2b28ab97d9187b6979d78a21eb7ce1.png)