avr_power(3)
๐ 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,USARTvsUSART0). 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 typical32.768 kHzcrystal, one shall not scale the clock below131.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 PortApower_adca_enable()โ Enable the Analog to Digital Converter module on PortApower_evsys_disable()โ Disable the EVSYS modulepower_evsys_enable()โ Enable the EVSYS modulepower_hiresc_disable()โ Disable the HIRES module on PortCpower_hiresc_enable()โ Enable the HIRES module on PortCpower_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 modulepower_rtc_enable()โ Enable the RTC modulepower_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 PortCpower_spic_enable()โ Enable the SPI module on PortCpower_spid_disable()โ Disable the SPI module on PortDpower_spid_enable()โ Enable the SPI module on PortDpower_tc0c_disable()โ Disable the TC0 module on PortCpower_tc0c_enable()โ Enable the TC0 module on PortCpower_tc0d_disable()โ Disable the TC0 module on PortDpower_tc0d_enable()โ Enable the TC0 module on PortDpower_tc0e_disable()โ Disable the TC0 module on PortEpower_tc0e_enable()โ Enable the TC0 module on PortEpower_tc0f_disable()โ Disable the TC0 module on PortFpower_tc0f_enable()โ Enable the TC0 module on PortFpower_tc1c_disable()โ Disable the TC1 module on PortCpower_tc1c_enable()โ Enable the TC1 module on PortCpower_twic_disable()โ Disable the Two Wire Interface module on PortCpower_twic_enable()โ Enable the Two Wire Interface module on PortCpower_twie_disable()โ Disable the Two Wire Interface module on PortEpower_twie_enable()โ Enable the Two Wire Interface module on PortEpower_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 PortCpower_usartc0_enable()โ Enable the USART0 module on PortCpower_usartd0_disable()โ Disable the USART0 module on PortDpower_usartd0_enable()โ Enable the USART0 module on PortDpower_usarte0_disable()โ Disable the USART0 module on PortEpower_usarte0_enable()โ Enable the USART0 module on PortEpower_usartf0_disable()โ Disable the USART0 module on PortFpower_usartf0_enable()โ Enable the USART0 module on PortFpower_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 from1to129. so you don't even need to use theclock_div_ttype 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
- fedora 43: avr-libc 2.2.1-3.fc43 ยท BSD-3-Clause
- fedora 44: avr-libc 2.2.1-5.fc44 ยท BSD-3-Clause
- opensuse-leap 16.0: avr-libc 2.1.0-bp160.1.33 ยท BSD-3-Clause
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms