PID based thermostat built using the Flash Destroyer module

Explore the limits of solid state storage. Get a kit for $30, including worldwide shipping.

PID based thermostat built using the Flash Destroyer module

Postby jeanmarc78 » Mon Dec 30, 2013 5:15 pm

Hello,

After trying a few commercial thermostats for my central heating (hot water), i was not really satisfied. They don't provide a smooth regulation.
Then i decided to build my own one reusing my flash destroyer hardware board.

It has the following features :
- PID based regulation
- PWM with a 5mn period cycle to drive the on/off gas boiler
- Up to 8 temperature sensors (DS18B20 or DS18S20) on a 1wire bus
- Auto detection, at power up time, of all the sensors and sorting them according to their internal Id
- Per sensor, compute mean temp value on 8 successive samples (each is 10 bits) then providing an enhanced measurement
- Select the lowest temp among all sensors and use it as "measured temp" for the regulation
- Setup values are stored in the pic eeprom
- Displays temp of each sensor in °C (round robin)
- Displays the percentage of time the heater is on in a PWM cycle
- Displays via a blinking dot when heater is on ("on" period of the PWM cycle)
- Direct change of temp setting via 2 push buttons (- and +)
- Access to a simple menu to change some settings (P, I and D coeff, luminosity of the display) by pressing simultaneously both buttons

Some very limited modifications of the DP Flash Destroyer board are needed :
- Remove the eeprom
- Pin 6 of the eeprom support is used for the 1wire bus
- Pin 5 of the eeprom support is used for the + button (other side to ground)
- Existing button connection is used for - button. An external one can be put in parallel if you need to group + and - in a more convenient location
- Pin 17 of the PIC18f2550 is used to control the boiler (was not used on Flash Destroyer)

My boiler is controlled directly via the AC mains then i have used a solid state relay, driven via a simple npn transistor plus 2 resistors.

Other types of interface can easily be buit, for example with a mechanical relay or with a power mosfet depending of the load you want to drive.

Some pics of the thermostat :
Thermostat_1.jpg

Thermostat_2.jpg


The firmware, after the initializations, enters a main infinite loop in which all "tasks" are sequentially activated when needed. Most of them rely on their own timer, implemented as a counter, which is decremented via the timer interrupt until it reachs zero.

The display is driven directly from the timer interrupt which ensure the digits multiplexing. The on state duration of each digit is adjusted (a given number of timer interrupt ticks) to allow to drive the luminosity according to the value set by the user (or to the default one).

For the PID, the P_coeff and the D_coeff are used as a multiplier. The I_coeff is used as a divider as the integral is based on the sum of the previous samples.

Thermostat_FlashDest_X_RF_v5-.production.hex.zip
The firmware
(12.45 KiB) Downloaded 424 times


Your Flash Destroyer was probably sleeping in your drawer since many months. You can give it a new long life :)

Best regards
JM
jeanmarc78
Newbie
Newbie
 
Posts: 21
Joined: Sat Jul 09, 2011 10:42 am

Re: PID based thermostat built using the Flash Destroyer mod

Postby matseng » Mon Dec 30, 2013 10:24 pm

Very nice reuse of the FlashDestroyer!

I have basically zero experience of PID systems - how hard is it to trim the parameters to get a good regulation? With a 5 minute cycle time and a very sluggish response in the system severe over and undershoots can't be easy to trim away...
User avatar
matseng
Hero Member
Hero Member
 
Posts: 876
Joined: Sat Oct 15, 2011 12:29 pm
Location: Kuala Lumpur, Malaysia

Re: PID based thermostat built using the Flash Destroyer mod

Postby jeanmarc78 » Tue Dec 31, 2013 4:03 am

Thanks for your appreciation matseng.

In fact i have choosen arbitrary the values for PID coefficients. And they have provided an efficient regulation. The room radiators have now a quite constant temperature and no longer a succession of cold and warm periods as it was with a simple thermostat.
It is probably possible to improve the response by tuning the PID coeffs.

In fact my first attemp, before deciding to implement a PID, had been to build a simple thermostat on which i was able to set a small hysteresis and the result was still not as good as i expected.
Then i decided to implement the PID. and i am very happy with the result.

I have installed one in my home and an other one in my father's house 2 years ago and we are both happy with it.
jeanmarc78
Newbie
Newbie
 
Posts: 21
Joined: Sat Jul 09, 2011 10:42 am

Re: PID based thermostat built using the Flash Destroyer mod

Postby jeanmarc78 » Sat Feb 01, 2014 4:29 pm

Hello,

The following schematic describes the wiring that must be added to the Flash Destroyer to use it as a PID based thermostat

Thermostat PID2.jpg

For the output to drive the boiler or the heater, 2 possibilities are described, the first one with a static relay which is ok for an AC load, the second one with a mechanical relay which can drive any type of load.
The base resistor is 2.7kOhms (as the dot is not very visible on the schema).

The power supply is a standard AC adapter able to provide more than 7v (for example 9v) and a current greater than 500mA.
It can be put close to the boiler and the DC power is provided via the wire to the Flash Destroyer.
I have used an old cat5 network cable between the boiler and the thermostat and have used 1 pair of wires to send DC power from the boiler to the thermostat and an other pair to drive the solid state relay.

JM
jeanmarc78
Newbie
Newbie
 
Posts: 21
Joined: Sat Jul 09, 2011 10:42 am

Re: PID based thermostat built using the Flash Destroyer mod

Postby jeanmarc78 » Sun Jul 13, 2014 5:11 am

An interesting tutorial about PID which includes the description of a simple method to tune the P, I and D parameters :

http://newton.ex.ac.uk/teaching/CDHW/Feedback/
jeanmarc78
Newbie
Newbie
 
Posts: 21
Joined: Sat Jul 09, 2011 10:42 am


Return to Flash_Destroyer EEPROM tester