loveff 发表于 2012-10-18 09:45:12

VHDL的程序求助

最近编了个很简单的滤波程序,但是在ModelSim仿真时出现了一点问题,希望大神们快快现身,帮小弟解决这个困扰了好长时间的问题,特此把程序和仿真结果附上。
--****************************************************************************
--此程序为滤波源程序。通过计数输入脉冲的宽度,来滤除杂散窄脉冲。并将滤波后的脉冲输出,双边沿滤波。滤除高低电平杂波宽度范围不同
--****************************************************************************
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;      --delayu复位信号,clku为时钟信号,u为输入待滤波信号
                        fu:                out std_logic);
end entity;
architecture behav of filter_unbalance is
             constant N1:integer:=50;
             constant N2:integer:=120;
             signal countu1: integer range 0 to N1+1;
             signal countu2: integer range 0 to N2+1;
                  signal fu1:std_logic;
begin
        process(delayu,u,clku)
                begin
                        if(delayu ='0')then
                                countu1<=0;
                                countu2<=0;
                                fu1<='0';
                        elsif(clku'event and clku='1') then
                                  if(u ='0' and countu2<=N2)then
                                                countu1<=0;
                                                countu2<=countu2+1;       
                                       elsif(u ='1' and countu1<=N1)then         
                                                countu2<=0;
                                                countu1<=countu1+1;
                                       else
                                           null;
                                        end if;               
                                        if(countu2 >= N2)then
                                                fu1<='0';                                                 --当输入低电平宽度大于或等于N2个时钟周期时输出低电平
                                        end if;
                                        if(countu1 >= N1)then
                                                fu1<='1';                   --当输入高电平宽度大于或等于N1个时钟周期时输出高电平
                                        end if;
                                end if;
                end process;
                fu<=fu1;
        end behav;
--****************************************************************************

NJ8888 发表于 2012-10-18 11:02:28

if(countu2 >= N2)then
      fu1<='0';                                                 --当输入低电平宽度大于或等于N2个时钟周期时输出低电平
end if;
if(countu1 >= N1)then
      fu1<='1';                   --当输入高电平宽度大于或等于N1个时钟周期时输出高电平
   end if;
上面count1 count2两个独立,会存在fu1无所适从

loveff 发表于 2012-10-18 11:49:10

NJ8888 发表于 2012-10-18 11:02 static/image/common/back.gif
if(countu2 >= N2)then
      fu1= N1)then
      fu1

if(u ='0' and countu2<=N2)then
      countu1<=0;
      countu2<=countu2+1;      
elsif(u ='1' and countu1<=N1)then         
      countu2<=0;
      countu1<=countu1+1;
上面这段程序不算把它们关联起来么,如果不算的话,还请您明示,请问如何才能把它们关联起来呢

sky5566 发表于 2012-10-18 12:27:07

本帖最后由 sky5566 于 2012-10-18 12:30 编辑

你程序有問題,不能同時對 fu1 下達 2 個寫入狀態

fu1 <= '1' when countu1>=N1 else
         '0' when countu2>=N2 else 'x';<-----學好 vhdl.....{:lol:}

你的觀念還停留在 c++

loveff 发表于 2012-10-18 16:41:04

sky5566 发表于 2012-10-18 12:27 static/image/common/back.gif
你程序有問題,不能同時對 fu1 下達 2 個寫入狀態

fu1 =N1 else


when 后面是赋值语句,不是判断语句啊,所以还是不行…

loveff 发表于 2012-10-18 17:03:13

sky5566 发表于 2012-10-18 12:27 static/image/common/back.gif
你程序有問題,不能同時對 fu1 下達 2 個寫入狀態

fu1 =N1 else


不好意思,我把它放在进程里面,所以没法调试成,当我把这句话放在进程外面的话,输出结果还是有一小段未知的情况

sky5566 发表于 2012-10-18 19:07:40

本帖最后由 sky5566 于 2012-10-19 01:06 编辑

當然要放在 process 外,因為 else 會引起 if誤判.{:titter:}
你有 4 個狀態,但是卻只輸出 2 個狀態,其他狀態你要怎麼處理fu1?{:sleepy:}

countu1>=N1(最高優先)
countu2>=N2
countu1<N1
countu2<N2

一般我會這樣規劃

f1 <= '0' when NN ="1111111100000000" else
         '1' when NN ="0000000011111111" else
         '0' when NN ="0000000000000000" else
         '1' whne NN ="1111111111111111" elsef1;

NN的值,使用移位bit方式進入........{:lol:}

你可以參考 ps2 解碼程序方式

loveff 发表于 2012-10-18 21:14:21

sky5566 发表于 2012-10-18 19:07 static/image/common/back.gif
當然要放在 process 外,因為 else 會引起 if誤判.
你有 4 個狀態,但是卻只輸出 2 個狀態,其他狀 ...

好的,非常非常感谢你的回答!{:handshake:}
页: [1]
查看完整版本: VHDL的程序求助