View previous topic :: View next topic |
Author |
Message |
cebersp
Joined: 29 Jun 2008 Posts: 3
|
Posted: Tue Apr 26, 2011 10:54 am Post subject: Autotuning PID Controller in Basic for Temperatur Control |
|
|
Autotuning PID Controller in Basic for Temperatur Control
I did not find any source code for an autotuning PID- Controller, so this might be perhaps of some interest for others...
To control a heating, PI or PID controllers are well suitable. The question is how to find good parameters for the PI or PID controller. The finding of parameters is called tuning. There is a method "Ziegler-Nichols" for manual tuning, which was automated using a "Relay-Tuning-Method". These methods and their descriptions can be found in the internet. (http://www.scribd.com/doc/38545855/atv) So this is nothing new here. Of course the method can only be applied, if there is no danger coming from the cycling!
Actually you use two controllers. A simple relay- controller first and then the PID controller.
The relay controller switches on the heating, when the temperature is too low and switches it off, when the temperature is too high. This will give some temperature cycling with an amplitude and a cycle time. These two values are recorded and are the base for the calculation of the parameters. So after a few cycles for stabilisation you can calculate the parameters and switch to the PID- controller.
The keys of the Relay Method are two findings:
• The cycle time is equal to the "ultimate Time" Tu of the Ziegler- Nichols method.
• The "ultimate gain" can be calculated Ku= 4h/(3.14*A). h is the output amplitude of the relay controller (+/- 50 percent in our case) and A is the measured amplitude of the temperature in our case.
The implementation in Bascom:
• Uses floating point maths
• uses a very simple multi-tasking system: A "scheduler" timer interrupt routine will count down a number for each task. The task will start, when the number is zero and it will reset its number to a starting value.
• Output to serial LCD from Parallax and to a serial terminal.
• Input from 4 key switches from a resistor ladder to an analogue input
• Pwmtask is a pulse width output depending from the variable pwmval. (0...100pc)
• Relaytask is the Relay-Controller with measurement of cycle time "Deltaz" and amplitude and calculation of the parameters.
• Infotask prints actual state of the controllers.
• Tasttask reads the keys.
• Pidtask is the PID-Controller.
o The input is averaged from 10 measurements
o Both the integral part ("anti- windup") and the end result are limited
o The differential part is filtered. This seems to be necessary, because long cycle times give high Kd-parameter values which result in high outputs just from single bit differences. The resolution of the ADC should be very much higher.
• The setup was tested with an arduino board and a "process", which consists of 3 resistor-capacitor combinations in series (100k and 47µF each)
Have fun, Christof
P.S. If you could use this, it would be interesting to post your feedback here. |
|
Back to top |
|
|
PaulC
Joined: 09 Jan 2008 Posts: 122 Location: Ireland
|
Posted: Tue Apr 26, 2011 8:32 pm Post subject: Excellenjt cebersp |
|
|
Excellenjt cebersp
This should be a very interesting read.
All helps in the learning process
Thank you _________________ Bascom Avr 2.0.7.3
Works for me
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5914 Location: Holland
|
Posted: Tue Apr 26, 2011 8:36 pm Post subject: |
|
|
Thanks for sharing. This method is new to me. _________________ Mark |
|
Back to top |
|
|
Ross_ValuSoft
Joined: 20 Nov 2005 Posts: 275 Location: Melbourne, Australia
|
Posted: Wed Apr 27, 2011 4:08 am Post subject: |
|
|
Hello Christof,
Thanks also from me for your contribution.
It is not clear to me how you have connected your circuitry to an Arduino. Could you provide a drawing please?
Thanks,
Ross |
|
Back to top |
|
|
maxneo
Joined: 07 Sep 2010 Posts: 35
|
Posted: Fri Apr 29, 2011 3:35 pm Post subject: drawing |
|
|
Looks really interesting but I would like to see the drawing.
Best regards, Janne |
|
Back to top |
|
|
cebersp
Joined: 29 Jun 2008 Posts: 3
|
Posted: Sat Apr 30, 2011 8:10 pm Post subject: |
|
|
.... a "process", which consists of 3 resistor-capacitor combinations in series (100k and 47µF each):
This means, that each of the capacitors has one side tied to GND. The first resistor comes from the output of the atmega to the first C, the second is situated between the first and the second C and the third is situated between the second and the third C. So you have got 3 low pass filters in series. The input of the atmega comes from the last C.
Best regards Christof |
|
Back to top |
|
|
Ross_ValuSoft
Joined: 20 Nov 2005 Posts: 275 Location: Melbourne, Australia
|
Posted: Sun May 01, 2011 5:34 am Post subject: |
|
|
Sorry Christof ... still not clear enough to try it.
Are you testing by connecting D.2 to the input of the 3 low pass filters? And using a 4 bit resistor DAC to connect to ADC0 to "program" the required process result?
In real life, does D.2 drive a relay connecting power to a heater module (for example). And the heater module includes its own temperature sensor linear voltage output which you connect directly to ADC4?
Still trying to understand it. Do you have a link to your Arduino results?
Thanks,
Ross |
|
Back to top |
|
|
Ross_ValuSoft
Joined: 20 Nov 2005 Posts: 275 Location: Melbourne, Australia
|
Posted: Sat May 07, 2011 7:10 am Post subject: |
|
|
Christof? Are you there? |
|
Back to top |
|
|
|