本帖最后由 sair_lucifer 于 2010-12-21 16:15 编辑
我大三,有一个数字系统设计作业,做一个自动售货机。源程序如下
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity salor is
port( clk : in std_logic;
reset,sel : in std_logic;
kind : in std_logic_vector(1 downto 0); --由于输入接口数目不够,所以本程序
coin1,coin5: in std_logic; --选定1,2,5毛邮票,投入1,5毛硬币
incoin : out std_logic_vector(3 downto 0); --累计投入金额
sound : out std_logic; --警报
a,b,c: out std_logic; --购买成功指示灯
ret : out std_logic_vector(3 downto 0)
);
end entity salor;
architecture behav of salor is
signal tincoin : std_logic_vector(3 downto 0);
signal tcoin : std_logic_vector(3 downto 0);
signal coin0 : std_logic;
signal alarm : std_logic;
signal alarm0 : std_logic; --警报清零信号
begin
incoin <= tincoin ;
coin0<=not(coin1 or coin5 ) xor reset;
sound<=alarm and clk;
sum : process (coin1 ,coin5) --进程:计算投入硬币面值
begin
if coin0='1' then
tcoin<="0000";
elsif coin1='1' then
tcoin<="0001";
elsif coin5='1' then
tcoin<="0101";
end if;
end process sum;
pay1 : process (coin0) --进程:计算累计投入金额
begin
if reset='1' then
tincoin<="0000";
elsif coin0='1' then
if tincoin <="1001" then
tincoin<=tincoin+tcoin;
else tincoin<="0000";
end if;
end if;
end process pay1;
sell : process(sel,reset,alarm0) --进程:购买和找零
begin
if reset='1' then
ret<="0000";
elsif alarm0='1' then
alarm<='0';
elsif sel='1'and sel'event then
case kind is
when "01" =>
if tincoin< 1 then
ret<="0000";
alarm<='1';
else
ret<=tincoin-"0001";
end if;
when "10"=>
if tincoin< 2 then
ret<="0000";
alarm<='1';
else
ret<=tincoin-"0010";
end if;
when "11"=>
if tincoin< 5 then
ret<="0000";
alarm<='1';
else
ret<=tincoin-"0101";
end if;
when others=>
ret<=tincoin;
end case;
end if;
end process sell;
alarm1 : process(clk) --进程:警报计时3秒
variable c0,c1: integer :=0;
begin
if clk='1' and clk'event then
if c0 =5 then
alarm0<='1';c0:=0;
elsif alarm='1' then
c0:=c0+1;
end if;
if c1=2 then
alarm0<='0';
c1:=0;
elsif alarm0='1' then
c1:=c1+1;
end if;
end if;
end process alarm1;
light : process(sel,reset) --购买成功指示
begin
if reset='1'then
a<='0';b<='0';c<='0';
elsif sel='0' and sel'event then
case kind is
when "01" =>
if alarm='1' then a<='0';
else a<='1';
end if;
when "10" =>
if alarm='1' then b<='0';
else b<='1';
end if;
when "11" =>
if alarm='1' then c<='0';
else c<='1';
end if;
when others =>null;
end case;
end if;
end process light;
end behav;
在不加最后一个light进程的时候波形仿真没问题,但是加了之后coin1信号对累计钱数没影响,coin5变成了加4.那位高手能给小弟分析一下这是什么原因。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>