led的进化
- 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的进化的更多相关文章
- Atitit 软件架构方法的进化与演进cs bs soa roa msa attilax总结
Atitit 软件架构方法的进化与演进cs bs soa roa msa attilax总结 1.1. 软件体系架构是沿着单机到 CS 架构,再到 BS 的三层架构甚至多层架构逐步发展过来的,关于 ...
- Atitit 编程语言编程方法的进化演进 sp COP ,AOP ,SOP
Atitit 编程语言编程方法的进化演进 sp COP ,AOP ,SOP 1.1. Sp oop>>COP ,AOP ,SOP1 1.2. Sp oop 结构化方法SP(Stru ...
- js生成一个不重复的ID的函数的进化之路
在MongoDB中的ObjectID,可以理解为是一个不会重复的ID,这里有个链接http://blog.csdn.net/xiamizy/article/details/41521025感兴趣可以去 ...
- linux输入子系统(input subsystem)之按键输入和LED控制
实验现象:在控制台打印按键值,并且通过按键控制相应的LED亮灭. 1.代码 input_subsys_drv.c #include <linux/module.h> #include &l ...
- FPGA与simulink联合实时环路系列——实验二LED
实验二LED 实验内容 在实验一的基础上,将simulink产生的测试信号输出到FPGA开发板上的LED灯进行显示,这里要在生成的硬件模型上进行修改,将传送到FPGA的信号输出到8个LED灯上,并且对 ...
- 差分进化算法 DE-Differential Evolution
差分进化算法 (Differential Evolution) Differential Evolution(DE)是由Storn等人于1995年提出的,和其它演化算法一样,DE是一种模拟生物进化 ...
- [Evolutionary Algorithm] 进化算法简介
进化算法,也被成为是演化算法(evolutionary algorithms,简称EAs),它不是一个具体的算法,而是一个“算法簇”.进化算法的产生的灵感借鉴了大自然中生物的进化操作,它一般包括基因编 ...
- 嵌入式Linux学习入门:控制LED灯
记录自己linux学习过程,让自己能够一直坚持下去 1.原理图分析: nLED_1, nLED_2, nLED_4, 给低电平则对应LED灯亮,高电平则对应LED灯灭, S3C2440芯片GPF4-G ...
- 单片机与控制实验(2)——LED点阵显示屏
一.实验目的和要求 了解LED点阵显示的基本原理和实现方法.掌握点阵汉字库的编码和从标准字库中提取汉字编码的方法. 二.实验设备 单片机测控实验系统 LED点阵显示器实验模块 Keil开发环境 STC ...
随机推荐
- Keepalived入门学习
一个执着于技术的公众号 Keepalived简介 Keepalived 是使用C语言编写的路由热备软件,该项目软件起初是专门为LVS负载均衡设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后 ...
- c++:-3
上一节学习了C++的函数:c++:-2,本节学习C++的数组.指针和字符串 数组 定义和初始化 定义 例如:int a[10]; 表示a为整型数组,有10个元素:a[0]...a[9] 例如: int ...
- 使用CSS实现《声生不息》节目Logo
声明:本文涉及图文和模型素材仅用于个人学习.研究和欣赏,请勿二次修改.非法传播.转载.出版.商用.及进行其他获利行为. 背景 <声生不息> 是芒果TV.香港电视广播有限公司和湖南卫视联合推 ...
- Android 解析包时出现问题 的解决方案(应用检查更新)
问题描述我们在进行Android开发的时候,一般都会在应用里检测有没有更新,并且从网上下载最新的版本包,覆盖本地的旧版本.在我的项目中,出现了一个问题,就是当安装包下载到本地的时候,产生了" ...
- SQL多表多字段比对方法
目录 表-表比较 整体思路 找出不同字段的明细 T1/T2两表ID相同的部分,是否存在不同NAME 两表的交集与差集:判断两表某些字段是否相同 两表的交集与差集:找出T2表独有的id 字段-字段比较 ...
- 记一次IIS网站启动不了的问题排查
今天清理了下机器中的IIS网站,将很久不用的网站都删除. 因为需要删除的比较多,正在使用的很少,就将网站全部删除了,然后准备重新添加需要用的. 在添加了网站后,点击启动按钮,发现网站启动不了,因为网站 ...
- Canal-监听数据库表的变化
1. 简介 Canal是阿里巴巴旗下的一款开源项目,纯Java开发.基于数据库增量日志解析,提供增量数据订阅&消费功能. 工作原理 Mysql主备复制原理 MySQL master 将数据变更 ...
- SAP 实例 4 CFW
*&---------------------------------------------------------------------* *& Report demo_cfw ...
- Vue 安装 vue的基本使用 vue的初步使用步骤
1. 资源: https://cn.vuejs.org/v2/guide/#%E8%B5%B7%E6%AD%A5 进入官网学习 2. 点击安装,要把vue下载到本地文件的根目录中,不要选择压缩版的,这 ...
- QT工程构建目录下,将生成的中间文件和可执行文件分离
在QT工程中,当我们选择了构建目录后,编译生成程序后,总会发现在debug目录下会有混淆着各类文件,如下图 很多时候,我们又仅仅只需要可执行文件或者自定义的动态链接库.如下图 当然,如果不觉得麻烦,有 ...