0

I'm very new to VHDL and for my digital design project I have to make a simulation of a washing machine in a DE10-Lite FPGA with finite states.

Everything seems good so far but when it's turn for the impure function Wash to work, it looks like signal sec is not summing up one, and therefore never leaves the state.

Any idea on how to correct this?

This is the full code. Impure Wash function is declared in the second process and signal sec is part of the architecture variables.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;
  
entity WM is --Wash

    port (  
        p,m,s,w,r,d,c,t: in std_logic; --power,mode,start,wash,rinse,dry,clock,tank
        pl,ml,wl,rl,dl,motor: out std_logic --powerLed,modeLed,washLed,rinseLed,dryLed,motor
            );
                
end WM;

architecture bhv of WM is

    signal sec: integer:= 0;
    signal e: boolean := false;
    
    type t_state is (off,autoL,autoP,manualL);
    signal state : t_state;
    
    begin
    
        process(p,m,w,r,d,s)
        
        begin
        
        if p = '0' then
        
            state <= off; --off
                        
        else
                        
            if m = '1' then
            
                state <= autoL; --auto
                
                if s = '1' then
                    state <= autoP; 
                else
                    state <= autoL;
                end if;
                        
            else
                
                state <= manualL; --manual
                
            end if;
        
        end if;
            
        end process;    
        
        process(state,c,t,e,sec)
        
        impure function WashFill(Seconds : integer:= 0) return boolean is
        begin
        
        if t = '1' then
            return true;
            
        else
            if c = '1' then
                wl <= '0';
            else
                wl <= '1';
            end if;
            
            return false;
        end if; 
        
        end function;
        
        impure function Wash(Seconds : integer:= 0) return boolean is
        begin
        
            if c = '1' then
              sec <= sec + 1;
         else
              sec <= sec;
         end if;

         if sec = 5 then
              sec <= 0;
              motor <= '0';
              return true;
         else
              motor <= '1';
              wl <= '1';
              return false;
         end if;  
        
        end function;   
        
        
        impure function WashDrain(Seconds : integer:= 0) return boolean is
        begin
        
        if t = '0' then
            return true;
            
        else
            if c = '1' then
                wl <= '0';
            else
                wl <= '1';
            end if;
            
            return false;
        end if; 
        
        end function;   
        
        begin
        
            case state is
                
                when off =>
                
                    pl <= '0';
                    ml <= '0';
                    wl <= '0';
                    rl <= '0';
                    dl <= '0';
                    motor <= '0';
                            
                when autoL =>
                
                    pl <= '1';
                    ml <= '1';
                    wl <= '1';
                    rl <= '1';
                    dl <= '1';
                    motor <= '0';
                    
                when autoP =>
                
                    if WashFill(Seconds => 5) then
                        if Wash(Seconds => 5) then
                            if WashDrain(Seconds => 5) then
                                end if;
                        end if;
                    end if; 
                    
                when manualL =>
                
                    pl <= '1';
                    ml <= '0';
                    wl <= '0';
                    rl <= '0';
                    dl <= '0';
                    motor <= '0';
                
                --when others =>
                    --motor <='1';
                    
            end case;
        
        end process;
    
    end bhv;
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Adolf RJ
  • 19
  • 2
  • 3
    How are you testing this? Do you have a testbench? Can you see what is going on in simulation? counters etc generally do not work without a clock. Your functions all take a `Seconds` parameter that is not used within the functions. I recommend not using `impure functions` (or even pure functions) until you understand the basics of digital logic and VHDL fundamentals. I recommend removing the functions and doing the code directly in the process. – Tricky Jun 26 '23 at 18:54
  • Make sure you understand the different semantics of variable and signal assignments. This code reads as if you might not have grasped postponed assignment and delta cycles. This may help a little : https://stackoverflow.com/questions/13954193/is-process-in-vhdl-reentrant/13956532#13956532 And as Tricky says, write a testbench and take a deep look inside, in simulation. –  Jun 27 '23 at 10:33
  • See IEEE Std 1076-2008 11.3 Process statement and 10.2 Wait statement on how to construct a process sensitivity list. Note an assignment sensitive to a signal level with feedback and an increment or decrement will produce a gated oscillator because of inversion. Counters and state registers should be assigned on clock edges to match post synthesis behavior. Provide a [mcve] here implying a testbench and a specific issue instead of the observation the sec counter isn't counting. – user16145658 Jun 28 '23 at 21:45

0 Answers0