VHDL延迟单稳态初始化

时间:2018-01-28 19:00:26

标签: vhdl

想法是在Trig输入被激活时产生延迟脉冲,延迟和脉冲宽度分别可以通过“延迟”来调整。并且' ton'。我使用整数计数器比较延迟然后延迟+吨以切换脉冲输出。

问题是时序在电路板编程之后开始:sigPulseCounter递增...即使信号被初始化。有什么提示吗?

重置效果很好,Trig也有效,但启动时会出现不需要的脉冲。

感谢您的反馈。

library ieee;
use ieee.std_logic_1164.all;

entity DelayedMonostable is
    generic(
            delay :integer:= 2*40000000;
            ton :integer:= 2*40000000);
    port (
            Clk: in std_logic;
            Reset: in std_logic;
            Trig: in  std_logic;
            Pulse: out std_logic;
            Debug: out std_logic);
end DelayedMonostable;

architecture Behavioral of DelayedMonostable is
-- Signal declaration
signal sigPulseCounterEnable: std_logic := '0';
signal sigPulseCounter : integer := 0;      
signal sigPulse : std_logic :='0';          
signal sigDebug: std_logic := '0';

begin

    Debug <= not sigPulseCounterEnable;
    Pulse <= not sigPulse;

    Counter : process(Clk, Reset)
    begin
        if Reset='0' then
            sigPulseCounter <= 0;
                sigPulseCounterEnable <= '0';
            sigPulse <= '0';

          elsif Trig='0' then
            sigPulseCounter <= 0;
                sigPulseCounterEnable <= '1';
            sigPulse <= '0';

          elsif rising_edge(Clk) then

                if(sigPulseCounterEnable='1') then

                    if(sigPulseCounter = delay) then
                        sigPulse <= '1';
                    end if;

                    if(sigPulseCounter = delay+ton) then
                        sigPulse <= '0';
                        sigPulseCounterEnable <= '0';
                        sigPulseCounter <= 0;
                    end if;

                    sigPulseCounter <= sigPulseCounter + 1;

                end if;

        end if;
    end process Counter;

end Behavioral;

我试图在过程中反转Trig逻辑但没有成功:

elsif Trig='0'

elsif Trig='1' 

修改

我将3个部分拆分为架构,每个部分都为信号或端口赋值 - 现在工作正常。

library ieee;
use ieee.std_logic_1164.all;

entity DelayedMonostable is
    generic(    
          delay : integer := 40000000/2;
          ton : integer := 2*40000000);

    port(   
        Clk: in std_logic;
        Reset: in std_logic;
          Trig: in  std_logic;
        Pulse: out std_logic;
        Debug: out std_logic);
end DelayedMonostable;

---------------------------------------

architecture Behavioral of DelayedMonostable is
-- Signal declaration 
signal PWMCounter : integer;
signal sigTrig: std_logic;

begin

    Debug <= not sigTrig;

    Counter : process(Clk, Reset)
    begin
        if (Reset='0') then
            PWMCounter <= 0;

        elsif(rising_edge(Clk) and sigTrig='1') then

            if(PWMCounter = ton+delay) then
                PWMCounter <= 0;
            else
                PWMCounter <= PWMCounter + 1;
            end if;

      end if;
    end process Counter;


    Trigger: process(Reset, Trig)
    begin
        if (Reset='0') then
            sigTrig <= '0';

        elsif (Trig='0') then
            sigTrig <= '1';

        elsif (PwmCounter = ton+delay) then
            sigTrig <= '0';

        end if;
    end process Trigger;


    Generator : process(Clk, Reset)
    begin
        if (Reset='0') then
            Pulse <= not '0';

        elsif(rising_edge(Clk)) then

            if(PwmCounter=delay) then
                Pulse <= not '1';
            end if;

            if(PwmCounter=delay+ton) then
                Pulse <= not '0';
            end if;

        end if;

    end process Generator;
end Behavioral;

0 个答案:

没有答案