首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >VHDL边缘检测

VHDL边缘检测
EN

Stack Overflow用户
提问于 2013-07-02 23:12:49
回答 2查看 16.3K关注 0票数 4

我想检测串行数据信号(din)上的边沿。我已经用VHDL语言写了下面的代码,它运行成功,但是边沿是以一个时钟周期延迟检测的,即在每个边沿产生一个clk_50mhz周期延迟的变化输出。有没有人能帮我尽快检测出边缘?谢谢。

代码语言:javascript
运行
复制
 process (clk_50mhz)
 begin
        if clk_50mhz'event and clk_50mhz = '1' then
            if (rst = '0') then
                shift_reg <= (others => '0');
            else
                shift_reg(1) <= shift_reg(0);
                shift_reg(0) <= din;    
                        end if;      
        end if;
 end process;

    process (clk_50mhz)
    begin
        if clk_50mhz'event and clk_50mhz = '1' then
            if rst = '0' then
                change <= '0' ;
            elsif(clk_enable_2mhz = '1') then
                change <= shift_reg(0) xor shift_reg(1);                    
            end if ;
        end if ;
    end process ;

当我将我的代码改为下面的代码时,我能够检测到边缘

代码语言:javascript
运行
复制
 process (clk_50mhz)
begin
    if clk_50mhz'event and clk_50mhz = '1' then
        if (RST = '0') then
            shift_reg <= (others=>'0');
        else
            shift_reg(1) <= shift_reg(0);
            shift_reg(0) <= din;    
  end if;     
    end if;
end process;

change <= shift_reg(1) xor din; 
EN

回答 2

Stack Overflow用户

发布于 2013-07-02 23:48:11

这就是你要的

代码语言:javascript
运行
复制
library ieee;
use ieee.std_logic_1164.all;

entity double_edge_detector is
    port ( 
        clk_50mhz   : in std_logic;
        rst         : in std_logic;
        din         : in std_logic;
        change      : out std_logic
    );
end double_edge_detector;

architecture bhv of double_edge_detector is

signal din_delayed1 :std_logic;

begin
    process(clk_50mhz)
    begin
        if rising_edge(clk_50mhz) then
            if rst = '1' then
                din_delayed1 <= '0';
            else
                din_delayed1 <= din;
            end if;
        end if;

    end process;

    change <= (din_delayed1 xor din); --rising or falling edge (0 -> 1 xor 1 -> 0)


end bhv;
票数 4
EN

Stack Overflow用户

发布于 2013-07-03 00:19:13

您必须使用组合过程来检测差异,而不会导致额外的时钟周期延迟。(您仍然需要一个寄存器来延迟输入。)

代码语言:javascript
运行
复制
DELAY: process(clk_50mhz)
begin
    if clk_50mhz'event and clk_50mhz = '1' then
        din_reg <= din;
    end if;
end process;

change <= din xor din_reg;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17429280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档