avr_power(3)

๐Ÿ“ฆ version 2.2.1, in fedora 43, fedora 44, opensuse-leap 16.0

๐Ÿ’– avr_power ๐Ÿ’–

okay bestie, welcome to the avr_power page from the avr-libc manual ๐Ÿ’… this is the whole low-power era of your AVR's life and honestly it's giving energy-saving icon behavior. no cap.


โœจ SYNOPSIS โœจ

Functions

void clock_prescale_set (clock_div_t __x)

๐Ÿซถ Detailed Description ๐Ÿซถ

#include <avr/power.h>

so like, a LOT of AVRs ship with a Power Reduction Register (PRR) or honestly several of them (PRRx), and their whole thing is letting you cut power consumption by turning on-board peripherals on and off whenever you feel like it. slay. some devices also have the XTAL Divide Control Register (XDIV), which does pretty much the same kind of job as the System Clock Prescale Register (CLKPR).

this header file is FULL of macros that give you an easy little interface to enable or disable on-board peripherals and save power. the whole list is down below ๐Ÿ‘‡

Note

๐Ÿšจ not every AVR device has a Power Reduction Register (the ATmega8 says hi and says no). on those devices that don't have one, the power reduction macros are simply not available.
๐Ÿšจ not every AVR device contains the same peripherals (the LCD interface is a whole example of this), or they'll be named differently (looking at you, USART vs USART0). please go consult your device's datasheet, or the header file itself, to figure out which macros actually apply to your device. iykyk.
๐Ÿšจ for devices using the XTAL Divide Control Register (XDIV), when prescaler is used, Timer/Counter0 can only be used in asynchronous mode. and keep in mind that Timer/Counter0 source shall be less than ยผth of peripheral clock. therefore, when using a typical 32.768 kHz crystal, one shall not scale the clock below 131.072 kHz. math is math bestie ๐Ÿงฎ

Power Macro Description

  • power_aca_disable() โ€” Disable the Analog Comparator on PortA.
  • power_aca_enable() โ€” Enable the Analog Comparator on PortA.
  • power_adc_enable() โ€” Enable the Analog to Digital Converter module.
  • power_adc_disable() โ€” Disable the Analog to Digital Converter module.
  • power_adca_disable() โ€” Disable the Analog to Digital Converter module on PortA
  • power_adca_enable() โ€” Enable the Analog to Digital Converter module on PortA
  • power_evsys_disable() โ€” Disable the EVSYS module
  • power_evsys_enable() โ€” Enable the EVSYS module
  • power_hiresc_disable() โ€” Disable the HIRES module on PortC
  • power_hiresc_enable() โ€” Enable the HIRES module on PortC
  • power_lcd_enable() โ€” Enable the LCD module.
  • power_lcd_disable() โ€” Disable the LCD module.
  • power_pga_enable() โ€” Enable the Programmable Gain Amplifier module.
  • power_pga_disable() โ€” Disable the Programmable Gain Amplifier module.
  • power_pscr_enable() โ€” Enable the Reduced Power Stage Controller module.
  • power_pscr_disable() โ€” Disable the Reduced Power Stage Controller module.
  • power_psc0_enable() โ€” Enable the Power Stage Controller 0 module.
  • power_psc0_disable() โ€” Disable the Power Stage Controller 0 module.
  • power_psc1_enable() โ€” Enable the Power Stage Controller 1 module.
  • power_psc1_disable() โ€” Disable the Power Stage Controller 1 module.
  • power_psc2_enable() โ€” Enable the Power Stage Controller 2 module.
  • power_psc2_disable() โ€” Disable the Power Stage Controller 2 module.
  • power_ram0_enable() โ€” Enable the SRAM block 0 .
  • power_ram0_disable() โ€” Disable the SRAM block 0.
  • power_ram1_enable() โ€” Enable the SRAM block 1 .
  • power_ram1_disable() โ€” Disable the SRAM block 1.
  • power_ram2_enable() โ€” Enable the SRAM block 2 .
  • power_ram2_disable() โ€” Disable the SRAM block 2.
  • power_ram3_enable() โ€” Enable the SRAM block 3 .
  • power_ram3_disable() โ€” Disable the SRAM block 3.
  • power_rtc_disable() โ€” Disable the RTC module
  • power_rtc_enable() โ€” Enable the RTC module
  • power_spi_enable() โ€” Enable the Serial Peripheral Interface module.
  • power_spi_disable() โ€” Disable the Serial Peripheral Interface module.
  • power_spic_disable() โ€” Disable the SPI module on PortC
  • power_spic_enable() โ€” Enable the SPI module on PortC
  • power_spid_disable() โ€” Disable the SPI module on PortD
  • power_spid_enable() โ€” Enable the SPI module on PortD
  • power_tc0c_disable() โ€” Disable the TC0 module on PortC
  • power_tc0c_enable() โ€” Enable the TC0 module on PortC
  • power_tc0d_disable() โ€” Disable the TC0 module on PortD
  • power_tc0d_enable() โ€” Enable the TC0 module on PortD
  • power_tc0e_disable() โ€” Disable the TC0 module on PortE
  • power_tc0e_enable() โ€” Enable the TC0 module on PortE
  • power_tc0f_disable() โ€” Disable the TC0 module on PortF
  • power_tc0f_enable() โ€” Enable the TC0 module on PortF
  • power_tc1c_disable() โ€” Disable the TC1 module on PortC
  • power_tc1c_enable() โ€” Enable the TC1 module on PortC
  • power_twic_disable() โ€” Disable the Two Wire Interface module on PortC
  • power_twic_enable() โ€” Enable the Two Wire Interface module on PortC
  • power_twie_disable() โ€” Disable the Two Wire Interface module on PortE
  • power_twie_enable() โ€” Enable the Two Wire Interface module on PortE
  • power_timer0_enable() โ€” Enable the Timer 0 module.
  • power_timer0_disable() โ€” Disable the Timer 0 module.
  • power_timer1_enable() โ€” Enable the Timer 1 module.
  • power_timer1_disable() โ€” Disable the Timer 1 module.
  • power_timer2_enable() โ€” Enable the Timer 2 module.
  • power_timer2_disable() โ€” Disable the Timer 2 module.
  • power_timer3_enable() โ€” Enable the Timer 3 module.
  • power_timer3_disable() โ€” Disable the Timer 3 module.
  • power_timer4_enable() โ€” Enable the Timer 4 module.
  • power_timer4_disable() โ€” Disable the Timer 4 module.
  • power_timer5_enable() โ€” Enable the Timer 5 module.
  • power_timer5_disable() โ€” Disable the Timer 5 module.
  • power_twi_enable() โ€” Enable the Two Wire Interface module.
  • power_twi_disable() โ€” Disable the Two Wire Interface module.
  • power_usart_enable() โ€” Enable the USART module.
  • power_usart_disable() โ€” Disable the USART module.
  • power_usart0_enable() โ€” Enable the USART 0 module.
  • power_usart0_disable() โ€” Disable the USART 0 module.
  • power_usart1_enable() โ€” Enable the USART 1 module.
  • power_usart1_disable() โ€” Disable the USART 1 module.
  • power_usart2_enable() โ€” Enable the USART 2 module.
  • power_usart2_disable() โ€” Disable the USART 2 module.
  • power_usart3_enable() โ€” Enable the USART 3 module.
  • power_usart3_disable() โ€” Disable the USART 3 module.
  • power_usartc0_disable() โ€” Disable the USART0 module on PortC
  • power_usartc0_enable() โ€” Enable the USART0 module on PortC
  • power_usartd0_disable() โ€” Disable the USART0 module on PortD
  • power_usartd0_enable() โ€” Enable the USART0 module on PortD
  • power_usarte0_disable() โ€” Disable the USART0 module on PortE
  • power_usarte0_enable() โ€” Enable the USART0 module on PortE
  • power_usartf0_disable() โ€” Disable the USART0 module on PortF
  • power_usartf0_enable() โ€” Enable the USART0 module on PortF
  • power_usb_enable() โ€” Enable the USB module.
  • power_usb_disable() โ€” Disable the USB module.
  • power_usi_enable() โ€” Enable the Universal Serial Interface module.
  • power_usi_disable() โ€” Disable the Universal Serial Interface module.
  • power_vadc_enable() โ€” Enable the Voltage ADC module.
  • power_vadc_disable() โ€” Disable the Voltage ADC module.
  • power_all_enable() โ€” Enable all modules.
  • power_all_disable() โ€” Disable all modules.

