Page 1 of 1
PID Temperature Control
Posted: Thu Jul 02, 2020 9:13 am
by jollybv
Hi Guys
I'm trying to make a PID controller but am a bit lost I have made a test program using a PID example I found on the net with no luck I'm not sure where to insert the changing temperature that will then change the duty cycle of the PWM can someone please explain what I need to do.
Re: PID Temperature Control
Posted: Thu Jul 02, 2020 9:50 am
by QMESAR
Hi
Flowcode has Control Functions as Components go to DSP tab and use them search the wiki and you will find examples of using the PID contol components
Re: PID Temperature Control
Posted: Thu Jul 02, 2020 1:24 pm
by jollybv
Hi Qmesar
Thanks for the reply my only problem is that I am not using a DsPIC so not sure if the DSP functions will work on a PIC18F47K40
Re: PID Temperature Control
Posted: Thu Jul 02, 2020 6:27 pm
by Benj
Hello,
not sure if the DSP functions will work on a PIC18F47K40
Yes they will
This might help.
https://www.matrixtsl.com/wikiv7/index. ... ve_Control
where to insert the changing temperature that will then change the duty cycle of the PWM can someone please explain what I need to do.
With PID it's good to get everything on the same scale. So you have the input from your setpoint, the temperature you want. You have the input from your feedback, the temperature at the moment. And you have the control signal output, the PWM duty to your heater. If the PWM duty can go from 0 to 255 then it's often nice to scale your temperatures so that the working range is from 0 to 255.
Lets take an example say you want to control the heat between 0 degrees and 50 degrees and your PWM duty to vary between 0 and 250. You might format your values like this.
if (temperature < 0)
scaledtemp = 0
else if (temperature > 50)
scaledtemp = 250
else
scaledtemp = temperature * 5
This then helps to get everything into a single unit. A byte might be too restrictive so you might want say 0-1023 instead to use with the 10-bit PWM.
Or you base everything on the temperature values and then scale the output to be a PWM duty but this might be too restrictive on an integer based system. Hope this makes sense?
Let us know how you're getting on.
Re: PID Temperature Control
Posted: Fri Jul 03, 2020 8:47 am
by jollybv
Hi Ben
Thanks for the reply I'm getting somewhere the problem I'm having is the PWM output I have tried implementing the Scaledtemp but don't seem to know what I'm doing. Say I want to have a maximum temperature if 125 and temperature is 0 then the pwm must be 255 and when it gets closer to the 125 it should start backing off
if (temperature < 0)
scaledtemp (control) = 0
else if (temperature > 120)
scaledtemp (control) = 255
else
scaledtemp (control) = temperature * 5
What i see here is theat if temperature is 0 then 5 * 0 is 0 so the system will never start the PWM or maybe im not seeing something