我正在制作一个包含普通入口和出口的多层停车场系统模块,其想法是,当我从信号car entry
或car exit
获得输入刺激时,它将检查汽车的类型然后输出应显示为轿厢应行驶的特定类型预留的高度,如果特定类型的插槽预留空间已满,则应按此输出。在给出输入刺激后的下一个时钟周期之后,才通过输出刺激代码。
我尝试使用不同的if-else块来计数操作,还尝试使用标志来进行不同的处理,并尝试将其更改为不同的if-else块,但是仍然相同。我是vhdl的初学者,执行语句非常混乱,在线搜索几乎无济于事,请帮助我哪里出错了?
library ieee;
use ieee.std_logic_1164.all;
use ieee.Numeric_std.all;
use work.Parking_Package.all;
entity CarPark is
port( clk :in std_logic;
rst : in std_logic;
car_in : in std_logic;
Car_out : in std_logic;
Ent_car_type : car_type;
Ext_car_type : car_type;
Status : out level
);
end CarPark;
architecture behave of CarPark is
signal count : counter;
begin
SLOT_CHECKING: process(rst,clk)
begin
if(rst= '1')then
count <= (others => 0);
Status <= FULL;
elsif(rising_edge(clk))then
if(car_in )then
case(Ent_car_type)is
when Admin =>
if(count(Admin) < 5) then
Status <= L1;
count(Admin) <= count(Admin) +1;
else
Status <= FULL;
end if;
when Staff =>
if(count(Staff) < 5) then
Status <= L2;
count(Staff) <= count(Staff) + 1;
else
Status <= FULL;
end case;
end if;
elsif(car_out)then
case(Ext_car_type)is
when Admin =>
if(count(Admin) >0) then
Status <= L1a;
count(Admin) <= count(Admin) - 1;
else
count(Admin)<= 0;
end if;
when Staff =>
if(count(Staff) >0) then
Status <= L2a;
count(Staff) <= count(Staff) - 1;
else
count(Staff) <= 0;
end if;
end process;
end behave;
用户定义的软件包在下面给出
library ieee;
use ieee.std_logic_1164.all;
use ieee.Numeric_std.all;
package Parking_Package is
type car_type is (Admin, Staff);
type level is (L1, L2a, FULL);
type counter is array (Staff downto Admin) of integer range 0 to 22;
end Parking_Package;
package body Parking_Package is
end Parking_Package;
使用reset初始化后,我将car_in
的输入设为1,然后
car_type
作为管理员,在下一个时钟中,输出显示为L1
并且如果我将car_type
的值强制设为staff
,则会在下一个时钟周期模拟相应的输出。
![ScreenShot模拟] https://imgur.com/a/B6cqADn
答案 0 :(得分:0)
首先,一些评论:
然后使用可用于通过2个过程获得预期行为的代码(一个纯粹是顺序的,另一个纯粹是组合的):
signal current_count : counter;
signal next_count : counter;
signal current_status : level;
signal next_status : level;
begin
SEQ : process(rst_tb, clk_tb)
begin
if (rst_tb = '1') then
current_count <= (others => 0);
current_status <= FULL;
elsif (rising_edge(clk_tb)) then
current_count <= next_count;
current_status <= next_status;
end if;
end process;
SLOT_CHECKING : process(current_count, current_status, car_in, car_out, Ent_car_type, Ext_car_type)
begin
next_count <= current_count;
next_status <= current_status;
if (car_in = '1') then
case (Ent_car_type) is
when Admin =>
if (current_count(Admin) < 5) then
next_status <= L1;
next_count(Admin) <= current_count(Admin) + 1;
else
next_status <= FULL;
end if;
when Staff =>
if (current_count(Staff) < 5) then
next_status <= L2;
next_count(Staff) <= current_count(Staff) + 1;
else
next_status <= FULL;
end if;
end case;
elsif (car_out = '1') then
case (Ext_car_type) is
when Admin =>
if (current_count(Admin) > 0) thenremarques
next_status <= L1a;
next_count(Admin) <= current_count(Admin) - 1;
else
next_count(Admin) <= 0;
end if;
when Staff =>
if (current_count(Staff) > 0) then
next_status <= L2a;
next_count(Staff) <= current_count(Staff) - 1;
else
next_count(Staff) <= 0;
end if;
end case;
end if;
end process;
count <= next_count ;
Status <= next_status ;
警告,使用此代码,输出直接来自组合逻辑:不建议这样做,但这是获得预期行为的唯一方法。
如果此应用程序仅是一种实践,我也建议您再举一个更适合VHDL的示例:滤波器,SPI通信,处理单元...