Attiny824 1.5uA Thermostat Demo

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Hi, I am sending this Demo only for fun or inspiration or discussion. It is side product of some small project.
target: Application which can measure temperature, turn heater (MOSFET) on and off at preprogramed temperatures twice per second with the lowest possible current consumption to be able run year(s) from battery.
Used MCU is Attiny824. Its power consuptions are insufficiently characterised (only preliminary datasheet). Temperature sensor is low cost MCP9701. Power supply 3.3V, but can be between 2.1V (limited by MOSFET threshold and sensor temperature range) to 5V (limited by MCU absolute max.rating) or higher if used voltage regulator (which rising consumption). Current consumption between 1.28uA to 1.57uA was estimated by two methods (averaging hundred ~10Hz ammeter readings or "known capacitor drop over time" method).

outline:
RTC running from internal 32kHz and waking up core when "compare" event to power on sensors (need about 1.5ms to stabilize its output)
RTC sending overflow event to trigger AD conversion
ADC conversion result wakes up MCU to read out and process results

Schematic
Schematic diagram

Program

 

// "Micropower" thermostat, PB3 output to heater, PB1 power supply for temperature sensor, PA1 sensor output, measure 2x per second
// Temperature sensor MCP9701
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>

void init_pit(void);
void unuse_pins(void);
void init_rtc(void);
void init_adc(void);
void process_temperature(void);
#define SENSOR_ON PORTB.OUTSET = PIN1_bm
#define SENSOR_OFF PORTB.OUTCLR = PIN1_bm
#define HEAT_ON  PORTB.OUTSET = PIN3_bm
#define HEAT_OFF PORTB.OUTCLR = PIN3_bm
volatile uint8_t phase=0; // state machine variable
uint16_t adc_val;

#define VREF_VAL 2.048 // ADC voltage reference value
#define HIGH_THR 33  // Heater OFF temperature [°C]. Must be smaller then 83°C (for wider range, select 2.5V reference) 
#define RELEASE_THR 31  // Heater ON temperature [°C]

// calculations from selected temperature to ADC raw thresholds (4x oversampling)
#define H_THR_VAL ((HIGH_THR*0.0195)+0.4)/VREF_VAL*(4096*4)
#define L_THR_VAL ((RELEASE_THR*0.0195)+0.4)/VREF_VAL*(4096*4)

int main(void){
 _PROTECTED_WRITE(CLKCTRL.MCLKCTRLB,CLKCTRL_PDIV_10X_gc | CLKCTRL_PEN_bm); // 2MHz clock
 unuse_pins(); // deactivate all unused GPIOs
 init_rtc();  // Run RTC
 init_adc();  // Config and enable ADC
 BOD.CTRLA = 0; // Disable BOD
 set_sleep_mode(SLEEP_MODE_STANDBY);  // Select STANDBY mode 
 sleep_enable(); 
 sei(); // Enable interrupts
 PORTB.DIRSET = PIN1_bm; // Sensor power supply pin
 PORTB.DIRSET = PIN3_bm; // Heater control pin

 while (1){
  if(phase == 1){ // time to enable sensor power supply
   phase = 0;
   SENSOR_ON; 
  }
  if(phase == 2){ // AD conversion result ready
   phase = 0;
   SENSOR_OFF;  // turn off sensro power supply
   adc_val=ADC0.RESULT; // read out conversion result
   process_temperature(); // ... and process it
  }
  sleep_cpu(); // sleep
 }
}

void process_temperature(void){
 if(adc_val > H_THR_VAL){ // if temperature is grater then threshold
  HEAT_OFF; 
 }
 else if(adc_val < L_THR_VAL){ // if temperature is lower then threshold
  HEAT_ON; // zapnout topení
 }
}

void init_adc(void){
 ADC0.CTRLB = ADC_PRESC_DIV2_gc; // clock 1MHz for ADC
 ADC0.CTRLC = 2<<ADC_TIMEBASE_gp | ADC_REFSEL_2048MV_gc; // timebase 2 ticks, reference internal 2.048V
 ADC0.CTRLE = 3; // sampling time 3.5us
 ADC0.CTRLF = ADC_SAMPNUM_ACC4_gc; // accumulate 4 results
 ADC0.MUXPOS = ADC_MUXPOS_AIN1_gc; // signal from AIN1 (PA1) - sensor output
 ADC0.INTCTRL = ADC_RESRDY_bm; // Enable interrupt from conversion complete
 ADC0.CTRLA = ADC_RUNSTDBY_bm | ADC_ENABLE_bm; // enable ADC and enable ADC run in sleep
 ADC0.COMMAND = ADC_MODE_BURST_gc | ADC_START_EVENT_TRIGGER_gc; // conversion of all 4 samples started by single event
}

