VHDL State Machine One Hot

One Hot
Ist ein VHDL-Endcoding-BEgriff und bezieht sich auf die Umsetzung der Zustände in Hardware.
Bei One Hot wird für jeden Zustand s ein weiteres Bit gebraucht wird bzw. ein neues FF eingebaut.

s1 = 0001    -> 4 Flip-Flop
s2 = 0010
s3 = 0100
s4 = 1000

Der Vorteil von One Hot ist, dass sich die Input-Logik (das Decodieren der Zustände) vereinfacht. Man muss nur 1 Bit kontrollieren.

Minimal Bit Endocding
Ist der Gegenbegriff. Die Zustände werden mit möglichst wenigen Bits in VHDL umgesetzt.

s1 = 00    -> 2 Flip-Flop
s2 = 01
s3 = 10
s4 = 11

Einstellen in quartus
Menu Settings/ Analyse & Synthese/   Klicken auf Feld: More Settings:
Scrollen  bis zum Betriff  State Machine Processing:
Dort unter diversen Optionen One-Hot oder minimal-Bit auswählen

State Machine VHDL

states bitweise definieren

constant s0         : std_logic_vector(2 downto 0) := "000";
constant s1         : std_logic_vector(2 downto 0) := "100";
constant s2         : std_logic_vector(2 downto 0) := "110";
constant s3         : std_logic_vector(2 downto 0) := "011";
constant s4         : std_logic_vector(2 downto 0) := "001";
constant s5         : std_logic_vector(2 downto 0) := "111";

signal state :        std_logic_vector(2 downto 0);
signal next_state:    std_logic_vector(2 downto 0);

states als type

type actual_state is (s0, s1, s2, s3, s4, s5, s6, s7);
        
signal state:          actual_state  := s0;  
signal next_state:     actual_state  ;


Enumeriter Type

type actual_state is (s0, s1, s2, s3);

attribute enum_encoding : string;
attribute enum_encoding of actual_state: type is "00 01 10 11";  

// nicht sicher:     
signal state:          actual_state  := s0;  
signal next_state:     actual_state  ;


State-Zuweisung

fsm: process (all)
    begin
        if (KEY_1 = '0') then
            state <= s0;
        elsif (rising_edge(CLOCK_27)) then
          state <= next_state;
        end if;
    end process;


Logik Events

fsm_input: process (all)        
begin     
    case state is
       when s0 =>
          if(pulse ='1') then
            next_state <= s1;
          else
            next_state <= s0;
          end if;           
       when s1 =>    
          if(pulse ='1') then
             if SW_17 = '1' the
                next_state <= s2;  
             else
                next_state <= s0;
             end if;
          else
             next_state <= s1;
          end if;
       when s2 =>   next_state <= s3;
       when s3 =>   next_state <= s4;
       when s4 =>   next_state <= s5;
       when s5 =>   next_state <= s6;
       when s6 =>   next_state <= s7
       when s7 =>   next_state <= s7;    
    end case;        
 end process;

Output Action

fsm_output: process (all)
begin   
    case state is
            when s0 =>   out     <= "001"; 
            when s1 =>   out     <= "011"; GPIO_0_0 <= '1';
            when s2 =>   LEDR_2  <= '1';
            when s3 =>   LEDR_3  <= '1';
   
            when OTHERS =>   NULL;
      end case;
end process;

 

 

 

Variable <-> Signale in VHDL

Variable
Leben nur innerhalb eines Prozesses.
– Ihr Zustand kann nicht gespeichert werden.
– Sie müssen im Prozess, vor dem begin definiert werden
Zuweisung erfolgt sofort (asynchron)
– Wird die Variable auch ausserhalb des Prozesses gebraucht, wird sie einem Signal zugewiesen.

read_file: process(all)	
	
variable token_note: std_logic_vector(7 downto 0) :=(OTHERS => '0');
variable token_velocity: std_logic_vector(7 downto 0) :=(OTHERS => '0');
	
begin
       // token einlesen (muss variable sein)
      read(line_in, token_type_n, good);

      // variable signal übergeben
      s_token_type <= token_type;


Signale
Verbinden Blöcke miteinander und/oder werden innerhalb Block gebraucht
– Sie werden ausserhalb von Prozessen definiert
– Ihr Wert kann in einem FF gespeichert werden (muss aber nicht)

architecture rtl of counter is

signal s_token_typ std_logic_vector(7 downto 0) := (others => '0'); 

begin 

execute_file: process (all) 
begin

end

..