This question already has an answer here:
- VHDL: Unable to read output status 2 answers
library IEEE;
use IEEE.std_logic_1164.all;
entity doorlock is
port( reset : in std_logic;
enable : in std_logic;
password : in std_logic_vector (7 downto 0);
door : out std_logic_vector (7 downto 0);
lock : out std_logic;
alarm : out std_logic;
turnoff : out std_logic);
end doorlock;
--password is 10(decimal no.) which is 00010000(binary no.)
architecture DDL of doorlock is
signal err_count : integer range 0 to 5 := 0;
begin
lock <= '0' when (reset = '0');
alarm <= '0' when (reset = '0');
turnoff <= '0' when (reset = '0');
door <= "00000000" when (reset = '0');
lock <= '0' when (enable <= '0');
process(password)
begin
if (password = "-------1") then
door <= "00000000";
elsif (password = "------10") then
door <= "00000001";
elsif (password = "-----100") then
door <= "00000011";
elsif (password = "----1000") then
door <= "00000111";
elsif (password = "---00000") then
door <= "00001111";
elsif (password = "--110000") then
door <= "00011111";
elsif (password = "-1010000") then
door <= "00111111";
elsif (password = "10010000") then
door <= "01111111";
elsif (password = "00010000") then
door <= "11111111";
end if;
err_count <= err_count + 1;
end process;
alarm <= '1' when (err_count = 3);
turnoff <= '1' when (err_count = 5);
lock <= '1' when (door = "11111111" and turnoff = '0' and alarm = '0');
end DDL;
I made this code for my homework making digital door lock. And this line have error as I compile it.
lock <= '1' when (door = "11111111" and turnoff = '0' and alarm = '0');
Error is like this below
** Error: D:\modelsim\Door.vhd(53): Cannot read output "alarm".
VHDL 2008 allows reading outputs. This facility is enabled by compiling with -2008.
** Error: D:\modelsim\Door.vhd(53): Cannot read output "door".
VHDL 2008 allows reading outputs. This facility is enabled by compiling with -2008.
** Error: D:\modelsim\Door.vhd(53): Cannot read output "turnoff".
VHDL 2008 allows reading outputs. This facility is enabled by compiling with -2008.
** Error: D:\modelsim\Door.vhd(55): VHDL Compiler exiting
I don't know why it happens please help me
First off: "Please help me" is not a good question. Better would be something like "Modelsim error "cannot read output" when compiling"
Second off: The error is quite descriptive. "Cannot read output "alarm"".
alarm
is declared asThus it is an output port. In pre-2008 VHDL it was not allowed to read output ports. Next the compiler hints on how to fix it:
So do so! In your modelsim compilation window select "default options"
And then set to VHDL-2008
Alternatively you can actually do what is described (add the
-2008
) on the command line:Voila. Finished! Not?
No wait, still doesn't work!
You have a multiple driver error. In line 23 it states:
This acts as a latch, effectively being the same as
Thus once
reset='0'
has occurred, the process will drivedoor
to a fixed value. In thepassword
-triggered process you again drivedoor
! This will resolve badly. E.g. if(password = "------10")
, thendoor <= "00000001"
. This will resolve:Because connecting
'0'
to'1'
is equivalently a short-circuit.So let's look at proper design. You're now triggering on a change of
password
. Not so nice, but it's possible. I would use another trigger, like theenable
signal that is not being used. But anyhow: we introduce an extra signal to detect the changepassword_delay
. But more importantly we introduce a clock. In digital hardware most systems use a clock. Finally, we use the new VHDL-2008 statementcase?
to decode the don't cares.Together the VHDL-2008 code becomes:
That's something different, eh? I'm sorry, but I don't have time to write a test bench for you.
NOTE: The code gives a compiler warning
Ignore this. This is required for simulation as else undefined initial value of
password_delay
will cause a trigger ofpassword /= password_delay
.