Page 1 of 1

Esercizio vhdl

PostPosted: 25 Jan 2020, 09:07
by Sabato
Buongiorno, premetto che sono nuovo di questo linguaggio e non capisco ancora bene molte cose.
Vi spiego il mio problema. Dovrei svolgere un esercizio in cui devo programmare il sistema di entrata/uscita di un parcheggio. Ci sono due fotocellule(entrata/uscita) due sbarre che si alzano per regolare il passaggio (entrata/uscita) e un pulsante che deve essere premuto nel momento in cui qualcuno voglia entrare. Se qualcuno vuole entrare, la sbarra rimane alzata per massimo 15 colpi di clk. All'uscita invece rimane alzata finché la macchina non esce.
Io ho creato i miei stati, e quando faccio il testbench, però, la macchina non rispetta alcuni passaggi di stato, però non so proprio dove io possa aver sbagliato, vorrei un aiuto se possibile, grazie.

Code: Select all
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity controllore_modulo is
    Port ( clk : in  STD_LOGIC;
           rst : in  STD_LOGIC;
           puls : in  STD_LOGIC;
           fot_a : in  STD_LOGIC;
           fot_b : in  STD_LOGIC;
           sbar_a : out  STD_LOGIC;
           sbar_b : out  STD_LOGIC;
           sem : out  STD_LOGIC);
end controllore_modulo;
architecture Behavioral of controllore_modulo is
   type state is (s0, s1, s2, s3, s4, s5, s6);
  signal present_state,next_state: state;
   signal count, new_count: integer range 0 to 15; -- Contatori in interi dei cicli di clock
   signal time_over: std_logic := '0' ; -- Segnale tempo scaduto
begin
  --Processo sequenziale che regola il passaggio di stato e aggiorna, di conseguenza, il contatore
   synchronous_process: process (clk, rst, fot_a, fot_b, time_over, present_state)
begin
  if rising_edge(clk) then
           if (rst='1') then
              present_state<=s0;
              count<=0;
           else
             if((present_state = s0)) then
                  if((puls='1')and(fot_a='1')and (fot_b='0')) then
                        present_state <= next_state;
                  end if;
             elsif(present_state = s2) then
                  if((puls='1')and(fot_a='1')and (fot_b='0')) then
                     present_state<=next_state;
                  elsif(((puls='0')and(fot_a='0')and (fot_b='1')) or ((puls='0')and(fot_a='1')and (fot_b='1')) ) then
                     present_state<=next_state;
                  end if;
             elsif(present_state = s1) then
                  if(((puls='0')and(fot_a='1')and (fot_b='0')and(time_over='1')) or ((puls='1')and(fot_a='1')and (fot_b='0')and(time_over='1'))) then
                      present_state <= next_state;
                  elsif((puls='0')and(fot_a='0')and(fot_b='0')and(time_over='0')) then
                      present_state <= next_state;
                      count <= new_count;
                  end if;
            elsif(present_state = s3) then
                  if(((puls='0')and(fot_a='1')and (fot_b='0')and(time_over='1')) or ((puls='1')and(fot_a='1')and (fot_b='0')and(time_over='1'))) then
                      present_state <= next_state;
                  elsif(((puls='0')and(fot_a='0')and(fot_b='0')and(time_over='0')) or ((puls='1')and(fot_a='0')and(fot_b='0')and(time_over='0'))) then
                      present_state <= next_state;
                      count <= new_count;
                  end if;
            elsif(present_state = s4) then            
                  if(((puls='0')and(fot_a='0')and(fot_b='1')) or ((puls='1')and(fot_a='1')and(fot_b='1')) or ((puls='0')and(fot_a='1')and(fot_b='1')) or ((puls='1')and(fot_a='0')and(fot_b='1'))) then
                      present_state<= next_state;
                  end if;
            elsif(present_state = s5) then
                 if(((puls='0')and(fot_a='0')and(fot_b='0')) or ((puls='0')and(fot_a='1')and(fot_b='0'))) then
                      present_state<=next_state;
                 end if;
            elsif(present_state = s6) then   
                 if(((puls='0')and(fot_a='0')and(fot_b='0')) or ((puls='0')and(fot_a='1')and(fot_b='0'))) then   
                      present_state<=next_state;
                 end if;
           end if;
       end if;
