• 1.一个led亮100ns,灭400ns,循环
  • 2.一个led亮2500ns,灭5000ns,亮7500ns,灭10000ns循环
  • 3.以2500ns为变化周期,20000ns为一个循环,每个周期的亮灭模式由用户设置。
  • 4.以tim*20/8 ns为变化周期,tim*20 ns为一个循环,每个周期的亮灭模式,tim由用户设置。
  • 5.1最小周期相同(由用户指定),由多个ctrl控制多个led在其周期内循环亮灭
  • 5.2最小周期相同(由用户指定),由多个ctrl控制多个led在其周期内循环亮灭,用例化模块的方法
  • 6.每隔Tim秒,led的一个8状态周期tim循环一次,Tim>tim,两个参数都由用户设置。
module led_change1(      //1.一个led亮100ns,灭400ns,循环
clk,
reset,
led
);
input clk;
input reset;
output reg led = 1'd1;
reg [4:0]counter0; always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
counter0 <= 5'b0 ;
else if (counter0 == 24 )
counter0 <= 0 ;
else
counter0 <= counter0 + 1'd1;
end always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
led <= 0 ;
else if (counter0 == 4 )
led <= ! led ;
else if (counter0 == 24 )
led <= ! led ;
else
led <= led;//记得
end endmodule
module led_change2(      //2.一个led亮2500ns,灭5000ns,亮7500ns,灭10000ns循环
clk,
reset,
led
);
input clk;
input reset;
output reg led = 1'd1;
reg [11:0]counter0; parameter mcnt = 1250 ; always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
counter0 <= 5'b0 ;
else if (counter0 == mcnt - 1 )
counter0 <= 0 ;
else
counter0 <= counter0 + 1'd1;
end // always@( posedge clk or negedge reset )
// begin
// if ( reset == 0 )
// led <= 0 ;
// else if (counter0 == mcnt * 1 / 10 - 1 )
// led <= ! led ;
// else if (counter0 == mcnt * 3 / 10 - 1 )
// led <= ! led ;
// else if (counter0 == mcnt * 6 / 10 - 1 )
// led <= ! led ;
// else if (counter0 == mcnt * 10 / 10 - 1 )
// led <= ! led ;
// else
// led <= led;//记得
// end always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
led <= 0 ;
else case( counter0 )
mcnt * 1 / 10 - 1 : led <= ! led ;
mcnt * 3 / 10 - 1 : led <= ! led ;
mcnt * 6 / 10 - 1 : led <= ! led ;
mcnt * 10 / 10 - 1 : led <= ! led ;
endcase
end
endmodule
module led_change3(      //3.以2500ns为变化周期,20000ns为一个循环,每个周期的亮灭模式由用户设置。
clk,
reset,
ctrl,
led
);
input clk;
input reset;
input [7:0]ctrl;
output reg led ; reg [9:0]counter0; parameter mcnt = 1000 ; always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
counter0 <= 11'b0 ;
else if (counter0 == mcnt - 1 )
counter0 <= 0 ;
else
counter0 <= counter0 + 1'd1;
end always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
led <= 0 ;
else case( counter0 )
mcnt * 1 / 8 - 1 : led <= ctrl[0] ;
mcnt * 2 / 8 - 1 : led <= ctrl[1] ;
mcnt * 3 / 8 - 1 : led <= ctrl[2] ;
mcnt * 4 / 8 - 1 : led <= ctrl[3] ;
mcnt * 5 / 8 - 1 : led <= ctrl[4] ;
mcnt * 6 / 8 - 1 : led <= ctrl[5] ;
mcnt * 7 / 8 - 1 : led <= ctrl[6] ;
mcnt * 8 / 8 - 1 : led <= ctrl[7] ;
default led <= led ;
endcase
end
endmodule
module led_change4(      //4.以tim*20/8 ns为变化周期,tim*20 ns为一个循环,每个周期的亮灭模式,tim由用户设置。.
clk,
reset,
ctrl,
tim,
led
);
input clk;
input reset;
input [7:0]ctrl;
input [9:0]tim;
output reg led ; reg [9:0]counter0; always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
counter0 <= 11'b0 ;
else if (counter0 == tim - 1 )
counter0 <= 0 ;
else
counter0 <= counter0 + 1'd1;
end always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
led <= 0 ;
else case( counter0 ) //可以用第二个计数器的方法来设置判断条件
tim * 1 / 8 - 1 : led <= ctrl[0] ;
tim * 2 / 8 - 1 : led <= ctrl[1] ;
tim * 3 / 8 - 1 : led <= ctrl[2] ;
tim * 4 / 8 - 1 : led <= ctrl[3] ;
tim * 5 / 8 - 1 : led <= ctrl[4] ;
tim * 6 / 8 - 1 : led <= ctrl[5] ;
tim * 7 / 8 - 1 : led <= ctrl[6] ;
tim * 8 / 8 - 1 : led <= ctrl[7] ;
default led <= led ;
endcase
end
endmodule
module led_change4(      //5.1以tim*20/8 ns为变化周期,tim*20 ns为一个循环,每个周期的亮灭模式,tim由用户设置。.
clk,
reset,
ctrl,
tim,
led
);
input clk;
input reset;
input [7:0]ctrl;
input [9:0]tim;
output reg led ; reg [9:0]counter0; always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
counter0 <= 11'b0 ;
else if (counter0 == tim - 1 )
counter0 <= 0 ;
else
counter0 <= counter0 + 1'd1;
end always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
led <= 0 ;
else case( counter0 ) //可以用第二个计数器的方法来设置判断条件
tim * 1 / 8 - 1 : led <= ctrl[0] ;
tim * 2 / 8 - 1 : led <= ctrl[1] ;
tim * 3 / 8 - 1 : led <= ctrl[2] ;
tim * 4 / 8 - 1 : led <= ctrl[3] ;
tim * 5 / 8 - 1 : led <= ctrl[4] ;
tim * 6 / 8 - 1 : led <= ctrl[5] ;
tim * 7 / 8 - 1 : led <= ctrl[6] ;
tim * 8 / 8 - 1 : led <= ctrl[7] ;
default led <= led ;
endcase
end
endmodule
module led_change5_M(      //5.2最小周期相同(由用户指定),由多个ctrl控制多个led在其周期内循环亮灭,用例化模块的方法
clk,
reset,
ctrlA,
ctrlB,
tim,
led
);
input clk;
input reset;
input [7:0]ctrlA,ctrlB;
input [9:0]tim;
output wire [1:0]led ; led_change4 led_change4_sim0( //以tim*20/8 ns为变化周期,tim*20 ns为一个循环,每个周期的亮灭模式,tim由用户设置。
.clk(clk),
.reset(reset),
.ctrl(ctrlA),
.tim(tim),
.led(led[0])
); led_change4 led_change4_sim1( //以tim*20/8 ns为变化周期,tim*20 ns为一个循环,每个周期的亮灭模式,tim由用户设置。
.clk(clk),
.reset(reset),
.ctrl(ctrlB),
.tim(tim),
.led(led[1])
); endmodule
module led_change6(      //6.每隔Tim秒,led的一个8状态周期tim循环一次,Tim>tim,两个参数都由用户设置。
clk,
reset,
ctrl,
tim,
Tim,
led
);
input clk;
input reset;
input [7:0]ctrl;
input [9:0]tim;
input [10:0]Tim;
output reg led ; reg [10:0] counter0; always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
counter0 <= 9'b0 ;
else if (counter0 == Tim -1 )
counter0 <= 0 ;
else
counter0 <= counter0 + 1'd1;
end always@( posedge clk or negedge reset )
begin
if ( reset == 0 )
led <= 0 ;
else case( counter0 ) //可以用第二个计数器的方法来设置判断条件
tim * 1 / 8 - 1 : led <= ctrl[0] ;
tim * 2 / 8 - 1 : led <= ctrl[1] ;
tim * 3 / 8 - 1 : led <= ctrl[2] ;
tim * 4 / 8 - 1 : led <= ctrl[3] ;
tim * 5 / 8 - 1 : led <= ctrl[4] ;
tim * 6 / 8 - 1 : led <= ctrl[5] ;
tim * 7 / 8 - 1 : led <= ctrl[6] ;
tim * 8 / 8 - 1 : led <= ctrl[7] ;
tim * 9 / 8 - 1 : led <= 0 ;
default led <= led ;
endcase
end
endmodule

