【问题标题】:VHDL Up/Down CounterVHDL 加/减计数器
【发布时间】:2015-04-04 20:25:15
【问题描述】:

大家晚上好。我首先要说我对 VHDL 很陌生。我有一个项目要求我为摩托罗拉用 VHDL 制作的倒数计数器建模(任何好奇的人都可以使用 MC14510B)。

从数据表可以看出,如果输入 PE(预设启用)切换为高电平,则输入引脚 p4...p1 上的 4 个预设值直接传递到输出 q4...q1。

由于某种原因,我的代码拒绝编译,抛出错误 Error: COMP96_0143: MC14510B.vhd : (56, 13): Object "p" cannot be written。我使用 Aldec 作为编译器,不知道我做错了什么。我不想将输入写入 p,我想使用存储在 p 中的值写入 qtemp。

谁能看到我搞砸了什么?在进程语句中,主 if-else 中的 else 语句给我带来了问题(p

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.std_logic_unsigned.all;

entity MC14510B is
  port (
    signal pe     : in    std_logic;
    signal ci_not : inout std_logic;
    signal reset  : in    std_logic;
    signal updown : in    std_logic;
    signal clk    : in    std_logic;
    signal p      : in    std_logic_vector (3 downto 0);
    signal q      : out   std_logic_vector(3 downto 0);
    signal co_not : inout std_logic
    );
end;

architecture myarch of MC14510B is
begin

  process(pe, ci_not, reset, updown, clk)
    variable qtemp  : std_logic_vector(3 downto 0);
    variable cotemp : std_logic;
  begin
    if reset = '1' then                                     --reset condition
      qtemp := "0000";
    elsif clk'event and updown = '1' and ci_not = '1' then  --count up
      if qtemp < 15 then
        qtemp  := qtemp + 1;
        cotemp := '1';
      else
        qtemp  := "0000";
        cotemp := '0';
      end if;
    elsif clk'event and updown = '0' and ci_not = '1' then  --count down
      if qtemp > 0 then
        qtemp  := qtemp - 1;
        cotemp := '1';
      else
        qtemp  := "0000";
        cotemp := '0';
      end if;
    elsif ci_not = '0' then
      qtemp  := "1010";
      cotemp := '1';
    else
      if pe = '1' then                                      --enable preset
        p      <= qtemp;                                    --output = input presets
        cotemp := '1';
      else
        qtemp  := qtemp;                                    --output = output
        cotemp := '1';
      end if;
    end if;
    q      <= qtemp;
    co_not <= cotemp;
  end process;
end myarch;

【问题讨论】:

    标签: vhdl counter updown


    【解决方案1】:

    你似乎有一个分配给 qtemp 的任务在你有 p := qtemp 并且应该有 qtemp &lt;= p 的地方转过来。看起来 p 也应该在该进程的敏感列表中。

    然后您的代码进行分析。不保证它在其他方面是正确的。

    p 被声明为模式,你不能写入它。

    【讨论】:

    • 敏感列表?恐怕我不知道那是什么意思:/
    • 学习基本 VHDL 概念的绝佳机会;在这里试试:Google VHDL sensitivity list
    • 括号中的位:process(pe, ci_not, reset, updown, clk) 是敏感度列表。在进程结束时有一个隐含的wait on pe, ci_not, reset, updown, clk; 语句。它暂停流程执行,直到在其中一个信号上发生事务。与时钟一起影响异步分配的任何东西都应该在敏感度列表中。在这种情况下,如果 P 在 PE 为“1”时发生变化,会发生什么?如果敏感度列表中没有 P,则会错过更改。
    • 敏感度列表中似乎不需要 updown 和 ci_not。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 2020-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多