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

Thread Starter

Vindhyachal Takniki

Joined Nov 3, 2014
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