Proportional-Derivative controller with Picaxe 08M

Svejk

Senior Member
Recently I had the opportunity to play with PID Controllers and I managed to make a PD Controller with a Picaxe 08M. I'm sharing with the hope that it will find some use for someone.

The setup is build on a AXE021, Picaxe-08 Proto Board using minimal components. A schematic is attached as well as photo's of the setup.

It uses a DS18B20 temperature sensor to read the temperature and the output is controlled via a BC337 NPN transistor using a 500 Hz Pulse Width Modulation (PWM). Data is echoed to PC as CSV.

For testing the temperature sensor was tapped to a 12V, 5 W light bulb used as a heat source.

Enjoy.
 

Attachments

Last edited:

Janne

Senior Member
Hi Svejk,

Interesting test application you have going on in there.
I also recently played around with a bit similar application on 14M. The picaxe in my case is controlling a wood fired central heating boiler, or more precisely the air inlet (draft) on it. It tries to keep the temperature of the fumes constant, measured with a PT100-sensor. The set value is input with a potentiometer, and the actual air inlet hatch position is controlled by a stepper motor.

I also first tried to implement something similar to what you did, but soon found out I was running out of program memory.. So I had to rely just on a P-controller, with a fixed additional 'D' gain, if the error was still bigger than on the previous iteration. Even with this "crippled" system, it still is quite a nice improvement over a plain P-controller, as the PT100 has quite a long response time, almost 2 minutes.

Anyways, your code snipped is certainly most useful in picaxe's with more program memory space, 08M leaves a bit too little of program space for the actual application.
 

techElder

Well-known member
Adrian, what would it take to turn this controller "upside down" and make it a cooling controller instead of a heating controller?

Is there room left in the program for Celsius to Fahrenheit conversion?
 

Svejk

Senior Member
@Texasclodhopper:

It all depends of what are you trying to achieve. If you want to keep a constant temperature in, let say, a bar fridge so the beers will be always at 4 degrees C (~39 F)is just a mater of inverting some signs. The more power used, cooler it gets, once _under_ the set value, decrease the power. Extra code will be required for negative temperatures.

If you plan to keep cool a room during day and heat during night, then this control isn't suitable.

For C to F conversion insert

temp = temp*9/5 + 3200

after the data conversion . It should look like this:

tmp0 = temp / 16 ' whole degree
tmp1 = temp & $00F *625/100 ' the decimals
temp = tmp0 * 100 + tmp1
temp = temp*9/5 + 3200 ' C to F conversion


There are still 5 bytes free after C to F conversion.
 
Last edited:

Svejk

Senior Member
@ Janne:

Funny enough this application is a spin off from a house heating project.

Anyway it is presented as an example and I've used what I found in my Picaxe drawer, if more programming space is required then a Picaxe to suit should be used.
 

premelec

Senior Member
Thanks for posting this! I'm not very well experienced with PD control and would much appreciate some more rem comments on your code and the procedure you are implementing - I know there are discussions of integral and derivative techniques but these are not strictly applied with PICAXE 08M maths.... I'll keep your code for reference as it looks useful for various control projects.
 

techElder

Well-known member
The byte count left was very good to know. I'm sure I could implement this with a cooler rather than a heater.

Thanks for the great project!


@Texasclodhopper:

It all depends of what are you trying to achieve. If you want to keep a constant temperature in, let say, a bar fridge so the beers will be always at 4 degrees C (~39 F)is just a mater of inverting some signs. The more power used, cooler it gets, once _under_ the set value, decrease the power. Extra code will be required for negative temperatures.

If you plan to keep cool a room during day and heat during night, then this control isn't suitable.

For C to F conversion insert

temp = temp*9/5 + 3200

after the data conversion . It should look like this:

tmp0 = temp / 16 ' whole degree
tmp1 = temp & $00F *625/100 ' the decimals
temp = tmp0 * 100 + tmp1
temp = temp*9/5 + 3200 ' C to F conversion


There are still 5 bytes free after C to F conversion.
 

fernando_g

Senior Member
Svejk:
Very nice little project!
I'm always amazed a the truly useful projects that can be built using a lowly 08M. This is such an ingenious project.

Also, that little 2X8 display is really cool. It shows that one does not always require a 4X20 display to provide useful information.

Last: Why don't you move this thread to the "finished projects" section. It will be easier to find. Otherwise will be lost in the thousands of threads in this section.
 

gweep

New Member
Thanks for the great project. I was looking to do this myself with an adaptive controller but was struggling with how to handle minus signs. I'll study what you have done with interest.
Thanks
Mike
 
Top