Hola amigos, estoy creando un controlador digital PID. Los valores de Kp y Ki ya habían sido calculados matemáticamente.
Hace el PID pero, el sistema se debería estabilizar en 2.04s aproximadamente, y este lo hace en 3 aprox. (adjunto imagen proteus).
Si modifico el valor de Kp o de Ki, el sistema hace lo mismo, no hay ningún cambio y no entiendo por qué.
Si alguien pudiera ayudarme con esto por favor.
También me sale un mensaje de advertencia en proteus.
Adjunto código e imágenes. Les agradecería su ayuda.
Hace el PID pero, el sistema se debería estabilizar en 2.04s aproximadamente, y este lo hace en 3 aprox. (adjunto imagen proteus).
Si modifico el valor de Kp o de Ki, el sistema hace lo mismo, no hay ningún cambio y no entiendo por qué.
Si alguien pudiera ayudarme con esto por favor.
También me sale un mensaje de advertencia en proteus.
Adjunto código e imágenes. Les agradecería su ayuda.
Código:
#include <18F4550.h>
#device ADC=10
#use DELAY(internal=4MHZ)
#fuses XT,NOWDT
int16 PID_output;
float Ap=0, Ai=0; //Variables, floating of 32 bits
float max=255,min=0.0; //anti-windup
float Rs, Ys,e; //Variables of PID
float value;
float Us; //Float variables
int8 range; // Magnitude of control action.
float e0;
//PID control
void PID_control() {
float Ki;
float Kp=2.066;
float Ti=0.1597;
Ki= Kp/Ti;
Ap = e*Kp; //Kp, Ki calculation according to algoritm
Ai = e*Ki+e0;
Us = Ap+Ai; //Control action calculation m(kT)
if( Us>max ) { //Anti windup.
Us=value;
}
else {
if(Us<min){
Us=value;
}
}
PID_output = ((int16)(Us));
if(PID_output>255.0) PID_output = 255.0; //Limiting control action to 255
range = (int)PID_output; //Changing float to an 8 bits int
}
#INT_TIMER2
void main() {
setup_port_a(ALL_ANALOG); //All port A pines analog
//set_tris_a(0b00111111); //Port A as input
setup_adc(ADC_CLOCK_INTERNAL); //Allow A/D converter with internal clock
setup_timer_2(T2_DIV_BY_16, 255,1);
setup_ccp1(CCP_PWM); //Configure CCP1 module with PWM
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_4MHZ|OSC_INTRC);
while(TRUE) {
set_adc_channel(1);
delay_us(10);
value=READ_ADC(); //read value of reference
Rs=(value)*5/1023.0;
set_adc_channel(0);
delay_us(10);
value=READ_ADC(); ////read value variable measured
Ys=(value)*5/1023.0;
e=Ys-Rs; //Error calculation
PID_control(); //Calling PID function
set_pwm1_duty(range);//PWM according to the magnitude of the calculated control action
e0=Ai;
}
}