VHDL Up/Down Counter

2k Views Asked by At

Good evening everyone. I'll start off by saying that I am very new to VHDL. I have a project that is asking me to model an updown counter that is made by Motorola in VHDL (an MC14510B for anyone curious).

From the datasheet one can see that if the input PE (preset enable) is toggled high, then the 4 preset values at input pin p4...p1 are passed straight through to the output q4...q1.

For some reason, my code refuses to compile, throwing the error Error: COMP96_0143: MC14510B.vhd : (56, 13): Object "p" cannot be written. I'm using Aldec as a compiler and have no idea what I'm doing wrong. I don't want to write to p the input, I want to write to qtemp with the values that are stored in p.

Can anyone see what I've messed up? In the process statement the else statement in the main if-else is what is giving me problems (the p <= qtemp line). Any help would be tremendously appreciated.

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;
1

There are 1 best solutions below

4
On

You seem to have an assignment to qtemp turned around where you have p := qtemp and should have qtemp <= p. It also looks like p should be in the sensitivity list for that process.

Your code then analyzes. No guarantees it's otherwise correct.

p is declared mode in, you can't write to it.