集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 2091|回复: 3

请教一个 检测低电平的程序

[复制链接]
johnson925 发表于 2011-10-14 23:46:15 | 显示全部楼层 |阅读模式
现在的这个程序每检测到一个低电平就会给出一个触发信号
希望能只在检测到第一个低电平时给出触发信号
求大侠指导一下
sig_in:输入信号
h2l:低电平触发信号


module detect_module (clk, sig_in, rst, h2l);
                       
input clk;
input sig_in;
input rst;
output h2l;

reg detect1;
reg detect2;

always @ ( posedge clk )
        if ( rst )
                begin
                        detect1 <= 1'b1;
                        detect2 <= 1'b1;
                end
        else
                begin
                        detect1 <= detect2;
                        detect2 <= sig_in;
                        #1 detect2 <= sig_in | detect2;
                end
assign h2l = detect1 & !detect2;
至芯兴洪 发表于 2011-10-19 09:52:24 | 显示全部楼层
可综合模块是不能有这种符号“#”,这是不可综合的,你的代码写法是错误的,得好好看看书,多练练
提点建议:
1,功能模块中不可出现不可综合语句;
2,module 对应有个end module才对;
3,一般来说复位信号应该是低电平异步复位;
4,always语句下面记得加上begin--end;
5,端口输出尽量定义成reg型,寄存器输出,信号稳定,如果是组合逻辑输出可能会造成不稳定,在时序方面延迟会大一些;
下面是我根据你的代码改的,你看看吧
module detect_module (clk,
                      sig_in,
                      rst,
                      h2l
                      );                     
input         clk;
input         sig_in;
input                rst;
output  h2l;

reg detect1;
reg detect2;
reg h21;

always @ ( posedge clk or negedge rst)
        begin
        if (! rst )
                begin
                        detect1 <= 1'b1;
                        detect2 <= 1'b1;
                end
        else
                begin
                        detect1 <= sig_in;
                        detect2 <= detect1;
                 end
   end
   
always @ ( posedge clk or negedge rst)
        begin
        if (! rst )
                        h21<=0;
        else if(detect1==1'b0 && detect2==1'b1 )
                        h21<=1;
        else
                        h21<=0;
   end
   
endmodule
ok1246 发表于 2011-10-24 16:47:42 | 显示全部楼层
看不懂。。。
至芯兴洪 发表于 2011-10-28 13:56:52 | 显示全部楼层
你还是从最基本的老老实实学起吧
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-5-11 00:22 , Processed in 0.068160 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表