Issue in PID control formula & assigning output to 16 bit timer PWM

Go To Last Post
2 posts / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1. Writing PID control for temperature control. Took kp,ki,kd values from Delta Electronics PID which calculates from Autotune.


2. Below is code. Is below code ok for PID?

float previous_err_4 =0;
float integral_4 = 0;
float error_4;
float dt_4 = 1;
float derivative_4;
float output_4;
float kp=30.6f,ki=354.0f,kd=88;

void pid_fxc_4(void)
	error_4 = Setpoint_Temp - temperature;
	integral_4 = integral_4 + (error_4 * dt_4);
	derivative_4 = (error_4 - previous_err_4)/dt_4;
	output_4 = (kp * error_4) + (ki * integral_4) + (-kd * derivative_4);
	previous_err_4 =  error_4;
	TIMER_16_PWM = output_4;  // put into timer 16 bit PWM register


3. Issue is I am getting very random output_4 values.  There is no decrease in output values when temperature comes close to set point.


4.Also how to map output values to 16bit pwm values which in turn control the ssr to turn heater on/off

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your PID params seem way out of whack to me, start with kp=1 and the rest at zero.


Test your plant and see how it reacts, add to kp gain to get the temperature rise time you desire,  then add a small amount of ki (like ki=0.1 or more)  to close the offset as needed with in a reasonable time frame, and observe the new reaction.  Once that is working, add kd to remove any over shoot if necessary to optimize the output. 


Take a look at this for an example of PID in action:





(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"


Last Edited: Thu. Dec 5, 2019 - 02:14 PM