Difference between revisions of "Temperature control"

From BitWizard WIKI
Jump to: navigation, search
(Created page with "= intro = I wanted to demonstrate that temperature control using three of our boards would be easy. I will replicate this experiemnt at home to make a "sous vide" setup short...")
 
(Putting the hardware together)
Line 6: Line 6:
  
 
I took my ftdi_atmega
 
I took my ftdi_atmega
 +
[[File:tempcontroller_01_ftdi_atmega.jpg|200px|thumb|left|FTDI ATMEGA PCB]]
 +
 +
* and used a standard 6 pin SPI cable to connect it to my spi_temp board.
 +
[[File:tempcontroller_02_spi_temp.jpg|200px|thumb|left|spi_temp board]]
 +
 +
The spi cable was then daisychained to the next board:
 +
[[File:tempcontroller_03_spi_relay.jpg|200px|thumb|left|spi_relay board]]
 +
 +
The Relay was hooked up to an extension cord. This way the relay would control the power to the extension cord.
 +
[[File:tempcontroller_04_relay_and_extensioncord.jpg|200px|thumb|left|spi_relay and the extension cord]]
 +
 +
Next I hooked up the coffee pot to the extension cord.
 +
[[File:tempcontroller_05_coffee_pot.jpg|200px|thumb|left|coffee machine]]
 +
 +
and I extended the LM35 sensor (and waterproofed it). I put the sensor in the water in the coffee pot.
 +
 +
= writing the software =
 +
 +
I took the spi_atmega demo application, and modified it to add temperature control. This was really easy:
 +
<code>  if (wanted_temp && tchanged) {
 +
    long t0;
 +
    unsigned char heater;
 +
    static unsigned char curheater = -1;
 +
 +
    t0 = SPI_getu16 (SPI_TEMP, 0x28);
 +
    //pputs ("t0 = ");hexshort (t0);
 +
    t0 = (t0 * 1000/11) >> 16;
 +
    // pputs (" t0 = ");hexshort (t0);
 +
 +
    heater = (t0 < wanted_temp);
 +
 +
    pputs (" t0 = ");hexshort (t0);
 +
    pputs (" wt = ");hexbyte (wanted_temp);
 +
    pputs (" heat = ");hexbyte (heater);
 +
    pputs (".\n\r");
 +
    if (curheater != heater) {
 +
      spi_setreg_u8 (SPI_RELAY, 0x20, heater);
 +
      curheater = heater;
 +
      pputs ("Turned heater ");
 +
      if (heater) pputs ("on");
 +
      else        pputs ("off");
 +
      pputs ("\r\n");
 +
    }
 +
  }
 +
</code>
 +
This gets executed every second (because of the tchanged), It gets the temperature reading, converts it to centigrade and then compares it with the wanted temperature. In the mean time it logs some variables for debugging.
 +
 +
This is very simple on-off control. This, it turns out is not ideal with the slow response of the coffee machine. The temperature overshoots the intended temperature by quite a lot. This can be fixed by using a proper PID control algorithm. With a different heater setup this would not be necessary.

Revision as of 16:59, 22 March 2012

intro

I wanted to demonstrate that temperature control using three of our boards would be easy. I will replicate this experiemnt at home to make a "sous vide" setup shortly.

Putting the hardware together

I took my ftdi_atmega

FTDI ATMEGA PCB
  • and used a standard 6 pin SPI cable to connect it to my spi_temp board.
spi_temp board

The spi cable was then daisychained to the next board:

spi_relay board

The Relay was hooked up to an extension cord. This way the relay would control the power to the extension cord.

spi_relay and the extension cord

Next I hooked up the coffee pot to the extension cord.

coffee machine

and I extended the LM35 sensor (and waterproofed it). I put the sensor in the water in the coffee pot.

writing the software

I took the spi_atmega demo application, and modified it to add temperature control. This was really easy: if (wanted_temp && tchanged) {

   long t0;
   unsigned char heater;
   static unsigned char curheater = -1;
   t0 = SPI_getu16 (SPI_TEMP, 0x28);
   //pputs ("t0 = ");hexshort (t0);
   t0 = (t0 * 1000/11) >> 16;
   // pputs (" t0 = ");hexshort (t0);
   heater = (t0 < wanted_temp);
   pputs (" t0 = ");hexshort (t0);
   pputs (" wt = ");hexbyte (wanted_temp);
   pputs (" heat = ");hexbyte (heater);
   pputs (".\n\r");
   if (curheater != heater) {
     spi_setreg_u8 (SPI_RELAY, 0x20, heater);
     curheater = heater;
     pputs ("Turned heater ");
     if (heater) pputs ("on");
     else        pputs ("off");
     pputs ("\r\n");
   }
 }

This gets executed every second (because of the tchanged), It gets the temperature reading, converts it to centigrade and then compares it with the wanted temperature. In the mean time it logs some variables for debugging.

This is very simple on-off control. This, it turns out is not ideal with the slow response of the coffee machine. The temperature overshoots the intended temperature by quite a lot. This can be fixed by using a proper PID control algorithm. With a different heater setup this would not be necessary.