end if;      
    end process;

  -- Transizione degli stati   
  state_process: process (present_state,puls,fot_a,fot_b,time_over)
      begin
   
      case present_state is
        --Stato iniziale
         when s0=> if((puls='0') and (fot_a='0') and (fot_b='0')) then
                    next_state <= s0;
                   elsif((puls='1') and (fot_a='1') and (fot_b='0')) then
                    next_state <= s1;
                   else
                    next_state <= s0;
                   end if;
        --Stato s1
         when s1=> if((puls='-') and (fot_a='1') and (fot_b='0') and (time_over='0')) then
                    next_state<=s1;
                   elsif((puls='-') and (fot_a='1') and (fot_b='0') and (time_over='1')) then
                    next_state<=s0;
                   elsif((puls='0') and (fot_a='0') and (fot_b='0')) then
                    next_state<=s2;
                   else
                    next_state<=s0;
                   end if;
        --Stato s2
        when s2=> if((puls='0') and (fot_a='0') and (fot_b='0')) then
                    next_state <= s2;
                   elsif((puls='1') and (fot_a='1') and (fot_b='0')) then
                    next_state <= s3;
                   elsif(((puls='0')and(fot_a='0')and (fot_b='1')) or ((puls='0')and(fot_a='1')and (fot_b='1')) ) then
                    next_state <= s6;
                   else
                    next_state<= s2;
                   end if;
        --Stato s3
        when s3=> if((puls='-') and (fot_a='1') and (fot_b='0') and (time_over='0')) then
                    next_state <= s3;
                  elsif((puls='-') and (fot_a='1') and (fot_b='0') and (time_over='1')) then
                    next_state <= s2;
                  elsif((puls='-') and (fot_a='0') and (fot_b='0')) then
                    next_state <= s4;
                  else
                    next_state <= s2;
                  end if;
        --stato s4
        when s4=> if((puls='-') and (fot_a='-') and (fot_b='1')) then
                    next_state<=s5;
                  elsif((puls='-') and (fot_a='-') and (fot_b='0')) then
                    next_state<=s4;
                  end if;
         --stato s5   
         when s5=> if((puls='-') and (fot_a='-') and (fot_b='1')) then
                    next_state <= s5;
                   elsif((puls='0') and (fot_a='0') and (fot_b='0')) then
                    next_state <= s2;
                   else
                    next_state<=s5;
                   end if;
         --stato s6
         when s6=> if(((puls='0') and (fot_a='-') and (fot_b='0'))) then
                    next_state<=s0;                   
                   elsif(((puls='0') and (fot_a='-') and (fot_b='1'))) then
                    next_state<=s6;
                   end if;            
      end case;
    end process;
       --Valori dei segnali in uscita per i diversi stati (Implementazione Moore)
      output_function : process(present_state)
        begin
           case (present_state) is
              when s0 =>
               sem <= '1' ; sbar_a <= '0' ; sbar_b <= '0';               
              when s1 =>
               sem <= '1' ; sbar_a <= '1' ; sbar_b <= '0';
              when s2 =>
               sem <= '1' ; sbar_a <= '0' ; sbar_b <= '0';
              when s3 =>
               sem <= '1' ; sbar_a <= '1' ; sbar_b <= '0';
            when s4 =>
               sem <= '0' ; sbar_a <= '0' ; sbar_b <= '0';
            when s5 =>
               sem <= '0' ; sbar_a <= '0' ; sbar_b <= '1';
            when s6 =>
               sem <= '1' ; sbar_a <= '0' ; sbar_b <= '1';
           end case;
        end process;
 
 
  --Contatore dei 15 cicli di clock
   Timer:process(present_state,count)
     begin
       if (present_state=s1 or present_state=s3) then
              if (count=15) then --clock attraverso il segnale count arriva a 15
                new_count<=0;
                 time_over<='1'; --scatta il segnale di time over
              else
                 new_count<=count+1;
                time_over<='0';
              end if;
       else
           new_count <= 0;
           time_over <= '0';
         end if;
         
  end process;        
end Behavioral;

Re: Esercizio vhdl

PostPosted: 20 Mar 2020, 00:00
by Leonardo
Ciao Sabato,

Quali stati non rispetta?

A presto,
Leonardo