Incorrect code in power.h for power_adc_disable()?

Hi All,

I am new here in Arduino forum, so excuse me if the question is replicated or not in the correct place.

I am trying to make an extreme low power application (IR code transmitter) therefore I assembled a bare "Arduino" on a breadboard to do measures of current consumption. I used standard arv/power.h to switch off all peripherals and avr/sleep.h to go into power down mode. External (push button) interrupt is used to wake up the processor, and "L" LED is to indicate the operation. Everything was working fine, but current consumption was measured to be ~150uA instead of the maximum few microamperes, that should be by the datasheet.

Rummaging the net I found a library "Low-Power" (rocketscream), that could do the thing, in the power down mode current consumption was less then a microampere! As the Low-Power library does not know my final target platform (ATmega88), I looked into the code and was found the difference between the power.h and Low-Power: the power.h only uses PRR (power reduction register) to switch off ADC, while Low-Power disables the ADC in ADCSRA (ADC Control and Status Register A).

The datasheet sais about PRADC bit in the PRR register:
"Bit 0 – PRADC: Power Reduction ADC
Writing a logic one to this bit shuts down the ADC. The ADC must be disabled before shut down. The
analog comparator cannot use the ADC input MUX when the ADC is shut down."

As it seems, powering down ADC is not working if the ADC is not disabled before shutting down. While the ADC disabling code in avr/power.h does not matter with ADCSRA register, using only the built-in function the real low power consumption cannot be reached.

As I want to write my code with minimal using of "non standard" codelets make my code more portable, I cannot decide what I should do. I think, the best way would be correcting the "official" avr/power.h, but I don't know if it is possible anyway (not my local copy of it).

What do you suggest me, what way should walk?

Thanks.

As I want to write my code with minimal using of "non standard" codelets make my code more portable, I cannot decide what I should do.

Writing code for a specific microprocessor pretty much guarantees that it will not be completely portable, so don't worry about it.

Just document the unique code features with clear comments, or use #define, #if, #endif directives to isolate processor specific sections of code.

Best low power tutorial for AVR processors here: Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors

Thank you for reply!

jremington:
Writing code for a specific microprocessor pretty much guarantees that it will not be completely portable, so don't worry about it.

Yes, I know. Even selecting the AVR architecture is narrowing the portability. I thought there is some "official" way to do the task (switching off the ADC) hoping that the portability would remain at least using the AVR architecture. If it is not possible I should write my own code to do this.

Btw. the sentence above about PRADC bit is from the datasheet of ATmega328P, which is - I think - the most frequently used AVR in Arduino projects and can be found in the official Arduino boards. So the case is true for official Arduinos too, not only my "smaller brother" ATmega88.

jremington:
Just document the unique code features with clear comments, or use #define, #if, #endif directives to isolate processor specific sections of code.

You are right, the clean and well understandable coding and commenting is critical, especially when you port or modify your project years later.

jremington:
Best low power tutorial for AVR processors here: Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors

Many thanks, this is a very useful link. (They mentioned the switching off the ADC too!)

Regards,
Zoltan