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;