注意:

1.需要用户指定的便需要设置输入端口,这是一个变量。

2.用if语句时可以用else 罗列其他没有写出的情况。而用case语句时应该用default xxxxx。语句实现,见上面3和4。同时,可以用if先列出复位信号的情况,再用else case罗列时钟信号的情况。

3.工程包含多个文件时,用set as top来激活指定要操作的文件。

4.乘除可以使用左右移位来实现,节省乘法器。

5.用顶层中例化模块的方法十分便捷有效,只需要把顶层的引脚分别分配给多个例化模块就可以了。要学会这么用,很快很好用。

6.多位宽既可以用来表示多个输出端口,也可以用来表示一个端口的不同时期的多个状态。

7.参数赋值时,要明确指定进制,不然会默认是十进制,有时候不注意就会出错。养成良好习惯。

8.错误:counter设定位宽太小,导致计数不到第二个else if就已经溢出,成为0,波形一直在重复前面的结果,后面的结果没有出现,难以看出错误。所以遇到我们设置的有些预期结果没有出现的情况,要检查一下计时器的位宽设置有没有出错。因为溢出不报错,但影响结果。

9.记住:仿真设置的例化module参数的位宽必须与原来module的参数位宽保持一致,不然虽然没有报错,但是输出会出错。

10.再次记忆:顶层设计时的输出端写为wire,底层是reg。顶层写reg会报错。

