打印

关于自动售货机设计问题,非常纠结,高手见笑了

[复制链接]
2690|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
sair_lucifer|  楼主 | 2010-12-21 16:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 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.那位高手能给小弟分析一下这是什么原因。

相关帖子

沙发
gxs64| | 2010-12-21 18:49 | 只看该作者
为什么要用FPGA?不用单片机 OR ARM?

使用特权

评论回复
板凳
op2sql| | 2010-12-21 18:51 | 只看该作者
有一个数字系统设计作业

使用特权

评论回复
地板
linux达人| | 2010-12-21 21:03 | 只看该作者
我只是想说,很少人会仔细的把你写的程序看完在来回答你的问题。

使用特权

评论回复
5
linux达人| | 2010-12-21 21:04 | 只看该作者
我只是想说,很少人会仔细的把你写的程序看完在来回答你的问题。还是靠自己吧,我也是个初学者,自动售货机的程序也写过。

使用特权

评论回复
6
sxhhhjicbb| | 2010-12-22 22:07 | 只看该作者
coin1,coin5: in std_logic;           --选定1,2,5毛邮票,投入1,5毛硬币
coin5是一个输入变量,只受你的测试文件更改。你的测试文件找找原因吧。

使用特权

评论回复
7
lelee007| | 2010-12-24 22:08 | 只看该作者
哈哈,别照着书上抄,那些乌七八糟的书不一定对

有些书即使本身是对的,经过验证的,排版的时候出小问题,也可能导致代码无法直接使用

所以,还是问题自己思考,代码自己垒

使用特权

评论回复
8
xiexiajing| | 2014-6-28 18:18 | 只看该作者
我的毕业设计是关于兑钱的,想来参照的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

1

帖子

1

粉丝