SOS信号:. . . _ _ _ . . .

1.

module sos_module
(
CLK, RSTn, Pin_Out, SOS_En_Sig
); input CLK;
input RSTn;
input SOS_En_Sig;
output Pin_Out; /****************************************/ parameter T1MS = 'd49_999;//DB4CE15开发板使用的晶振为50MHz,50M*0.001-1=49_999 /***************************************/ reg [:]Count1; always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
Count1 <= 'd0;
else if( isCount && Count1 == T1MS )
Count1 <= 'd0;
else if( isCount )
Count1 <= Count1 + 'b1;
else if( !isCount )
Count1 <= 'd0; /****************************************/ reg [:]Count_MS; always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
Count_MS <= 'd0;
else if( isCount && Count1 == T1MS )
Count_MS <= Count_MS + 'b1;
else if( !isCount )
Count_MS <= 'd0; /******************************************/ reg isCount;
reg rPin_Out;
reg [:]i; always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
begin
isCount <= 'b0;
rPin_Out <= 'b0;
i <= 'd0;
end
else
case( i ) 'd0 :
if( SOS_En_Sig ) i <= 'd1; 'd1, 5'd3, 'd5,
'd13, 5'd15, 'd17 :
if( Count_MS == 'd100 ) begin isCount <= 1'b0; rPin_Out <= 'b0; i <= i + 1'b1; end // short
else begin isCount <= 'b1; rPin_Out <= 1'b1; end 'd7, 5'd9, 'd11 :
if( Count_MS == 'd300 ) begin isCount <= 1'b0; rPin_Out <= 'b0; i <= i + 1'b1; end // long
else begin isCount <= 'b1; rPin_Out <= 1'b1; end 'd2, 5'd4, 'd6,
'd8, 5'd10, 'd12,
'd14, 5'd16, 'd18 :
if( Count_MS == 'd50 ) begin isCount <= 1'b0; i <= i + 'b1; end// interval
else isCount <= 'b1; 'd19 :
begin rPin_Out <= 'b0; i <= 5'd0; end // end endcase /***************************************************/ assign Pin_Out = rPin_Out; /***************************************************/ endmodule

2.

“Start_Sig”如同 C 语言中的调用指令,“Done_Sig”如同 C 语言的返回指令。这两个信号的存在就是为了控制模块的调用。

module sos_control_module
(
CLK, RSTn,
Start_Sig,
S_Done_Sig, O_Done_Sig,
S_Start_Sig, O_Start_Sig,
Done_Sig
); input CLK;
input RSTn;
input Start_Sig;
input S_Done_Sig, O_Done_Sig;
output S_Start_Sig, O_Start_Sig;
output Done_Sig; /*************************************/ reg [:]i;
reg isO;
reg isS;
reg isDone; always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
begin
i <= 'd0;
isO <= 'b0;
isS <= 'b0;
isDone <= 'b0;
end
else if( Start_Sig )
case( i ) 'd0:
if( S_Done_Sig ) begin isS <= 'b0; i <= i + 1'b1; end
else isS <= 'b1; 'd1:
if( O_Done_Sig ) begin isO <= 'b0; i <= i + 1'b1; end
else isO <= 'b1; 'd2:
if( S_Done_Sig ) begin isS <= 'b0; i <= i + 1'b1; end
else isS <= 'b1; 'd3:
begin isDone <= 'b1; i <= 4'd4; end 'd4:
begin isDone <= 'b0; i <= 4'd0; end endcase /*****************************************/ assign S_Start_Sig = isS;
assign O_Start_Sig = isO;
assign Done_Sig = isDone; /*****************************************/ endmodule
module s_module
(
CLK, RSTn,
Start_Sig,
Done_Sig,
Pin_Out
); input CLK;
input RSTn;
input Start_Sig;
output Done_Sig;
output Pin_Out; /****************************************/ parameter T1MS = 'd49_999; /***************************************/ reg [:]Count1; always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
Count1 <= 'd0;
else if( Count1 == T1MS )
Count1 <= 'd0;
else if( isCount )
Count1 <= Count1 + 'b1;
else if( !isCount )
Count1 <= 'd0; /****************************************/ reg [:]Count_MS; always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
Count_MS <= 'd0;
else if( Count_MS == rTimes )
Count_MS <= 'd0;
else if( Count1 == T1MS )
Count_MS <= Count_MS + 'b1; /******************************************/ reg [:]i;
reg rPin_Out;
reg [:]rTimes;
reg isCount;
reg isDone; always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
begin
i <= 'd0;
rPin_Out <= 'b0;
rTimes <= 'd1000;
isCount <= 'b0;
isDone <= 'b0;
end
else if( Start_Sig )
case( i ) 'd0, 4'd2, 'd4:
if( Count_MS == rTimes ) begin rPin_Out <= 'b0; isCount <= 1'b0; i <= i + 'b1; end
else begin isCount <= 'b1; rPin_Out <= 1'b1; rTimes <= 'd100; end 'd1, 4'd3, 'd5:
if( Count_MS == rTimes ) begin isCount <= 'b0; i <= i + 1'b1; end
else begin isCount <= 'b1; rTimes <= 10'd50; end 'd6:
begin isDone <= 'b1; i <= 4'd7; end 'd7:
begin isDone <= 'b0; i <= 4'd0; end endcase /******************************************/ assign Done_Sig = isDone;
assign Pin_Out = !rPin_Out; /******************************************/ endmodule
module o_module
(
CLK, RSTn,
Start_Sig,
Done_Sig,
Pin_Out
); input CLK;
input RSTn;
input Start_Sig;
output Done_Sig;
output Pin_Out; /****************************************/ parameter T1MS = 'd49_999; /***************************************/ reg [:]Count1; always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
Count1 <= 'd0;
else if( Count1 == T1MS )
Count1 <= 'd0;
else if( isCount )
Count1 <= Count1 + 'b1;
else if( !isCount )
Count1 <= 'd0; /****************************************/ reg [:]Count_MS; always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
Count_MS <= 'd0;
else if( Count_MS == rTimes )
Count_MS <= 'd0;
else if( Count1 == T1MS )
Count_MS <= Count_MS + 'b1; /******************************************/ reg [:]i;
reg rPin_Out;
reg [:]rTimes;
reg isCount;
reg isDone; always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
begin
i <= 'd0;
rPin_Out <= 'b0;
rTimes <= 'd1000;
isCount <= 'b0;
isDone <= 'b0;
end
else if( Start_Sig )
case( i ) 'd0, 4'd2, 'd4:
if( Count_MS == rTimes ) begin rPin_Out <= 'b0; isCount <= 1'b0; i <= i + 'b1; end
else begin isCount <= 'b1; rPin_Out <= 1'b1; rTimes <= 'd400; end 'd1, 4'd3, 'd5:
if( Count_MS == rTimes ) begin isCount <= 'b0; i <= i + 1'b1; end
else begin isCount <= 'b1; rTimes <= 10'd50; end 'd6:
begin isDone <= 'b1; i <= 4'd7; end 'd7:
begin isDone <= 'b0; i <= 4'd0; end endcase /******************************************/ assign Done_Sig = isDone;
assign Pin_Out = !rPin_Out; /******************************************/ endmodule
module sos_module
(
CLK, RSTn,
Start_Sig,
Done_Sig,
Pin_Out
); input CLK;
input RSTn;
input Start_Sig;
output Done_Sig;
output Pin_Out; /*****************************/ wire S_Done_Sig;
wire S_Pin_Out; s_module U1
(
.CLK( CLK ),
.RSTn( RSTn ),
.Start_Sig( S_Start_Sig ), // input - from U3
.Done_Sig( S_Done_Sig ), // output - to U3
.Pin_Out( S_Pin_Out ) // output - to selector ) ; /*********************************/ wire O_Done_Sig;
wire O_Pin_Out; o_module U2
(
.CLK( CLK ),
.RSTn( RSTn ),
.Start_Sig( O_Start_Sig ), // input - from U3
.Done_Sig( O_Done_Sig ), // output - to U3
.Pin_Out( O_Pin_Out ) // output - to selector
); /*********************************/ wire S_Start_Sig;
wire O_Start_Sig; sos_control_module U3
(
.CLK( CLK ),
.RSTn( RSTn ),
.Start_Sig( Start_Sig ), // input - from top
.S_Done_Sig( S_Done_Sig ), // input - from U1
.O_Done_Sig( O_Done_Sig ), // input - from U2
.S_Start_Sig( S_Start_Sig ), // output - to U1
.O_Start_Sig( O_Start_Sig ), // output - to U2
.Done_Sig( Done_Sig ) // output - to top
); /*********************************/ //selector reg Pin_Out; always @ ( * )
if( S_Start_Sig ) Pin_Out = S_Pin_Out; // select from U1
else if( O_Start_Sig ) Pin_Out = O_Pin_Out; // select from U2
else Pin_Out = 'bx; /*********************************/ endmodule

Verilog之SOS信号-仿顺序操作的更多相关文章

  1. 【黑金教程笔记之006】【建模篇】【Lab 05 SOS信号之一】—笔记

    sos_module.v是产生SOS信号的功能模块.即有次序的输出莫斯码:点.画.间隔.control_module.v是一个定时触发器,每一段时间使能sos_module.v. 模块: /***** ...

  2. 【黑金教程笔记之007】【建模篇】【Lab 06 SOS信号之二】—笔记

    控制模块的协调角色. 实验六用到了实验四的按键消抖模块debounce_module.v和实验五的sos_module.v. 设计思路: debounce_module.v看成一个输入,sos_mod ...

  3. 【黑金教程笔记之001】veriloghdl 扫盲文—笔记&勘误

    001_veriloghdl 扫盲文—笔记&勘误 2014/10/31 原文作者:akuei2 联系方式:blog.ednchina.con/akuei2 勘误001: Page 3 0.1 ...

  4. 【设计经验】1、Verilog中如何规范的处理inout信号

    在FPGA的设计过程中,有时候会遇到双向信号(既能作为输出,也能作为输入的信号叫双向信号).比如,IIC总线中的SDA信号就是一个双向信号,QSPI Flash的四线操作的时候四根信号线均为双向信号. ...

  5. verilog实现中值滤波

    前言 项目需要,想要实现算法中的其中一步即中值滤波,同时,因为图像处理部分中值滤波相对来说还是比较简单的,将中值滤波的硬件实现作为进入FPGA领域的第一次尝试.虽然说网上有较多关于中值滤波的文档,可是 ...

  6. 基于Proteus仿真的Arduino学习(1)——Arduino Uno最小系统及LED的简单使用

    一.前言:  A.Arduino简介 Arduino是由一个欧洲开发团队于2005年冬季开发.其成员包括Massimo Banzi.David Cuartielles.Tom Igoe.Gianluc ...

  7. SPI通信实验---verilog(FPGA作为从机,使用可读可写)

    本实验讲究实用性,故设计思想为:主机先向从机发送地址,若是向从机写入数据,则向从机发送数据,若是读取从机数据,则向从机发送时钟,然后在时钟下降沿读取数据即可.cs信号上升沿作为SPI通信的结束信号.r ...

  8. SPI的通信试验 --verilog (从机-全双工)

    SPI的 有关知识参考FPGA作为主机的通信实验. 本实验中FPGA作为从机通过SPI与MCU等通信的试验,可以在时钟上升沿接收数据并且在时钟下降沿发送数据,模仿全双工模式.接收的 数据作为地址,通过 ...

  9. 【接口时序】2、Verilog实现流水灯及与C语言的对比

    一. 软件平台与硬件平台 软件平台: 1.操作系统:Windows-8.1 2.开发套件:ISE14.7 3.仿真工具:ModelSim-10.4-SE 硬件平台: 1.FPGA型号:XC6SLX45 ...

随机推荐

  1. ssh 协议执行repo sync 报错:Permission denied (publickey)

    1.ssh key 已经添加ssh key到gerrit服务器,并且执行ssh协议的git clone可以正常克隆代码到本地,可见不是ssh key的问题. 2.manifest清单文件配置 最初在m ...

  2. Javascript 基础知识学习--javascript中的参数传递都是按值传递的

    ECMAScript中所有函数的参数传递都是按值传递的,无论参数是值类型还是引用类型的.过去我跟大多数人一样觉得跟传值类型相关. 自己写了一个测试的例子,确实如此 function add(a) { ...

  3. Raising Modulo Numbers

    Description People are different. Some secretly read magazines full of interesting girls' pictures, ...

  4. vs无法调试的时候

    ①选中所有程序可能经过的地方设置断点 ②清空.net frameword对应的缓存,路径"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temp ...

  5. Jmeter组件2. Timer 定时器

    关于定时器,首先明确几个概念 定时器在每个Sampler执行之前执行 定时器有作用域,同一个作用域内的定时器会在域内Sampler执行之前都执行掉 如果要让某定时器只作用于一个Sampler,将定时器 ...

  6. devexpress中如何给TabPage控件的Tab定义背景色

    js: /*tab选项卡样式*/ .color .dxtc-link { background-color: #bf4e6a !important; } 后台代码: //选项卡样式 protected ...

  7. mysql中中文乱码问题

    作用:约束用来保证数据有效性和完整性 . 定义主键约束 主键约束 primary key : 信息记录某个字段可以唯一区分其他信息记录,这个字段就可以是主键 (唯一 非空)   primary key ...

  8. 关于xib文件和storyboard文件的那些事儿

    在ios中,一般建议使用代码布局,因为使用代码布局,后期维护容易,拓展容易,并且可以实现动态加载很多数据,但是代码布局比较繁琐,不适合初学者.Xib布局或者Storyboard布局比较方便.下面介绍一 ...

  9. ASP.NET 操作Cookie详解 增加,修改,删除

    ASP.NET 操作Cookie详解 增加,修改,删除 Cookie,有时也用其复数形式Cookies,指某些网站为了辨别用户身份而储存在用户本地终端上的数据(通常经过加密).定义于RFC2109.它 ...

  10. 127.0.0.1和localhost完全相等吗?

    今天在使用ajax发请求的时候遇到如下问题: 以[Access-Control-Allow-Origin]为关键字搜索的结果进行改进,但没有效果. 返回仔细查看错误提示,发现ajax请求的url是lo ...