Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

[VHDL]Distributore di bibite

Strumenti informatici per la matematica applicata, le simulazioni, il disegno: Mathcad, Matlab, Scilab, Microcap, PSpice, AutoCad ...

Moderatori: Foto Utenteg.schgor, Foto Utentedimaios

0
voti

[1] [VHDL]Distributore di bibite

Messaggioda Foto UtenteMifert4 » 28 nov 2011, 20:34

devo descrivere e simulare una macchina a stati finiti che prevede l'inserimento di monete da 10,20 e 50 cent per acquistare una lattina del costo di 50 cent.Devo gestire oltre all'uscita della lattina anche il resto.
Ecco il mio codice:
Codice: Seleziona tutto
entity MSFresto is
    Port ( monete : in  STD_LOGIC_VECTOR (2 downto 0);
           clk : in  STD_LOGIC;
           reset : in  STD_LOGIC;
         resto : out  STD_LOGIC_vector(2 downto 0);
           lattina : out  STD_LOGIC);
end MSFresto;

architecture behavioral of MSFresto is
type stato is (s0,s10,s20,s30,s40,s50,s60,s70,s80,s90); 
signal SC, SF : stato;

begin

process(clk,reset)
begin
   if reset='1' then SC<=s0;
   elsif clk'event and clk='1' then SC<=SF;
   else null;
   end if;   
end process;

process(SC)
begin
   case SC is
      when s0  => lattina<='0',
                 => resto<='000';                                  
      when s10 => lattina<='0',
             =>   resto<='000';       
      when s20 => lattina<='0',
               =>   resto<='000';
      when s30 => lattina<='0',
              =>   resto<='000';   
      when s40 => lattina<='0',
               => resto<='000';
      when s50 => lattina<='1',
               =>   resto<='000';
        when s60 => lattina<='1',
               => resto<='001';
      when s70 => lattina<='1',
             =>   resto<='010';   
      when s80 => lattina<='1',
             =>   resto<='011';
      when s90 => lattina<='1',
             =>   resto<='100';
       when others => null;
      end case;
end process;

process(SC, monete)
begin
   case SC is
      when s0  => if    monete="000" then SF<=S0;
               elsif monete="001" then SF<=s10;
               elsif monete="010" then SF<=s20;
               elsif monete="100" then SF<=s50;
               else null;
               end if;            
                                 
      when s10 => if    monete="000" then SF<=S10;
               elsif monete="001" then SF<=s20;
               elsif monete="010" then SF<=s30;
               elsif monete="100" then SF<=s60;
               else null;
               end if;
      
      when s20 => if    monete="000" then SF<=S20;
               elsif monete="001" then SF<=s30;
               elsif monete="010" then SF<=s40;
               elsif monete="100" then SF<=s70;
               else null;
               end if;
                               
      when s30 => if    monete="000" then SF<=S30;
               elsif monete="001" then SF<=s40;
               elsif monete="010" then SF<=s50;
               elsif monete="100" then SF<=s80;
               else null;
               end if;
                               
      when s40 => if    monete="000" then SF<=S40;
               elsif monete="001" then SF<=s50;
               elsif monete="010" then SF<=s60;
               elsif monete="100" then SF<=s90;
               else null;
               end if;               
               
      when s50 => if    monete="000" then SF<=s0;
               elsif monete="001" then SF<=s10;
               elsif monete="010" then SF<=s20;
               elsif monete="100" then SF<=s50;
               else null;
               end if;
               
      when s60 => if    monete="000" then SF<=s0;
               elsif monete="001" then SF<=s10;
               elsif monete="010" then SF<=s20;
               elsif monete="100" then SF<=s50;
               else null;
               end if;
                               
      when s70 => if    monete="000" then SF<=S0;
                   elsif monete="001" then SF<=s10;
               elsif monete="010" then SF<=s20;
               elsif monete="100" then SF<=s50;
               else null;
               end if;
                               
      when s80 => if    monete="000" then SF<=S0;
               elsif monete="001" then SF<=s10;
               elsif monete="010" then SF<=s20;
               elsif monete="100" then SF<=s50;
               else null;
               end if;               
               
      when s90 => if    monete="000" then SF<=s0;
               elsif monete="001" then SF<=s10;
               elsif monete="010" then SF<=s20;
               elsif monete="100" then SF<=s50;
               else null;
               end if;
      when others => null;
      end case;
end process;
end behavioral;


non posto anche il test bench perché dovrebbe essere certamente corretto.
In questa parte invece il ghdl mi rileva degli errori:

Codice: Seleziona tutto
MSFresto.vhdl:30:18: unexpected token '=>' in a primary
MSFresto.vhdl:30:18: ';' is expected instead of '=>'
/usr/lib/ghdl/bin/ghdl: compilation error
error: cannot find entity or configuration msfresto
/usr/lib/ghdl/bin/ghdl: compilation error
error: cannot find entity or configuration tb_msfresto
/usr/lib/ghdl/bin/ghdl: compilation error
/usr/lib/ghdl/bin/ghdl: file 'tb_msfresto' does not exists
/usr/lib/ghdl/bin/ghdl: Please elaborate your design.

GTKWave Analyzer v3.3.24 (w)1999-2011 BSI

Error opening  .vcd file 'out.vcd'.
Mi aiutate a risolvere? :D
Avatar utente
Foto UtenteMifert4
0 3
 
Messaggi: 34
Iscritto il: 28 nov 2011, 20:28

0
voti

[2] Re: [VHDL]Distributore di bibite

Messaggioda Foto UtenteMifert4 » 28 nov 2011, 21:02

Ah,una cosa che non mi è mai stata chiara: quando usare le virgolette o i singoli apici
es:che differenza c'è tra
Codice: Seleziona tutto
x<='01'
e
Codice: Seleziona tutto
x<="01"
?
Avatar utente
Foto UtenteMifert4
0 3
 
Messaggi: 34
Iscritto il: 28 nov 2011, 20:28

0
voti

[3] Re: [VHDL]Distributore di bibite

Messaggioda Foto Utenterini » 7 dic 2011, 3:01

usa il singolo apice quando hai un solo bit, usa le virgolette quando hai un bit_vector.

Esempio
Codice: Seleziona tutto
x1 <= '1';
x2 <= "1001";
rini - \existslectroYou
Avatar utente
Foto Utenterini
1.420 2 5 13
Master EY
Master EY
 
Messaggi: 461
Iscritto il: 17 dic 2007, 1:04
Località: Bologna \ Salento


Torna a Programmi applicativi: simulatori, CAD ed altro

Chi c’è in linea

Visitano il forum: Nessuno e 6 ospiti