// ADC interrupt routine
ISR(ADC0_RESRDY_vect){
 ADC0.INTFLAGS = ADC_RESRDY_bm; // clear flag
 phase = 2; // signal to main function
}

// přerušení od RTC
ISR(RTC_CNT_vect){
  RTC.INTFLAGS = RTC_CMP_bm; // clear compare flag
  phase = 1; //// signal to main function
}

void init_rtc(void){
 RTC.CLKSEL = RTC_CLKSEL_INT32K_gc; // clock source internal ~32kHz oscilator
 RTC.INTCTRL = RTC_CMP_bm; // enable compare event interrupt
 RTC.PER = 1999; // period 1/(32k/8/2000) = 0.5s
 RTC.CMP = 1994; // compare event 6 ticks before overflow (time to enable sensor power supply)
 RTC.CTRLA = RTC_PRESCALER_DIV8_gc | RTC_RTCEN_bm | RTC_RUNSTDBY_bm; // RTC clock 32k/8=4kHz, enable run in sleep mode, enable RTC
 while(RTC.STATUS){} // wait until config written in regs
 EVSYS.CHANNEL0 = EVSYS_CHANNEL0_RTC_OVF_gc; // send overflow event into event system (channel0)
 EVSYS.USERADC0START = EVSYS_USER_CHANNEL0_gc; // Event routed into ADC (as trigger)
}

// Disable input buffer in all pins
void unuse_pins(void){
 PORTA.DIR = 0;
 PORTB.DIR = 0;
 PORTA.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc; 
 PORTA.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc;
 PORTA.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;
 PORTA.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc;
 PORTA.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc;
 PORTA.PIN5CTRL = PORT_ISC_INPUT_DISABLE_gc;
 PORTA.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc;
 PORTA.PIN7CTRL = PORT_ISC_INPUT_DISABLE_gc;
 PORTB.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
 PORTB.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc;
 PORTB.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;
 PORTB.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc; 
}

 

  • Measurment period can be simple changed by writing into RTC.PER.
  • Sensor turn on time can be adjusted by RTC.CMP.
  • Range is up to 83°C with selected 2.048V reference (sensor output about 2.04V at that temperature) and can be simple extende by selecting 2.5V reference.
  • EVOUTA can be used to adjusting sample time.
  • some guru can use CCL to generate sensor power supply signal autonomously (without waking up CPU)
  • EVOUTB does not work :/ (do not controll output in any case, PORTMUX configured right)
     

oscillogram - temperature sensor stabilisation time
Yellow signal - sensor power supply 
Magenta signal - Sensor output
 

 Photo

Have a nice day,
Michal Dudka

Last Edited: Thu. Jun 23, 2022 - 07:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 Application which can measure temperature, turn heater (MOSFET) on and off at preprogramed temperatures twice per second with the lowest possible current consumption to be able run year(s) from battery.

 

That makes almost no sense...the heater will probably take 1000000 times as much power as the AVR, why are you concerned about shutting it off (unless perhaps the heater never actually runs).  How much energy will the heater burn up in 30 seconds of heating?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
How much energy will the heater burn up in 30 seconds of heating?

Perhaps OP has designed a micro-power heater also.

 

BTW: @OP; Did you forget to ask your actual question. I couldn't find it ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In my case the heater is solar panel connected into resistive load which voltage vary from 0 to 200V depending on sunlight intensity. Its voltage cant be simply used as supply voltage for regulator. There are cases when voltage is too low to reliably open MOSFET and there is potential risk that MOSFET will be overpowered in linear region. In case that app recognize that undervoltage situation and disable MOSFET it can leads to oscillations. Open MOSFET, detect undervoltage, close MOSFET, detect enought voltage, open MOSFET...

May be, the heater isn't right model otput... i should have choosen some neutral output like "inidication" etc... 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BTW: @OP; Did you forget to ask your actual question. I couldn't find it ?

I have no question. I wanted to share this as "template" which could be useful to someone in similar application. 

Last Edited: Thu. Jun 23, 2022 - 09:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In my case the heater is solar panel connected into resistive load which voltage vary from 0 to 200V depending on sunlight intensity. Its voltage cant be simply used as supply voltage for regulator. There are cases when voltage is too low to reliably open MOSFET and there is potential risk that MOSFET will be overpowered in linear region. In case that app recognize that undervoltage situation and disable MOSFET it can leads to oscillations. Open MOSFET, detect undervoltage, close MOSFET, detect enought voltage, open MOSFET...

Ok, that makes a somewhat more sense:

The solar panel with resistor is forming a heater, controlled by an AVR thermostat

The worry is that at low light, the loaded heater voltage will fall so much as to make the voltage unusable for the AVR (even with regulator), resulting in sshutoff

