Jump to content
PLC Forum


P.I. SCL per STEP7


walterword
 Share

Recommended Posts

walterword

questo è un file che ho scritto per regolare temperature 

Si tratta di un regolatore P.I. con uscita anche pwm. 

 

FUNCTION_BLOCK FB80           // Digital regulator P.I.D. Written by Walter P.  05/06/2009

VAR_INPUT
Set_Point:REAL ;               // Set point value 
Feedback:REAL ;                // Feedback value process 
Kp:REAL;                       // K Proportional gain 
Ki:REAL;                       // K Integral gain 
Max_Analog:REAL;               // Maximum value for analog output 
Max_Time_Cycle:REAL;           // Maximum time cycle for PWM digital output (milliseconds)
Scan_Time:REAL;                // Scanning time of the plc 
Time_Sample:REAL;              // Time sample in OB35
Enable:BOOL;                   // Enable PWM digital P.I.D.
Reset:BOOL;                    // Reset regulator 

END_VAR

LABEL
salto;
end_label    
    
VAR_IN_OUT

END_VAR

VAR_OUTPUT
Out_Analog_Reg:REAL ;           // Output analog regulation 
Duty_Cycle_Perc:REAL;           // Duty cycle On percentage
Wave_On_PWM:BOOL;               // Output high wave On of digital PWM 
Wave_Off_PWM:BOOL;              // Output low wave On of digital PWM 


END_VAR

VAR_TEMP
  
END_VAR

VAR
    
Error:REAL ;                   // Error for each scan 
I_Ist:REAL;                    // Istant
I:REAL ;                       // Integral memory 
P:REAL;                        // Proportional component 
Accu_Timer:REAL;               // Timer Accumulator for the duty cycle PWM 
Thr_Wave_On:REAL;              // Threshold for the wave ON
Thr_Wave_Off:REAL;              // Threshold for the wave OFF
Wave_On:BOOL;                  // Wave On  
Wave_Off:BOOL;                 // Wave Off  
  
END_VAR
 
 
 
             BEGIN  
             
              Error:=Set_Point - Feedback ;
              
              P:=Error * Kp * 1000.0 ;
              
              I_Ist:=Error * Ki;
              
              I:=I + I_Ist ;
              
              IF I <= 0.0 THEN  I:=0.0; END_IF;
              
              IF I >= Max_Analog*0.8 THEN I:=Max_Analog*0.8; END_IF ;
              
              IF Enable=true THEN 
                  Out_Analog_Reg:=P + I ;
              END_IF;
              
              IF Reset THEN 
                 
                 P:=0.0;
                 I:=0.0;
                 I_Ist:=0.0;
                 Out_Analog_Reg:=0.0;
                 Wave_On:=false;
                 Wave_Off:=false;
                 Accu_Timer:=0.0;

                 
              END_IF;             
                  
              IF Out_Analog_Reg >= Max_Analog THEN  Out_Analog_Reg:=Max_Analog;END_IF;    IF Out_Analog_Reg <= 0.0 THEN  Out_Analog_Reg:=0.0; END_IF;
              
              
              
              // STATE OF ENDED MACHINE TO GENERATE THE WAVE SQUARED ON AND OFF OF THE PWM 

 
               Thr_Wave_On:= (Max_Time_Cycle / Max_Analog) *  Out_Analog_Reg;   
               
               Thr_Wave_Off:=Max_Analog - Thr_Wave_On;
                    
              
              IF  Accu_Timer=0.0 AND Enable THEN 
              
                 Wave_On:=true;
                 Wave_Off:=false;
              
              END_IF;
            
              
              IF Wave_On=true THEN 
                
                        Accu_Timer:=Accu_Timer +  Time_Sample;
                        Duty_Cycle_Perc:=(Thr_Wave_On / Max_Time_Cycle) * 100.0;
                        
                        IF Accu_Timer >= Thr_Wave_On THEN 
                            
                            Wave_On:=false;
                            Wave_Off:=true;

                        END_IF;    
                
              END_IF;  
            
            
             IF Wave_Off=true THEN 
                
                         Accu_Timer:=Accu_Timer +  Time_Sample;
         
                        IF Accu_Timer >= Max_Time_Cycle THEN 
                            
                            Wave_Off:=false;
                            Accu_Timer:=0.0;
                            GOTO salto ;
                        END_IF;    
                
              END_IF;  


              
                           
              salto:  
              
              Wave_On_PWM:= Wave_On AND Thr_Wave_On>= 1000.0;
              Wave_Off_PWM:=Wave_Off ;
                          
                 
  ;
END_FUNCTION_BLOCK

 

Link to comment
Share on other sites


walterword

in kop si potrebbe anche fare , non ci sono tipi di dati bytes , non ci sono caratteri etc .

Però non ha senso 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...