2 u014582332 u014582332 于 2014.04.07 11:47 提问

VHDL程序,出错代号10821

这是我自己编写的一个关于自动售货机的程序,网上说我的时钟有问题,但是我试了很多次没改成功,求各位高手帮帮我。
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.std_logic_unsigned.ALL;
ENTITY Vending_machine IS
port( clk1,clk:in std_logic;
coin_10,coin_5,coin_1:in std_logic;
a,b,g,buy,coin,confirm,cancel:in std_logic;
out_goods,give_charge:out std_logic;
sum_in,sum_out: buffer std_logic_vector(3 downto 0);
Z:out std_logic_vector(7 downto 0));
END Vending_machine;
ARCHITECTURE behav OF Vending_machine IS
signal slip:std_logic_vector(2 downto 0);
signal state:std_logic_vector(2 downto 0);
begin
process(clk,coin,confirm,cancel,state,coin_10,coin_5,coin_1)
VARIABLE I:integer RANGE 0 TO 5;
VARIABLE sum:std_logic_vector(3 downto 0);
begin
I:=0;
state <=a&b&g;
IF clk1'event and clk1 = '1' THEN
IF state = "000" THEN
IF rising_edge(clk) THEN
slip <= slip + 1;
END IF;
CASE slip IS
when "000" => Z <= "00000001";
when "001" => Z <= "00000011";
when "010" => Z <= "00000111";
when "011" => Z <= "00001111";
when "100" => Z <= "00011111";
when "101" => Z <= "00111111";
when "110" => Z <= "01111111";
when "111" => Z <= "11111111";
END CASE;
ELSIF state = "001" AND confirm = '1' THEN
IF coin = '1' THEN
IF rising_edge(coin_1) THEN
WHILE(I < 4) LOOP
sum_in <= sum;
I:= I + 1;
sum:= sum + 1;
END LOOP;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
END IF;
END IF;
END IF;
ELSIF coin = '0' AND coin_10 = '1' THEN
sum := sum + 10;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum_in - 3;
sum_out <= sum;
END IF;
END IF;
ELSE
IF coin = '0' AND coin_5 = '1' THEN
sum := sum + 5;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum - 3;
sum_out <= sum;
END IF;
END IF;
END IF;
END IF;
ELSIF state = "010" AND confirm = '1' THEN
IF coin = '1' THEN
IF rising_edge(coin_1) THEN
WHILE(I < 4) LOOP
sum_in <= sum;
I:= I + 1;
sum:= sum + 1;
END LOOP;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
END IF;
END IF;
END IF;
ELSIF coin = '0' AND coin_10 = '1' THEN
sum := sum + 10;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum_in - 3;
sum_out <= sum;
END IF;
END IF;
ELSE
IF coin = '0' AND coin_5 = '1' THEN
sum := sum + 5;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum - 3;
sum_out <= sum;
END IF;
END IF;
END IF;
END IF;
ELSIF state = "011" AND confirm = '1' THEN
IF coin = '1' THEN
IF rising_edge(coin_1) THEN
WHILE(I < 2) LOOP
sum_in <= sum;
I:= I + 1;
sum:= sum + 1;
END LOOP;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
END IF;
END IF;
END IF;
ELSIF coin = '0' AND coin_10 = '1' THEN
sum := sum + 10;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum_in - 1;
sum_out <= sum;
END IF;
END IF;
ELSE
IF coin = '0' AND coin_5 = '1' THEN
sum := sum + 5;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum - 1;
sum_out <= sum;
END IF;
END IF;
END IF;
END IF;
ELSIF state = "100" AND confirm = '1' THEN
IF coin = '1' THEN
IF rising_edge(coin_1) THEN
WHILE(I < 5) LOOP
sum_in <= sum;
I:= I + 1;
sum:= sum + 1;
END LOOP;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
END IF;
END IF;
END IF;
ELSIF coin = '0' AND coin_10 = '1' THEN
sum := sum + 10;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum_in - 4;
sum_out <= sum;
END IF;
END IF;
ELSE
IF coin = '0' AND coin_5 = '1' THEN
sum := sum + 5;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum - 4;
sum_out <= sum;
END IF;
END IF;
END IF;
END IF;
ELSIF state = "101" AND confirm = '1' THEN
IF coin = '1' THEN
IF rising_edge(coin_1) THEN
WHILE(I < 5) LOOP
sum_in <= sum;
I:= I + 1;
sum:= sum + 1;
END LOOP;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
END IF;
END IF;
END IF;
ELSIF coin = '0' AND coin_10 = '1' THEN
sum := sum + 10;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum_in - 4;
sum_out <= sum;
END IF;
END IF;
ELSE
IF coin = '0' AND coin_5 = '1' THEN
sum := sum + 5;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum - 4;
sum_out <= sum;
END IF;
END IF;
END IF;
END IF;
ELSIF state = "110" AND confirm = '1' THEN
IF coin = '1' THEN
IF rising_edge(coin_1) THEN
WHILE(I < 4) LOOP
sum_in <= sum;
I:= I + 1;
sum:= sum + 1;
END LOOP;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
END IF;
END IF;
END IF;
ELSIF coin = '0' AND coin_10 = '1' THEN
sum := sum + 10;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum_in - 3;
sum_out <= sum;
END IF;
END IF;
ELSE
IF coin = '0' AND coin_5 = '1' THEN
sum := sum + 5;
sum_in <= sum;
IF cancel = '1' THEN
give_charge <= '1';
sum_out <= sum_in;
ELSE
IF buy = '1' THEN
out_goods <= '1';
give_charge <= '1';
sum := sum - 3;
sum_out <= sum;
END IF;
END IF;
END IF;
END IF;
ELSE
IF rising_edge(clk) THEN
slip <= slip + 1;
END IF;
CASE slip IS
when "000" => Z <= "00000001";
when "001" => Z <= "00000011";
when "010" => Z <= "00000111";
when "011" => Z <= "00001111";
when "100" => Z <= "00011111";
when "101" => Z <= "00111111";
when "110" => Z <= "01111111";
when "111" => Z <= "11111111";
END CASE;
END IF;
END IF;
END process;
END behav;

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!