led的进化的更多相关文章

  1. Atitit 软件架构方法的进化与演进cs bs soa roa  msa  attilax总结

    Atitit 软件架构方法的进化与演进cs bs soa roa  msa  attilax总结 1.1. 软件体系架构是沿着单机到 CS 架构,再到 BS 的三层架构甚至多层架构逐步发展过来的,关于 ...

  2. Atitit 编程语言编程方法的进化演进 sp  COP ,AOP ,SOP

    Atitit 编程语言编程方法的进化演进 sp  COP ,AOP ,SOP 1.1.  Sp  oop>>COP ,AOP ,SOP1 1.2. Sp  oop 结构化方法SP(Stru ...

  3. js生成一个不重复的ID的函数的进化之路

    在MongoDB中的ObjectID,可以理解为是一个不会重复的ID,这里有个链接http://blog.csdn.net/xiamizy/article/details/41521025感兴趣可以去 ...

  4. linux输入子系统(input subsystem)之按键输入和LED控制

    实验现象:在控制台打印按键值,并且通过按键控制相应的LED亮灭. 1.代码 input_subsys_drv.c #include <linux/module.h> #include &l ...

  5. FPGA与simulink联合实时环路系列——实验二LED

    实验二LED 实验内容 在实验一的基础上,将simulink产生的测试信号输出到FPGA开发板上的LED灯进行显示,这里要在生成的硬件模型上进行修改,将传送到FPGA的信号输出到8个LED灯上,并且对 ...

  6. 差分进化算法 DE-Differential Evolution

    差分进化算法 (Differential Evolution)   Differential Evolution(DE)是由Storn等人于1995年提出的,和其它演化算法一样,DE是一种模拟生物进化 ...

  7. [Evolutionary Algorithm] 进化算法简介

    进化算法,也被成为是演化算法(evolutionary algorithms,简称EAs),它不是一个具体的算法,而是一个“算法簇”.进化算法的产生的灵感借鉴了大自然中生物的进化操作,它一般包括基因编 ...

  8. 嵌入式Linux学习入门:控制LED灯

    记录自己linux学习过程,让自己能够一直坚持下去 1.原理图分析: nLED_1, nLED_2, nLED_4, 给低电平则对应LED灯亮,高电平则对应LED灯灭, S3C2440芯片GPF4-G ...

  9. 单片机与控制实验(2)——LED点阵显示屏

    一.实验目的和要求 了解LED点阵显示的基本原理和实现方法.掌握点阵汉字库的编码和从标准字库中提取汉字编码的方法. 二.实验设备 单片机测控实验系统 LED点阵显示器实验模块 Keil开发环境 STC ...

随机推荐

  1. 为什么 Nginx 比 Apache 更厉害?

    关注「开源Linux」,选择"设为星标" 回复「学习」,有我为您特别筛选的学习资料~ 为什么Nginx在处理高并发方面要优于httpd,我们先从两种web服务器的工作原理以及工作模 ...

  2. MAUI候选版本3发布啦

    我们很高兴发布.NET 多平台应用程序UI (.NET MAUI) 候选版本3,这个版本包含一系列新的改进.与以前的候选版本一样,RC3 包含在"上线"支持政策中,这意味着Micr ...

  3. 使用 VS Code + Markdown 编写 PDF 文档

    背景介绍 作为一个技术人员,基本都需要编写技术相关文档,而且大部分技术人员都应该掌握 markdown 这个技能,使用 markdown 来编写并生成 PDF 文档将会是一个不错的体验,以下就介绍下如 ...

  4. 每日一题20180330-Linux

    一.问题 1.1 统计/var/log/下所有文件个数 1.2 查找出/var/log目录下面修改时间是7天以前,大小在50k到2M之间,并以.log结尾的文件把这些文件复制到/data目录中 1.3 ...

  5. K8S 部署Dashboard UI

    Kubernetes Dashboard是Kubernetes集群的通用.基于Web的UI.它允许用户管理集群中运行的应用程序并对其进行故障排除,以及管理集群本身. 访问到DashBoard有两种方式 ...

  6. HDFS 细粒度锁优化,FusionInsight MRS有妙招

    摘要:华为云FusionInsight MRS通过FGL对HDFS NameNode锁机制进行优化,有效提升了NameNode的读写吞吐量,从而能够支持更多数据,更多业务请求访问,从而更好的支撑政企客 ...

  7. Probabilistic two-stage detection

  8. 深度学习与CV教程(10) | 轻量化CNN架构 (SqueezeNet,ShuffleNet,MobileNet等)

    作者:韩信子@ShowMeAI 教程地址:http://www.showmeai.tech/tutorials/37 本文地址:http://www.showmeai.tech/article-det ...

  9. 【Azure 应用服务】NodeJS Express + MSAL 应用实现AAD登录并获取AccessToken -- cca.acquireTokenByCode(tokenRequest)

    问题描述 在上一篇博文 "[Azure 应用服务]NodeJS Express + MSAL 应用实现AAD集成登录并部署在App Service Linux环境中的实现步骤"中, ...

  10. QQ空间未授权评论_已忽略

    看群友们聊天时发现的, 大概是做了查看了动态访问时间的一个设置, 但是仅自己可见的说说还是被评论了的这么一个问题. 闲的没事就翻了一下找一下问题. 这个方法嘎嘎鸡肋, 可以说完全没用, 交到tsrc, ...