信号led无法合成,同步描述不好?

时间:2014-05-07 21:22:51

标签: vhdl fpga xilinx

我创建了一个分频器,我想用FPGA板测试它。为了测试它,如果开关打开,我想制作具有分频的LED闪烁。问题是如果时钟不在上升沿,我不知道如何改变led的值。

以下是我得到的确切错误:

  第51行:信号led无法合成,同步描述不良。当前软件版本不支持您用于描述同步元素(寄存器,内存等)的描述样式。    - >

library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.STD_LOGIC_ARITH.ALL;
    use IEEE.STD_LOGIC_UNSIGNED.ALL;


entity divizor1 is
    Port (clk : in STD_LOGIC;
            --clk_out : out STD_LOGIC;
            btn : in STD_LOGIC;
            led : out STD_LOGIC
            );
end entity divizor1;


architecture divizor_frecv of divizor1 is
    signal cnt : std_logic_vector (24 downto 0);
    signal clock :std_logic;
    signal bec : std_logic;
        begin
            process(clk)
                begin
                    if rising_edge(clk) then
                        cnt<=cnt +1;
                    end if;
                    if (cnt = "1111111111111111111111111") then
                        --clk_out <= '1';
                        clock <= '1';
                    else
                    --  clk_out <= '0';
                        clock <= '0';
                    end if;

            end process;

process (clock, btn)
    begin
        if btn = '1' then
                if clock'event and clock = '1' then
                    led <= '1';
                else
                    led <= '0';
                end if;

        end if;
    end process;



end divizor_frecv;

2 个答案:

答案 0 :(得分:0)

错误消息似乎在抱怨您正在使用cnt计数器的输出作为时钟。

相反,您可以将其用作切换启用和clk作为时钟:

--process (clock, btn)
process (clk, btn)
    begin
        -- if btn = '0' then
        if btn = '1' then  -- reset led
            led <= '0';    -- or '1' which ever turns it off
            -- if clock'event and clock = '1' then
        elsif clock = '1' and rising_edge(clk) then -- clock as enable
            -- led <= '1';
            led <= not led;
            -- else
            --     led <= '0';
        end if;

        -- end if;
    end process;

状态btn方便地重置,以便为led提供能够使用not led的初始值。这需要将端口信号led设为模式inout,或者您需要一个代理变量或信号,该信号已分配给led,以便not led正常工作(因此可以读取led )。 cnt的默认值也有助于模拟。

我作弊并让您的计数器cnt更短,并将时钟设置为4 MHz以说明:

divizor test

模拟是使用ghdl和gtkwave完成的。

答案 1 :(得分:0)

process (clock, btn)
begin
    if btn = '1' then
            if clock'event and clock = '1' then
                led <= '1';
            else
                led <= '0';
            end if;

    end if;
end process;

乍一看,我猜这个按钮是时钟启用。但是,else部分与时钟相连。因此,您要求led在时钟上升沿变高,在其他时间变低;鉴于时钟边缘是一个瞬间,这并没有多大意义(它总是很低)。我希望您能够根据时钟边缘的其他状态更新led,例如:

process (clock)
begin
    if clock'event and clock = '1' then
        led <= btn;
    end if;
end process;

如果您只想让LED指示时钟脉冲(可能检测得太快),您可以直接将时钟路由到LED。你的分频器已经产生非常短的脉冲(通常我们的目标是占空比为50%,这个占0.000003%)。

相关问题