【问题标题】:I'm getting an syntax error in my VHDL code near counter我在计数器附近的 VHDL 代码中遇到语法错误
【发布时间】:2023-03-19 11:50:02
【问题描述】:

我正在尝试模拟脉冲宽度调制 (PMW) 波形发生器并在 ISE 中遇到语法错误。检查了 fuse.xmsgs 并发现它在柜台附近。有人能指出语法错误吗?

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.numeric_std.all;
entity pwm_gen is
    port
    (
        clock, reset : in std_logic;
        width       : in std_logic_vector(7 downto 0);
        pwm          : out std_logic);
end pwm_gen;

architecture bhv of pwm_gen is
    type counter is range 0 to 255; 
    counter count := 0; 
begin
    process (clock) 
    begin
        if (reset = '1') then 
            count <= 0;
        elsif (clock'event and clock = '1') then 
            if (count <= width) then
                count <= count + 1; 
                pwm <= '1';
            else
                count <= count + 1; 
                pwm <= '0';
            end if;
        end if;
    end process;
end bhv;

【问题讨论】:

    标签: syntax-error vhdl simulation pwm xilinx-ise


    【解决方案1】:

    counter count := 0;

    这是非法语法,因为您没有声明对象类(信号、常量、变量)。您需要使用以下格式:

    signal count : counter := 0

    这也是非法的,因为你将一个整数与一个没有包含包的std_logic_vector 进行比较。您需要将 slv 转换为 unsigned

    if (count &lt;= unsigned(width)) then

    最后,敏感列表中缺少reset

    【讨论】:

    • 非常感谢,但在开始上述过程时我仍然遇到语法错误。
    • 你忘记了这里的类型:type counter is integer range 0 to 255; 但是为什么你需要将它声明为它自己的类型呢?通常更容易简单地限制信号:signal count : integer range 0 to 255;
    • 是的,我还是新手。边学习边参考各种来源。谢谢你的帮助,好先生!
    猜你喜欢
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多