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.
PID Temperature Control
Moderator: Benj
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: PID Temperature Control
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
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
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: PID Temperature Control
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
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
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: PID Temperature Control
Hello,
This might help.
https://www.matrixtsl.com/wikiv7/index. ... ve_Control
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.
Yes they willnot sure if the DSP functions will work on a PIC18F47K40
This might help.
https://www.matrixtsl.com/wikiv7/index. ... ve_Control
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.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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: PID Temperature Control
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
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