• 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. 面试突击44:volatile 有什么用?

    volatile 是 Java 并发编程的重要组成部分,也是常见的面试题之一,它的主要作用有两个:保证内存的可见性和禁止指令重排序.下面我们具体来看这两个功能. 内存可见性 说到内存可见性问题就不得不 ...

  2. AliIAC 智能音频编解码器:在有限带宽条件下带来更高质量的音频通话体验

    随着信息技术的发展,人们对实时通信的需求不断增加,并逐渐成为工作生活中不可或缺的一部分.每年海量的音视频通话分钟数对互联网基础设施提出了巨大的挑战.尽管目前全球的互联网用户绝大多数均处于良好的网络状况 ...

  3. 739. Daily Temperatures - LeetCode

    Question 739. Daily Temperatures Solution 题目大意:比今天温度还要高还需要几天 思路:笨方法实现,每次遍历未来几天,比今天温度高,就坐标减 Java实现: p ...

  4. 105_Power Pivot财务科目(层级深度&筛选深度)

    博客:www.jiaopengzi.com 焦棚子的文章目录 请点击下载附件 1.背景 在财务科目中,需要按照科目层级来显示:在excel中都是用公式来实现,而且对于数据的管理及更新是一件头痛的事情, ...

  5. mysql查询关键字补充与多表查询

    目录 查询关键字补充 having过滤 distinct去重 order by排序 limit分页 regexp正则 多表查询 子查询 连表查询 查询关键字补充 having过滤 关键字having和 ...

  6. 【SSM框架】Spring笔记 --- 事务详解

    1.Spring的事务管理: 事务原本是数据库中的概念,在实际项目的开发中,进行事务的处理一般是在业务逻辑层, 即 Service 层.这样做是为了能够使用事务的特性来管理关联操作的业务. 在 Spr ...

  7. 微服务效率工具 goctl 深度解析(上)

    前言 本文根据 安前松 的视频分享整理而来,视频回放地址如下: https://www.bilibili.com/video/BV1Hr4y1x7Ne goctl 的由来 1. goctl 的诞生 g ...

  8. 儿童节,和 AI 一起通关 “超级马里奥兄弟”

    摘要:六一儿童节,快来训练一款自己的游戏 AI,用代码让马里奥从大反派酷霸王的魔掌里救回桃花公主. 本文分享自华为云社区<儿童节,和 AI 一起通关 "超级马里奥兄弟"> ...

  9. DAST 黑盒漏洞扫描器 第三篇:无害化

    0X01 前言 甲方扫描器其中一个很重要的功能重点,就是无害化,目的是尽量降低业务影响到可接受程度. 做过甲方扫描器,基本上对于反馈都有所熟悉. "我们的服务有大量报错,请问和你们有关么&q ...

  10. 关于VHDL中case语句多执行语句的书写方式(转载stackoverflow.com并做翻译汇总)

    很多国内的教材对于case语句的讲解非常单一,比如: 1 [标号:]CASE 多值表达式 IS 2 WHEN 选择值 => 被赋值变量 <=赋值变量: 3 WHEN 选择值 => 被 ...