首页 > 解决方案 > 具有外部触发和触发输出的 VHDL 脉冲生成

问题描述

我被困在这个程序中,以从外部触发和内部触发创建自定义脉冲。

这是我的外部触发程序。它将从“trig_in”输入端口获取触发信号以生成自定义脉冲:

if state_trig = extrig then
    if (trig_in = '1') then
        counter1 <= "000000";
            if(counter >= 1 and counter <= 2) then
                pwm_out1 <= '1';
                pwm_out2 <= '0';
            end if;
            if(counter > 2 and counter <= 600) then
                pwm_out1 <= '0';
                pwm_out2 <= '0';
            end if;
            if(counter > 600 and counter <= 3000) then
                pwm_out1 <= '1';
                pwm_out2 <= '1';
            end if;
        counter <= counter + 1;
    else if (trig_in = '0') then
        counter <= "000000";
        counter1 <= counter1 + 1;
            if (counter1 >= 2100) then
                pwm_out1 <= '0';
                pwm_out2 <= '0';
            end if;
        end if;
    end if;
end if;

这是内部触发的程序。它将生成一个 1kHz 重复脉冲以在“trig_out”输出端口上触发:

if state_trig = intrig  then
    --1kHz
        if(i >= 1 and i <= 2) then
            pwm_out1 <= '1';
            pwm_out2 <= '0';
        end if;
     if(i > 2 and i <= 600) then
            pwm_out1 <= '0';
            pwm_out2 <= '0';
        end if;        
     if(i > 600 and i <= 3000) then
            pwm_out1 <= '1';
            pwm_out2 <= '1';
        end if;      
     if(i > 3000) then
            pwm_out1 <= '0';
            pwm_out2 <= '0';
        end if;
        if(i = 300000) then i := 0; end if;
        i := i + 1; 
    end if;
end if;

我使用 fsm 状态来确定“extrig”和“intrig”状态。

 type    fsm_trig   is (none, intrig, extrig);
 signal state_trig : fsm_trig := none;

两个程序分别工作完美。但是当我将它们都放在一个进程(时钟)中时。每个触发程序中产生的脉冲相互冲突。我正在使用 UART 来确定触发器的状态。将两个信号“pwm_out1”和“pwm_out2”分配给输出端口以生成脉冲:

out_clk1 <= pwm_out1;
out_clk2 <= pwm_out2;

以下是两个程序的端口:

    sys_clk     : in   STD_LOGIC;           --system clock
    rx          : in     STD_LOGIC;         --receive for UART
    trig_in     : in   STD_LOGIC;           --External trigger
    trig_out : out  STD_LOGIC;              --Internal trigger
    out_clk1 : out  STD_LOGIC;              --Pulse out1
    out_clk2 : out  STD_LOGIC;              --Pulse out2

请给我任何想法以避免两个程序之间的冲突。提前致谢。

标签: vhdlgeneratorpulse

解决方案


推荐阅读