Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PID controller for the heater

Status
Not open for further replies.

nileshthakare2

Member level 1
Joined
Jul 16, 2011
Messages
34
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,618
Hi,

I have plant value and set point value and for the PID processing i made the code
void pid_correct(unsigned int plant_value)
{
unsigned int SET_POINT,integral,prev_error;

//the plant error
//make sure error is positive when you need to apply a larger pwm value (wider positive width)
unsigned int error = plant_value - SET_POINT;
//int16_t error = ((int16_t) SET_POINT) - plant_value;

//proportional * pGain
unsigned int proportional = error * 200;

//integral * iGain
unsigned int temp_sum = integral + ( error * 10 );
//check that the integral doesn't get out of the desired range
if ( temp_sum > 0xFFFF ) integral = 0xFFFF;
else
if (temp_sum < (-0xFFFF) ) integral = -0xFFFF;
else
integral = temp_sum;

//differential * dGain
//if you used the other error calculation, use the other differential as well
unsigned int differential = ( (error - prev_error) * 20 );
//int32_t differential = ( (prev_error - error) * 20 );

//the final sum, with an overflow check
unsigned int temp_pid_sum = proportional + integral + differential;
unsigned int pid_total;
//set max pwm value at ~95% of 2^16 (change this to whatever you like)
if ( temp_pid_sum > 62258 ) pid_total = 62258;
else
if ( temp_pid_sum < 0 ) pid_total = 0;
else
pid_total = (unsigned int) temp_pid_sum;

//set pwm compare value to change the duty cycle
OCR1A = pid_total;

//store the previous error
prev_error = error;
}
This is taken from the example code. In this code the OCR1A control the pwm of the controller .my question is
how OCR1A = pid_total;control the pwm because pid_total is the difference between set point and plant value.Also how we interface the code with main due to that continue sly get correct output
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top