当前位置:网站首页>[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 .
边栏推荐
- JVM (4) bytecode technology + runtime optimization
- 一个超赞的开源的图片去水印解决方案
- 【编译原理】语义分析
- Sword finger offer 59 - I. maximum value of sliding window
- Linux安装MySQL5
- Sword finger offer 41 Median in data stream
- XSS漏洞
- Koa source code analysis
- Jmeter之BeanShell详解和夸线程调用
- Canonical engineers are trying to solve the performance problem of Firefox snap
猜你喜欢

La collection numérique Meng xiangshun, artiste national du tigre peint, est disponible en quantité limitée et est offerte avec Maotai de l'année du tigre

关于印发宝安区重点产业项目和总部项目遴选及用地保障实施细则(2022修订版)的通知

One hour to build a sample scenario sound network to release lingfalcon Internet of things cloud platform

如何设置 Pod 到指定节点运行

JVM(4) 字节码技术+运行期优化

【Try to Hack】vulnhub narak

Koa source code analysis

Foxit software was invited to appear at the 2022 advanced manufacturing digital intelligence development forum

Physical verification LVS process and Technology (Part I)

Flume configuration 3 - interceptor filtering
随机推荐
The era of data security solutions
Go: how to write a correct UDP server
Deficiencies and optimization schemes in Dao
一次 Keepalived 高可用的事故,让我重学了一遍它!
[sword finger offer] 51 Reverse pair in array
Flume配置3——拦截器过滤
WPS和Excele
攻防演练中的防守基石——全方位监控
Spark存储体系底层架构剖析-Spark商业环境实战
Sword finger offer 41 Median in data stream
La collection numérique Meng xiangshun, artiste national du tigre peint, est disponible en quantité limitée et est offerte avec Maotai de l'année du tigre
【剑指Offer】51. 数组中的逆序对
PowerShell command outputs only a list of directories
社区访谈丨一个IT新人眼中的JumpServer开源堡垒机
Flume配置2——监控之Ganglia
Introduction to the latest version 24.1.0.360 update of CorelDRAW
Performance improvement at the cost of other components is not good
SSH命令及使用说明
4-1 port scanning technology
Sword finger offer 59 - ii Maximum value of the queue
![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)