• 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. CTF中常见密码学

    前言 参考,我们任课老师的WORD和PPT,结合自己的理解,在结合网上文章的理解. 一.BASE64编码 BASE64编码中,特征和所拥有的字符字母:A-Z a-z;数字:0-9;符号:+ / ,然后 ...

  2. 一些特殊的CSS属性

    1.<form>标签的enctype属性 enctype属性规定在发送到服务器之前应该如何对表单数据进行编码,属性值如下: application/x-www-form-urlencode ...

  3. salesforce零基础学习(一百一十三)Trigger中获取IP地址的过程

    本篇参考: https://developer.salesforce.com/docs/atlas.en-us.228.0.apexcode.meta/apexcode/apex_class_Auth ...

  4. 基于SqlSugar的开发框架的循序渐进介绍(1)--框架基础类的设计和使用

    在实际项目开发中,我们可能会碰到各种各样的项目环境,有些项目需要一个大而全的整体框架来支撑开发,有些中小项目这需要一些简单便捷的系统框架灵活开发.目前大型一点的框架,可以采用ABP或者ABP VNex ...

  5. 【深入理解计算机系统CSAPP】第六章 存储器层次结构

    6 存储器层次结构 存储器系统(memory system)是一个具有不同容量.成本和访问时间的存储设备的层次结构.CPU 寄存器保存着最常用的数据.靠近 CPU 的小的.快速的高速缓存存储器(cac ...

  6. 详解CVE-2022-0847 DirtyPipe漏洞

    摘要:本文详细介绍了CVE-2022-0847漏洞形成根因,相应补丁修复方法,通过本文让读者对CVE-2022-0847漏洞有更清晰的了解. 本文分享自华为云社区<CVE-2022-0847 D ...

  7. grpc-java源码环境编译

    1. Clone 1.1 git clone https://github.com/grpc/grpc-java.git 1.2 idea 打开grpc-java工程 2.compile 2.1 ja ...

  8. babel使用

    Babel转码器 Babel定义 Babel 是一个广泛使用的 ES6 转码器,可以将 ES6 代码转为 ES5 代码,从而在老版本的浏览器执行 Babel安装 仅需要在项目文件下安装 npm ins ...

  9. 关于我学git这档子事(3)

    对于如下报错: hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpa ...

  10. Django-Model随笔

    Django数据库之Model 常用命令 生成迁移文件 python manage.py makemigrations 实行数据库迁移 python manage.py migrate 数据库表结构反 ...