avr_power(3avr)

πŸ“¦
version 2.2.1 Β· 2 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

avr_power β€” <avr/power.h>: Power Reduction Management πŸŽ€

fr fr this is the avr_power page from the 3avr manual, and it's basically the master switch panel for your microcontroller's power bill. bestie, we are turning things OFF. πŸ’…


✨ SYNOPSIS ✨

Macros

#define clock_prescale_get()

Functions

static void power_all_enable ()
static void power_all_disable ()
void clock_prescale_set (clock_div_t __x)

🌸 Detailed Description 🌸

#include <avr/power.h>

okay so here's the vibe πŸ‘‘ β€” lots of AVRs have a Power Reduction Register (PRR) or, like, several of them (PRRx), and what they do is let you cut power consumption by disabling or enabling all the different on-board peripherals whenever you feel like it. some devices also ship with the XTAL Divide Control Register (XDIV), which does pretty much the same kind of thing as the System Clock Prescale Register (CLKPR). iconic, honestly.

this header file is FULL of macros that give you an easy little interface to enable or disable on-board peripherals and lower that power draw. the whole list is right down below. ⬇️

🫢 real talk though: - Not all AVR devices have a Power Reduction Register (for example the ATmega8). On those devices without a Power Reduction Register, the power reduction macros are not available. 😭 - Not all AVR devices contain the same peripherals (for example, the LCD interface), or they will be named differently (for example, USART and USART0). Please consult your device's datasheet, or the header file, to find out which macros are applicable to your device. πŸ” - For device using the XTAL Divide Control Register (XDIV), when prescaler is used, Timer/Counter0 can only be used in asynchronous mode. 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. ⏰

πŸ’– The Power Macro Table πŸ’–

here's every single one, no skips, no cap:

  • 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

πŸ•°οΈ Clock Prescaling, the Other Half of the Story πŸ•°οΈ

so some of the newer AVRs contain a System Clock Prescale Register (CLKPR) that allows you to decrease the system clock frequency and the power consumption when the need for processing power is low. lowkey the move. πŸ’€

and on some earlier AVRs (ATmega103, ATmega64, ATmega128), similar functionality can be achieved through the XTAL Divide Control Register. below are two macros and an enumerated type that can be used to interface to the Clock Prescale Register or 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. πŸ’€

Clock prescaler setting enumerations for device using 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 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;

πŸŽ€ Macro Definition Documentation πŸŽ€

#define clock_prescale_get()

Value:

(clock_div_t)(CLKPR & (uint8_t)((1<<CLKPS0)|(1<<CLKPS1)|(1<<CLKPS2)|(1<<CLKPS3)))

Gets and returns the clock prescaler register setting. ✨ the return type is clock_div_t.

🚨 okay so for device with XTAL Divide Control Register (XDIV), return can actually range from 1 to 129. Care should be taken has the return value could differ from the typedef enum clock_div_t. This should only happen if clock_prescale_set was previously called with a value other than those defined by clock_div_t. so like… watch out πŸ™ˆ

πŸ’œ Function Documentation πŸ’œ

void clock_prescale_set (clock_div_t x)

Set the clock prescaler register select bits, selecting a system clock division setting. this function is inlined, even if compiler optimizations are disabled. she works regardless. πŸ’…

the type of x is clock_div_t.

🚨 for device with XTAL Divide Control Register (XDIV), x can actually range from 1 to 129. Thus, one does not need to use clock_div_t type as argument. okayyy loophole πŸ‘€

void power_all_disable () [inline], [static]

Disable all modules. everything. the whole party. lights out. πŸ’€πŸ«Ά


void power_all_enable () [inline], [static]

Enable all modules. the party's back on. πŸŽ‰


πŸ‘‘ Author πŸ‘‘

Generated automatically by Doxygen for AVR-LibC from the source code. yeah bestie, a robot wrote this one, not me β€” I just gave it the sparkle it deserved. πŸ€–βœ¨


and that's the whole page, cutie 🫢 this was AVR-LibC, Version 2.2.1, from the avr_power(3avr) manual β€” now go turn some peripherals off and save that battery, periodt. πŸ’–πŸŒˆ

πŸ“¦ where this page comes from