探索flutter框架开发的app在移动应用市场的潜力与挑战
1054
2022-11-22
[笔记]再笔记--边干边学Verilog HDL --001
缘起
偶然,借到块DE2,开始学习Verilog HDL,也是从语法看起,照着书上敲代码,仿真,做lab,-,貌似入门了,但总是不确定,总是觉得不能把握什么。偶然看到akuei2的《Verilog哪些事儿--建模篇》V4,觉得很好,遂想记录“打谱”的点滴--是为再笔记
Lab 1 永远的流水灯
这名字是直接拿来的,起的太好了,不多言。
这个实验想阐述并行的思想,用4个类似的模块建立1个并行操作的流水灯模块。每隔100ms流动一下。
代码:
led0_module.v
1 /** 2 * File name: led0_mocule.v 3 * 4 */ 5 6 module led0_module 7 ( 8 clk, rst_n, led_out 9 );10 11 input clk;12 input rst_n;13 output led_out;14 15 parameter T10MS = 25'd20_000_000;16 17 reg [24:0] count;18 19 always @(posedge clk or negedge rst_n)20 if (!rst_n)21 count <= 25'd0;22 else if (count == T10MS)23 count <= 25'd0;24 else25 count <= count + 1'b1;26 27 reg rled_out;28 29 always @(posedge clk or negedge rst_n)30 if (!rst_n)31 rled_out <= 1'b0;32 else if (count >= 25'd0 && count < 25'd5_000_000)33 rled_out <= 1'b1;34 else35 rled_out <= 1'b0;36 37 assign led_out = rled_out;38 39 endmodule 40
led1_module.v
1 /** 2 * File name: led1_mocule.v 3 * 4 */ 5 6 module led1_module 7 ( 8 clk, rst_n, led_out 9 );10 11 input clk;12 input rst_n;13 output led_out;14 15 parameter T10MS = 25'd20_000_000;16 17 reg [24:0] count;18 19 always @(posedge clk or negedge rst_n)20 if (!rst_n)21 count <= 25'd0;22 else if (count == T10MS)23 count <= 25'd0;24 else25 count <= count + 1'b1;26 27 reg rled_out;28 29 always @(posedge clk or negedge rst_n)30 if (!rst_n)31 rled_out <= 1'b0;32 else if (count >= 25'd5_000_000 && count < 25'd10_000_000)33 rled_out <= 1'b1;34 else35 rled_out <= 1'b0;36 37 assign led_out = rled_out;38 39 endmodule 40
led2_module.v
1 /** 2 * File name: led2_mocule.v 3 * 4 */ 5 6 module led2_module 7 ( 8 clk, rst_n, led_out 9 );10 11 input clk;12 input rst_n;13 output led_out;14 15 parameter T10MS = 25'd20_000_000;16 17 reg [24:0] count;18 19 always @(posedge clk or negedge rst_n)20 if (!rst_n)21 count <= 25'd0;22 else if (count == T10MS)23 count <= 25'd0;24 else25 count <= count + 1'b1;26 27 reg rled_out;28 29 always @(posedge clk or negedge rst_n)30 if (!rst_n)31 rled_out <= 1'b0;32 else if (count >= 25'd10_000_000 && count < 25'd15_000_000)33 rled_out <= 1'b1;34 else35 rled_out <= 1'b0;36 37 assign led_out = rled_out;38 39 endmodule 40
led3_module.v
1 /** 2 * File name: led3_mocule.v 3 * 4 */ 5 6 module led3_module 7 ( 8 clk, rst_n, led_out 9 );10 11 input clk;12 input rst_n;13 output led_out;14 15 parameter T10MS = 25'd20_000_000;16 17 reg [24:0] count;18 19 always @(posedge clk or negedge rst_n)20 if (!rst_n)21 count <= 25'd0;22 else if (count == T10MS)23 count <= 25'd0;24 else25 count <= count + 1'b1;26 27 reg rled_out;28 29 always @(posedge clk or negedge rst_n)30 if (!rst_n)31 rled_out <= 1'b0;32 else if (count >= 25'd15_000_000 && count < 25'd20_000_000)33 rled_out <= 1'b1;34 else35 rled_out <= 1'b0;36 37 assign led_out = rled_out;38 39 endmodule 40
top_module.v
1 /** 2 * File name: top_module.v 3 * Function: moving lamp, time interval = 0.1s. 4 * Pins: KEY0-rst_n, LEDG3-0 5 * Target board: DE2. 6 * Software: Quartus II 9.1 sp1 7 * ---------------------------- 8 * yf.x 9 * 7-11-201110 * 11 */12 13 module top_module14 (15 CLOCK_50, KEY, LEDG16 );17 18 input CLOCK_50;19 input [0:0] KEY;20 output [3:0] LEDG;21 22 wire led0_out;23 24 led0_module U025 (26 .clk (CLOCK_50),27 .rst_n (KEY[0]),28 .led_out (led0_out)29 );30 31 wire led1_out;32 33 led1_module U134 (35 .clk (CLOCK_50),36 .rst_n (KEY[0]),37 .led_out (led1_out)38 );39 40 wire led2_out;41 42 led2_module U243 (44 .clk (CLOCK_50),45 .rst_n (KEY[0]),46 .led_out (led2_out)47 );48 49 wire led3_out;50 51 led3_module U352 (53 .clk (CLOCK_50),54 .rst_n (KEY[0]),55 .led_out (led3_out)56 );57 58 assign LEDG[3:0] = {led3_out, led2_out, led1_out, led0_out};59 60 endmodule
RTL图
小结
并行思维.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~