Overclocked
Member
Hi, I am trying to understand how PID works by implementing it with PWM function that controls a heater. Nothing written down yet, just trying to understand it. So I have some sensor, an input variable, I think most of the time its called PV. My set temp would be SV (set variable Im assuming). So far how I want to implement it like so:
As input temp (PV) gets closer to my set temp (SV), the duty cycle of the PWM function would decrease. Consequently, if its near my set temp, the duty cycle would get close to 0. If its over, it would just not provide any pulse until my PV came down.
Difference in temp = SV-PV
Duty Cycle = Difference in temp *some gain variable
As the difference gets smaller, so does the duty cycle of the PWM function, but it seems that Im missing something. If the difference is Large then so is the duty cycle, and thus it heats up quicker. Now I guess if I were to implement this in a micro, this would happen VERY fast and would have a huge over shoot..So I would have to do this in increments of time. Lets say 250mS. I think I would add up those differences in temperature readings, average them and then make adjustments in the formula above..So now it becomes something like:
delta One = SV-PV
delta two = ...
..delta 4
Add it all up and then average it out, Then apply this formula : Duty cycle = average difference in temp * gain of some sort
There would also need to be a special case if PV is larger than SV, resulting in a negative number in software. Probably something like:
I feel like I am missing something in my understanding as to how PID controllers work.
As input temp (PV) gets closer to my set temp (SV), the duty cycle of the PWM function would decrease. Consequently, if its near my set temp, the duty cycle would get close to 0. If its over, it would just not provide any pulse until my PV came down.
Difference in temp = SV-PV
Duty Cycle = Difference in temp *some gain variable
As the difference gets smaller, so does the duty cycle of the PWM function, but it seems that Im missing something. If the difference is Large then so is the duty cycle, and thus it heats up quicker. Now I guess if I were to implement this in a micro, this would happen VERY fast and would have a huge over shoot..So I would have to do this in increments of time. Lets say 250mS. I think I would add up those differences in temperature readings, average them and then make adjustments in the formula above..So now it becomes something like:
delta One = SV-PV
delta two = ...
..delta 4
Add it all up and then average it out, Then apply this formula : Duty cycle = average difference in temp * gain of some sort
There would also need to be a special case if PV is larger than SV, resulting in a negative number in software. Probably something like:
Code:
if PV<0 then set duty cycle to 0
I feel like I am missing something in my understanding as to how PID controllers work.