ATTiny84 low current meter
Sometimes I want a nice cup of tea. At times it seems that the universe is not so keen on the idea - the tea needs replenishment, the milk is finished, there are no cups until the dishwasher is finished it's cycle, the lightbulb in the pantry is out so I can't see where the new tea is located - you get the idea, and we've all had days like that.
I recently also had an idea that it would be nice to accurately measure low currents so that I could experiment with the ATTiny13 and the PFS154 head-to-head by testing current draw while sleeping or collecting solar rays, etc.,.
My usual Cheap As Chips™ digital multimeters would unlikely be accurate at the levels predicted and I cannot afford a µA or nA meter. So I was chuffed to see David Johnson-Davies on the Technoblogy site whip up a simple low current meter using the ATTiny84's ADC inputs. As I was reading the blog I realised that I was out of tea AND cups needed a "regulated 5V power supply" (PSU) for accuracy.
I'm not sure that my cheap PSU or any other alternatives on the bench were going to cut it, but before committing to designing/building a lab PSU, I will whip up David's nano current meter just for proof of concept. The next few blogs and videos might contain a smattering of PSU stuff as well!
In the meantime I figured that an HT73XX LDO voltage regulator (either 5V or 3.3V) would probably provide a stable enough output to at least test David's circuit.
Before any comparisons between microcontrollers occurs, I firstly used the ATTiny13 in various modes to test the low current meter.
With the "bare sketch" and galloping along at 9.6MHz the meter measured "Hi", which is to say that it overshot the limits of it's measuring ability (Current > 10µA).
Even the "bare sketch" ambling at a mere 128kHz was still too high, but things got a bit more interesting when the ATTiny13 was compelled to sleep, firstly with the Analog Comparator, Analog to Digital Converter, Watchdog Timer and Brownout Detector all on, and then all off.
#include <avr/sleep.h> // the sleep routines
void powerDown(void) {
//disable watchdog if enabled
wdt_reset(); // turn off Watchdog Timer
MCUSR = 0;
WDTCR |= _BV(WDCE) | _BV(WDE);
WDTCR = 0;
ADCSRA &= ~(1 << ADEN); // turn off ADC
ACSR |= (1 << ACD); // turn off Analog comparator.
cli(); // Disable BOD
BODCR = (1 << BODSE) | (1 << BODS);
BODCR = (1 << BODS);
sei(); // enable global interrupts
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep deeply little one
sleep_enable(); // enable sleep mode
sleep_cpu();
sleep_disable(); // ISR routine returns here so wake up
ADCSRA |= (1 << ADEN); // turn on ADC
ACSR = (0 << ACD); // turn on Analog comparator.
delay(50); // settle time after waking up
}
void setup ()
{
DDRB = 0b00000000; // all pins inputs
PORTB = 0b00111111; // and internal pullups
}
void loop () {
powerDown(); // call the function that sleeps
}
After measuring the actual voltage output of the HT7350 and HT7333 (4.98V and 3.21V respectively) I coded the measured voltages as well as the "1uF" capacitor (which was measured at 964.2nF) as shown below.
The ATTiny84 was programmed with David's code using an Arduino as ISP.
Then the chip was put into the circuit as per David's diagram (but not anywhere near David's neatness!).
Here are the results: