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;
outputh2l;

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]
查看完整版本: 请教一个 检测低电平的程序