loveff 发表于 2012-10-23 11:09:42

简单的滤波程序仿真出问题,求大神解答

以下是我在上次论坛两个高手指点后的改进程序,但是在仿真时两个计数器还是偶尔会有一到两个周期的红颜色的错误,求大神给解答一下啊
PS:当我改两个计数器N1和N2的值后,仿真时的结果有时都很好,有时两个计数器countb1和countb2就会有显示红色的X一到两个周期,输出fu是没有问题的

--****************************************************************************
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity filter_unbalance is
        port(        delayu,u,clku: in std_logic;
                           fu : buffer std_logic);
end entity;
architecture behav of filter_unbalanceis
    constant N1:integer:=50;
       constant N2:integer:=103;
                signal countb1: integer range 0 to N1+1;
                signal countb2: integer range 0 to N2+1;
                signal fb1:integer range 0 to 1;
                signal fb2:integer range 0 to 1;               
begin
        process(delayu,clku,u)
                begin
                        if(delayu ='0')then
                                countb1<=0;       
                                fb1<=0;
                        elsif(rising_edge(clku)) then
                                        if(u ='1' and countb1<=N1)then
                                                countb1<=countb1+1;
                                        elsif(u='0')then
                                                countb1<=0;               
                         else
                       countb1<=countb1;       
                                        end if;               
                                        if(countb1 >= N1)then
                                                fb1<=1;                           --输入信号高电平保持一段时间后输出变为高电平
                                        else
                                                fb1<=0;
                                        end if;
                                end if;
                end process;
       
        process(delayu,clku,u)
                begin
                        if(delayu ='0')then
                                countb2<=0;       
                                fb2<=0;
                        elsif(falling_edge(clku)) then
                                        if(u ='0' and countb2<=N2)then
                                                countb2<=countb2+1;
                                        elsif(u='1')then
                                                countb2<=0;               
                         else
                       countb2<=countb2;       
                                        end if;               
                                        if(countb2 >= N2)then
                                                fb2<=0;                           --输入信号低电平保持一段时间后输出变为低电平
                                        else
                                                fb2<=1;
                                        end if;
                                end if;
                end process;
               
fu<= '1' when (fb1=1)   else
          fuwhen ((fb1=0)and(fb2=1))   else
   '0' when (fb2=0)         else
          fuwhen ((fb1=1)and(fb2=0))   else
          'Z';
               
end behav;
--****************************************************************************
页: [1]
查看完整版本: 简单的滤波程序仿真出问题,求大神解答