I've used analogRead() and suspect it is keeping analog circuitry powered, even after I've gone into deep sleep mode. What command can I use just prior to sleep to power off any on-chip analog circuitry?
Thanks
Scott
I've used analogRead() and suspect it is keeping analog circuitry powered, even after I've gone into deep sleep mode. What command can I use just prior to sleep to power off any on-chip analog circuitry?
Thanks
Scott
According to the ATmega168 datasheet...
23.8.2 ADCSRA – ADC Control and Status Register A
Bit 7 – ADEN: ADC Enable
Writing this bit to one enables the ADC. By writing it to zero, the ADC is turned off. Turning the
ADC off while a conversion is in progress, will terminate this conversion.
So this should shut off the converter...
ADCSRA &= ~(1<<ADEN);
You may have to turn it back on when the Arduino wakes up.
Thanks, I'll check the 328P spec sheet and see if the same bit is used in the same register. Seeing the technique for flipping bits in registers just by naming them like that is helpful to know. Very handy. I can do anything now!
Cheers
Scott
Aha! Found the following in init() section of code in wiring.c, the comments say init() is called before setup().
Anyways:
// enable a2d conversions
sbi(ADCSRA, ADEN);
So, this means in my application I'm going to do as you say:
ADCSRA &= ~(1<<ADEN);
Or, probably cbi(ADCSRA, ADEN) because it looks cleaner.
And reading the low power section of the 328P specsheet, there is a power register I'm going to explicitly de-power the ADC before sleep using what it suggests. And also disable brownout, that sucks resting power too. And make sure internal voltage reference is off.... lot's of advice there.
Then upon waking up, sbi(ADCSRA, ADEN),
and re-power or do whatever else is needed.
Be cool if Arduino took care of this housing keeping when a specific sleep mode is called. I can always wish for 0018 or 19.. or whatever
For those thinking beyond the Arduino, (moving to AVRgcc)...
It is a shame that what "looks" nicer was eventually considered "unclean" or not quite "C" by the developers of AVRgcc.
Support for "cbi(ADCSRA, ADEN)" was eventually removed from standard AVRgcc so you and now you only get these by adding deprecated include files.
As far as I understood they were removed for a reason - they are deprecated. Currently avr-gcc generates the most optimal code, depending upon where is your byte stored - in registers or memory. So, for example if the variable you are changing is located in a register between 0x0 and 0x20 and you are manipulating a single bit then the compiler will use sbi, cbi opcode and this will execute in a single cycle.
More on the topic in this tutorial:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=37871&postdays=0&postorder=asc&start=20