PID Digitsl controller

This conference allows discussion on any subject not already covered in another PICmicro conference. If a topic becomes popular enough, a new conference will be created for it.

PID Digitsl controller

Postby ABlincon » Fri Nov 08, 2019 1:08 pm

Hello friends, I am creating a digital PID controller. The values ​​of Kp and Ki had already been calculated mathematically. It does the PID but, the system should stabilize in approximately 2.04s, and this does it in 3 approx. (attached Proteus image) .If I modify the value of Kp or Ki, the system does the same, there is no change and I do not understand why. If anyone could help me with this please. I also get a warning message on proteus. Attached code and images. I would appreciate your help.


#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;

}
}
Attachments
2.png
Warning proteus
2.png (104.05 KiB) Viewed 2234 times
1.png
Proteus response
1.png (117.78 KiB) Viewed 2234 times
ABlincon
 
Posts: 1
Joined: Fri Nov 08, 2019 6:08 am

Re: PID Digitsl controller

Postby Roche » Sat Nov 09, 2019 1:33 pm

I may be being stupid, but it looks to me like a 1000uF cap charging through a 650ish R resistor.
Roche
 
Posts: 72
Joined: Fri Jul 11, 2014 12:35 pm
PIC experience: Professional 5+ years with MCHP products


Return to Other PICmicro topics

Who is online

Users browsing this forum: No registered users and 12 guests

cron