At lower lighting, when the heater is turned off the voltage will rise back up, potentially oscillating in the on/off manner.

 

Note the cycling might be ok (no harm) since it is waking up and determining it does need heating. It can try and let the voltage fall down if there is not enough light.

There are mosfet driver chips that will prevent driving the fet only while sufficient gate voltage is  available.

FAN3100 fet driver chip (example):

Internal circuitry provides an under−voltage lockout function by holding the output LOW until the supply voltage is within the operating range.   

 

There are also fets that will turn off if they get too hot .

 

 

 

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

 

Note the cycling might be ok (no harm) since it is waking up and determining it does need heating. It can try and let the voltage fall down if there is not enough light.

There are mosfet driver chips that will prevent driving the fet only while sufficient gate voltage is  available.

 

You are right. Cycling due undervoltage should not be a problem. Cycled power will be negligible, low cycle rate, low current and voltages. System will loose few wats of power which could be delivered into heater. I will consider adding HV regulator as secondary power source for termostat (simply mixed by diodes with battery power source). But "battery only" powering has an dvantage that switch can be connected at any place in circuit (not even in low side, but also in high side). I rejected useing FET driver due significant queiscent current. 

Now i am finding best solution how to turn on and turn off high voltage MOSFET (gate drive ~9V) from MCU by circuit with minimal queiscent current. Simple solution is few Megaohm pullup resistor connected on FET gate and use second FET to pull its gate low to close main FET. Like at following schematic:
simple FET driver schematic

But turn-on time will be really slow, because of time constat of FET gate capacity and large pullup resistor. That can lead to MOSFET overheating by switching losses (crossing linear region takes too long). I am looking for some simple trick how to speed that up without adding so much static consumption. I focus on some simple "single shot" charge pump which can speed up overcoming critical gate voltages. Ideas are welcomed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One meg is prob a good ways too high, due to all the leakage currents, especially under hot conditions.

 

Note this arrangement has a flaw---when the batt drains Q1 may be off (fine), but pulled up Vgs2, may still be enough (low enough) to cause Q2 to get into partial on. 

If the AVR is in reset, the heater will generally be on (bad).

Also Q1 would likely need a pullup, so at low voltages (the AVR off), the Q1 gate isn't flailing around..it barely need to crack on with the weak R1 pullup...

 

You might well find a decent HV logic level fet,for 5V operation, though higher gate voltage is indeed ideal.

You can run the diode/cap charge pump to double the gate voltage, but it will take some power.

Maybe when off ,the batt can by trickled charged using a very high ohm resistor.

If this is a 200V circuit, you should consider the circuit (and any switches to the AVR) as potentially "hot", unless you provide isolation (one option is a double insulated switch), as well as proper creepage and clearance.

 

You'd likely have an easier time running off your 200V supply with a 12V zener to make micropower 12V for the gate (use a driver with lowvolt lockout) and take down the 12V with another 5V zener for the AVR.

 

Note also good old CMOS metal gate CDxxxx gates can run up to 15V and will drive the gate on and off with virtually zero current consumption when its output is steady hi/lo.  This is FAR better than a 1 megohm.  In fact, even though ancient it remains some of the lowest static current part families ever.  Such parts can run direct off a battery for much longer than the battery can last sitting in a drawer (though current goes way up with temp).

 

You might also arrange the heater to never be 100% on (say duty 99.9%)...during the off time, the controller section could grab enough charge in a cap from solar to operate for the next (or several) on cycles.  Or the ADC could monitor the AVR supply and if too low shut off the heater for a spit to get another gulp of power in its caps..that might last quite awhile until another gulp is needed.

 

Could you just use a metal set of thermostat contacts? (closed until temperature reached)...then no "circuit" is needed.   solar panel/onoff sw/thermostat contacts/heater

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

That's low! (@25C)  CD4001

Also, we used some of this family as cheap high freq amplifiers (for the era), but that is another story...in fact there is a whole app/databook for these in linear usages (I beleiv e it was the unbuffered parts).

I have the linear book somewherz.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Jun 24, 2022 - 08:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Temperature sensor is low cost MCP9701

I would check out the internal temp sensor. I have a tiny3217, along with another mcu within 2 feet that is getting temp from a TMP117 and an Si7051. All are within 1 degree F, so the tiny3217 is doing pretty good compared to the 'accurate' ones.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

curtvm wrote:
I would check out the internal temp sensor.

Temp Sensor may (and probably should be) remote. However this particular sensor is no more accurate than a bog-standard silicon diode.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

One meg is prob a good ways too high, due to all the leakage currents, especially under hot conditions.


Working temperature for regulator will be under 35°C. Relevant is leakage from gate to source, but these values are negligible. But leakage in Q1 can be problem. I've measured values for 2N7000, and it looks ok at 26°C. But i can choose better one.