okay now, some of the newer AVRs have a System Clock Prescale Register (CLKPR) and the whole vibe of it is letting you turn the system clock frequency down โ€” and therefore the power consumption too โ€” for when you don't really need much processing power. and on some earlier AVRs (ATmega103, ATmega64, ATmega128), you can get similar functionality through the XTAL Divide Control Register. so below there are two macros and an enumerated type you can use to interface with the Clock Prescale Register or the XTAL Divide Control Register ๐ŸŽ€

๐Ÿšจ not all AVR devices have a clock prescaler!! on those devices without a Clock Prescale Register or XTAL Divide Control Register, these macros are not available. sad but true ๐Ÿ’€

here's the enum for devices using the System Clock Prescale Register:

typedef enum
{
    clock_div_1 = 0,
    clock_div_2 = 1,
    clock_div_4 = 2,
    clock_div_8 = 3,
    clock_div_16 = 4,
    clock_div_32 = 5,
    clock_div_64 = 6,
    clock_div_128 = 7,
    clock_div_256 = 8,
    clock_div_1_rc = 15, // ATmega128RFA1 only
} clock_div_t;

Clock prescaler setting enumerations for device using System Clock Prescale Register. โญ

and here's the enum for devices using the XTAL Divide Control Register:

typedef enum
{
    clock_div_1 = 1,
    clock_div_2 = 2,
    clock_div_4 = 4,
    clock_div_8 = 8,
    clock_div_16 = 16,
    clock_div_32 = 32,
    clock_div_64 = 64,
    clock_div_128 = 128
} clock_div_t;

Clock prescaler setting enumerations for device using XTAL Divide Control Register. ๐ŸŒˆ


๐Ÿ”ฅ Function Documentation ๐Ÿ”ฅ

clock_prescale_set (clock_div_t x)

sets the clock prescaler register select bits, so you're picking a system clock division setting. and the cute part: this function is inlined, even if compiler optimizations are disabled. no cap, it just does that ๐Ÿ’…

the type of x is clock_div_t.

๐Ÿšจ for a device with XTAL Divide Control Register (XDIV), x can actually range from 1 to 129. so you don't even need to use the clock_div_t type as the argument. free real estate ๐Ÿฆ‹

๐Ÿ‘‘ Author ๐Ÿ‘‘

Generated automatically by Doxygen for avr-libc from the source code.


and that's the whole page bestie!! this was Version 2.1.0, dated Sat Jan 29 2022 โ€” go forth and put your AVR in low-power mode, it's what she deserves ๐Ÿซถโœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from