- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello guys. I have a school project, that consists in making a Vending Machine with 3 products and we can only use 4 types of coins. My machine has to make change, and i don't know how to do it and i could use some help. So far i've done a FSM for the coins and a ROM with the value of the products.
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
this is my ROM code
library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.NUMERIC_STD.all; entity ROM_Venda is port(address : in std_logic_vector(1 downto 0); dataOut : out std_logic_vector(7 downto 0)); end ROM_Venda; architecture RTL of ROM_Venda is subtype TDataWord is std_logic_vector(7 downto 0); type TROM is array(0 to 3) of TDataWord; constant c_memory: TROM := (0 =>"00000000", 1 =>"01010000", 2=>"01100100", 3=> "01111000"); -- Produto 1 ->80 Produto 2 ->100 Produto 3 ->120 begin process (address) begin case address is when "00" => dataOut <= c_memory(0); when "01" => dataOut <= c_memory(1); when "10" => dataOut <= c_memory(2); when "11" => dataOut <= c_memory(3); end case; end process; end RTL;- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is a sample of my FSM code where e pretend to make te change(troco in the code)
"total" is the sum of the total of the coins library IEEE; use IEEe.STD_LOGIC_UNSIGNED.all; use IEEE.STD_LOGIC_1164.all; use IEEE.NUMERIC_STD.all; entity VendingMachine is port(sel: in std_logic_vector(1 downto 0); reset,clk,u,d,c,t: in std_logic; drink: out std_logic; total: out std_logic_vector(7 downto 0); troco: out std_logic_vector(7 downto 0)); end VendingMachine; architecture Behav of VendingMachine is type estados is(s0, s10,s20,s30,s40,s50,s60,s70,s80,s90,s100,s110,s120,s130,s140,s150,s160,s170,s180,s190,s200,s210,opnd); signal ps, ns : estados; signal s_preco : std_logic_vector ( 7 downto 0); signal s_troco: std_logic_vector(7 downto 0); begin roms: work.ROM_Venda(RTL) port map(dataOut => s_preco, address => sel); sync_proc: process(clk, reset) begin if(reset = '1') then ps <= s0; elsif(rising_edge(clk)) then ps <= ns; end if; end process; comb_proc: process(ps,u,d,c,t,ns) begin ns <= ps; case ps is when s0 => --0.00€ if u = '1' then ns <= s10; elsif d = '1' then ns <= s20; elsif c = '1' then ns <= s50; elsif t = '1' then ns <= s100; end if; total <="00000000"; when s10 => if u = '1' then ns <= s20; elsif d = '1' then ns <= s30; elsif c = '1' then ns <= s60; elsif t = '1' then ns <= s110; end if; total <="00001010"; troco <= s_preco(0) - total;- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
isn't this a duplicate of http://www.alteraforum.com/forum/showthread.php?t=52393, which you have started as well?
What's different?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem now is making change using the values in the ROM...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, what have you done? I don' see any ROM code here. And by making change I assume you mean change in coins?

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page