avrcandies wrote:

Note this arrangement has a flaw---when the batt drains Q1 may be off (fine), but pulled up Vgs2, may still be enough (low enough) to cause Q2 to get into partial on. 


I am aware of that flaw. AVR should measure battery voltage. In undervoltage condition AVR should hold Q1 on (and Q2) off "forever". AVR should work down to 1.8V (+ 0.1 voltage regulator drop). Voltages under about 2V can't open selected Q2 even partialy. But one must carefuly selecting Q2 with that in mind.

avrcandies wrote:

If the AVR is in reset, the heater will generally be on (bad).

Also Q1 would likely need a pullup, so at low voltages (the AVR off), the Q1 gate isn't flailing around..it barely need to crack on with the weak R1 pullup...


Yes. Q1 gate pullup needed.

avrcandies wrote:

You might well find a decent HV logic level fet,for 5V operation, though higher gate voltage is indeed ideal.


I did not search thoroughly, i didn't even hope that i can find ~200V MOSFET with low Rdson and 3.3V "threshold" voltage. Now i have  IXFA72N20X3 on a table.

avrcandies wrote:

You can run the diode/cap charge pump to double the gate voltage, but it will take some power.


I have to test it. But i hope that it can be build with negligible consuption. I've tested that routing periodic signal from PIT to EVOUTA and it has no impact at consumption (under 0.1uA difference).

avrcandies wrote:

If this is a 200V circuit, you should consider the circuit (and any switches to the AVR) as potentially "hot", unless you provide isolation (one option is a double insulated switch), as well as proper creepage and clearance.


Whole 200V system is floating, but thermostat will be protected against touch.

avrcandies wrote:

You'd likely have an easier time running off your 200V supply with a 12V zener to make micropower 12V for the gate (use a driver with lowvolt lockout) and take down the 12V with another 5V zener for the AVR.


I have LR8 linear regulator for these purposses. But battery is neede because high voltage can easy become few volts if loaded.

avrcandies wrote:

Note also good old CMOS metal gate CDxxxx gates can run up to 15V and will drive the gate on and off with virtually zero current


That is great idea. I definitely search for some levelshifter. It sound like best solution !

avrcandies wrote:

You might also arrange the heater to never be 100% on (say duty 99.9%)...during the off time, the controller section could grab enough charge in a cap from solar to operate for the next (or several) on cycles.  


I will consider that mode.

avrcandies wrote:

Could you just use a metal set of thermostat contacts? (closed until temperature reached)...then no "circuit" is needed.   solar panel/onoff sw/thermostat contacts/heater


Heater have its own "bimetal" thermostat contats. But there is high risk of electric arc when shitching off, which can bake contacts together.

Thank you for your notes. 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

IXFA72N20X3 

 

You should use a TO-220 fet if you are dealing with high power . Even at 25 amps you would need to bolt onto a heatsink.  With care, a circuit board is good for a couple watts of heat, but really not a lot compared to even a small heatsink.

 

But battery is neede because high voltage can easy become few volts if loaded.

Make it so that at low solar voltages (say less than Vin=30V) the fet cannot come on using a lockout driver & vmon.  No battery is needed.

The battery solves nothing, since then you have to worry about the battery getting weak.  Instead of solving for the bat getting weak, solve for the Vsolar getting low.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Jun 24, 2022 - 05:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sry for typo, i have TO-220 variant. Maximum current in my case is between 8-9 Amps, with 0.025Ohm FET have to dissipate less then 2W, small heatsink will manage it.

I plan to use battery to solve following problem:
Voltage of solar panel under weak light conditions is almost the same like under full sunlight (it is current source). But voltage of loaded solar panel depends directly on its current (solar iradiance) and load resistance. Regulator is not able reliably estimate voltage under load from open source voltage. Regulator have to connect load to determine real value of "voltage under load". A to do this, it needs to run from some secondary power source (for example capacitor). This strategy leads to periodic load unconnecting to charge regulators power storage (strategy you suggested).

That strategy can be best solution. Load resistance is about 25Ohm in my case.  If open source voltages are lower then about 10V, and are not able to deliver sufficient voltage to regulators storage then load can be definitely disconected without any power losses. Because solar panel with that low open voltage will not be able deliver neither single watt of power.

Unconected load in sunlight condition wasting energy. Regulator have to "recharge" storage capacitor as rarely as possible. That also leads to minimazing power consuption, but not that strictly like 9V battery. Next question is charging circuit... but that can simple handle LR8 voltage regulator (for the price about 0.5mA cunsumption from solar panel - in extreme case of 200V about 0.1W).

Thanks for your comments.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That IC looks like ideal "low power" MOSFET driver:

RE46C100 

or that variant with integrated 3.3V regulator
RE46C108

What do you think ?