集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 6847|回复: 11

verilog这段代码的输出怎样去掉毛刺

[复制链接]
CCIE 发表于 2010-6-27 23:09:14 | 显示全部楼层 |阅读模式
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity counter8 is
port( clk_Mfo  : in std_logic;
    rst    : in std_logic;
    clk_out_2Nfo : out std_logic);
end entity;

architecture behave of counter8 is
signal cq : std_logic_vector(2 downto 0);
signal temp : std_logic;
begin

P1:process(clk_Mfo,rst,cq)
begin
if rst = '0' then cq <= "000";
elsif clk_Mfo'event and clk_Mfo = '1' then
    cq <= cq + 1;
    if cq = "111" then
        cq <= "000";
        
    end if;
end if;
end process P1;

P2:process(clk_Mfo,cq)
begin
    if cq(0) = '0' then temp <= '0';
    elsif cq(1) = '0' then temp <= '0';
    elsif cq(2) = '0' then temp <= '0';
    else temp <= clk_Mfo;
    end if;
end process P2;

clk_out_2Nfo <= temp;
end behave;
从000开始计数,到111输出一个正脉冲,且保证正脉冲的宽度和输入时钟正脉冲宽度一致
CTT 发表于 2010-6-28 00:06:55 | 显示全部楼层
if (cp==3'b111)<br>
&nbsp; &nbsp;clk_out2 &lt;= clk_in<br>
you can try
interige 发表于 2010-6-28 01:09:44 | 显示全部楼层
现在知道了
VVIC 发表于 2010-6-28 01:27:56 | 显示全部楼层
由于<br>
P4:process(clk_Mfo,cq)<br>
begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if cqa(0) = '0' then tempa &lt;= '0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;elsif cqa(1) = '0' then tempa &lt;= '0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;elsif cqa(2) = '0' then tempa &lt;= '0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else tempa &lt;= clk_Mfo;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end if;<br>
end process P4;<br>
毛刺在计数器转态时有可能出现<br>
<br>
<br>
更改如下:<br>
P4:process(clk_Mfo,cq)<br>
begin<br>
&nbsp;&nbsp;if rst = '0'&nbsp;&nbsp;then <br>
&nbsp; &nbsp; &nbsp; &nbsp; tempa &lt;= '0';<br>
&nbsp;&nbsp;elsif clk_Mfo'event and clk_Mfo = '1' then<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case cq is<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; when "000" =&gt;&nbsp; &nbsp; &nbsp; &nbsp; tempa &lt;= '0'; <br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; when "001" =&gt;&nbsp; &nbsp; &nbsp; &nbsp; tempa &lt;= '0'; <br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; when "010" =&gt;&nbsp; &nbsp; &nbsp; &nbsp; tempa &lt;= '0';&nbsp;&nbsp;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; when "011" =&gt;&nbsp; &nbsp; &nbsp; &nbsp; tempa &lt;= '0'; <br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; when "100" =&gt;&nbsp; &nbsp; &nbsp; &nbsp; tempa &lt;= '0';&nbsp;&nbsp;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; when "101" =&gt;&nbsp; &nbsp; &nbsp; &nbsp; tempa &lt;= '0'; <br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; when "110" =&gt;&nbsp; &nbsp; &nbsp; &nbsp; tempa &lt;= '0';&nbsp;&nbsp;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; when others =&gt;&nbsp; &nbsp; &nbsp; &nbsp; null;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end case;&nbsp; &nbsp; &nbsp; &nbsp; <br>
<br>
&nbsp;&nbsp;end if;<br>
end process P4;<br>
<br>
temp &lt;=&nbsp;&nbsp;clk_Mfo when cq="111" else tempa;&nbsp;&nbsp;<br>
<br>
<br>
output只有在 clk_Mfo变化才改变,不受计数器转态时的瞬间电平影响。
longtim 发表于 2010-6-28 02:10:56 | 显示全部楼层
楼上的也不一定可行,谁仿真一下贴来结果看看<br>
应该是在011变100,111变000时多位变化引起的毛刺<br>
其实,计数方式改成格雷码,约翰逊计数方式就不会产生毛刺了<br>
<br>
[ 本帖最后由 dieyi31 于 2006-9-11 22:43 编辑 ]
ngtim 发表于 2010-6-28 02:23:06 | 显示全部楼层
回帖挣钱,帮你顶。
UFP 发表于 2010-6-28 02:55:55 | 显示全部楼层
试了试,改成下面这样,还有毛刺!<br>
library ieee;<br>
use ieee.std_logic_1164.all;<br>
use ieee.std_logic_unsigned.all;<br>
<br>
entity count8 is<br>
port( clk_Mfo&nbsp; &nbsp;&nbsp; &nbsp;: in std_logic;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; rst&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; : in std_logic;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; clk_out_2Nfo : out std_logic);<br>
end entity;<br>
<br>
architecture behave of count8 is<br>
signal cq : std_logic_vector(2 downto 0);<br>
signal temp,tempa : std_logic;<br>
begin<br>
<br>
P1:process(clk_Mfo,rst,cq)<br>
begin<br>
if rst = '0' then cq &lt;= "000";<br>
elsif clk_Mfo'event and clk_Mfo = '1' then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;cq &lt;= cq + 1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if cq = "111" then <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; cq &lt;= "000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end if;<br>
end if;<br>
end process P1;<br>
<br>
P4:process(clk_Mfo,cq)<br>
begin<br>
&nbsp;&nbsp;if rst = '0'&nbsp;&nbsp;then <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;tempa &lt;= '0';<br>
&nbsp;&nbsp;elsif clk_Mfo'event and clk_Mfo = '1' then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; case cq is<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when "000" =&gt;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;tempa &lt;= '0'; <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when "001" =&gt;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;tempa &lt;= '0'; <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when "010" =&gt;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;tempa &lt;= '0';&nbsp;&nbsp;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when "011" =&gt;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;tempa &lt;= '0'; <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when "100" =&gt;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;tempa &lt;= '0';&nbsp;&nbsp;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when "101" =&gt;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;tempa &lt;= '0'; <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when "110" =&gt;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;tempa &lt;= '0';&nbsp;&nbsp;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when others =&gt;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;null;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; end case;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br>
<br>
&nbsp;&nbsp;end if;<br>
end process P4;<br>
<br>
temp &lt;=&nbsp;&nbsp;clk_Mfo when cq="111" else tempa;&nbsp;&nbsp;<br>
<br>
clk_out_2Nfo &lt;= temp;<br>
end behave;
longt 发表于 2010-6-28 04:42:18 | 显示全部楼层
一般的如果是在组合逻辑中,<br>
有计数器输出的不同位的计算操作的时候,<br>
正常计数由于可能会一次变化多个位,可能会使电路产生毛刺<br>
比如楼主帖子的正常输出高电平脉冲前面那个毛刺,<br>
就是在计数器由101-&gt;110的时候,可能cq[0]新值尚未到达(仍为1),<br>
但此时cq[1]新值1已经到达,则会产生一个 111,产生一个毛刺。(别的地方没有产生不知道为什么,可能小延迟不同。)<br>
这种毛刺问题,解决的最好的方法,就是用gray码计数,使得计数输出每次只变化一位。
longt 发表于 2010-6-28 06:30:52 | 显示全部楼层
但是楼主帖子中后面的那个由111-&gt;000 变化时产生的毛刺,用gray码应该是无法避免的。<br>
原因很清楚,因为你的cq的变化取决于clk的变化,所以cq从111变化到000总是在clk一个上升沿变化之后<br>
此时,clk的变化引起了p4的运行,则产生了一个毛刺。<br>
<br>
上面是我针对这个题目的想法,不知道对否,欢迎讨论。
longt 发表于 2010-6-28 08:06:42 | 显示全部楼层
斑竹的裹脚,又长又臭
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2024-12-24 11:05 , Processed in 0.064713 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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