rcc 1.0
RCC - RGB LED Color Cube Documentation
Loading...
Searching...
No Matches
battery.h File Reference

Battery monitoring interface for AVR microcontrollers. More...

#include <avr/io.h>
#include "../hal/avr0/adc/adc.h"
Include dependency graph for battery.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define BATTERY_CHANNEL   ADC_CH6
 Specifies the ADC channel used for battery voltage measurement.
#define BATTERY_EMPTY_VALUE   990UL
 ADC threshold value indicating an empty or critically low battery.

Typedefs

typedef enum BATTERY_Status_t BATTERY_Status
 Alias for enum BATTERY_Status_t to represent battery status codes.

Enumerations

enum  BATTERY_Status_t { BATTERY_Ok =0 , BATTERY_Fault }
 Represents the status of the battery voltage measurement. More...

Functions

void battery_init (void)
 Initialize the battery measurement interface.
void battery_disable (void)
 Disable battery voltage measurement.
BATTERY_Status battery_status (void)
 Check the current battery status.

Detailed Description

Battery monitoring interface for AVR microcontrollers.

This header file defines the interface for battery status monitoring using an ADC channel. It provides macros to configure ADC channel and battery empty threshold, a status enumeration, and function prototypes to initialize battery measurement and retrieve battery status.

Author
g.raf
Date
2025-09-28
Version
1.0 Release
Note
This file is part of a larger embedded systems project and subject to the license specified in the repository. For updates and the complete revision history, see the GitHub repository.
See also
https://github.com/0x007e/rcc "AVR ATmega GitHub Repository"

Macro Definition Documentation

◆ BATTERY_CHANNEL

#define BATTERY_CHANNEL   ADC_CH6

Specifies the ADC channel used for battery voltage measurement.

This macro defines the ADC channel number used to measure the battery voltage. By default, it is set to ADC_CH6. Override this macro before including the battery module to use a different ADC channel if your hardware configuration requires it.

Note
Ensure the selected ADC channel is properly connected to the battery voltage sensing circuitry.

◆ BATTERY_EMPTY_VALUE

#define BATTERY_EMPTY_VALUE   990UL

ADC threshold value indicating an empty or critically low battery.

This macro defines the ADC reading value below which the battery is considered empty or in fault condition. Override this macro before including the battery module to adjust the threshold value if your hardware or battery specifications differ.

Note
The setting of the BATTERY_EMPTY_VALUE depends on the voltage reference of the A/D converter and the input voltage of the channel.

Typedef Documentation

◆ BATTERY_Status

Alias for enum BATTERY_Status_t to represent battery status codes.

Enumeration Type Documentation

◆ BATTERY_Status_t

Represents the status of the battery voltage measurement.

This enumeration defines possible statuses indicating the state of the battery based on the analog-to-digital converter (ADC) measurement.

Values include:

  • BATTERY_Ok: Battery voltage is above the defined empty threshold, indicating a healthy battery.
  • BATTERY_Fault: Battery voltage is below the threshold, indicating an empty or faulty battery.
Enumerator
BATTERY_Ok 
BATTERY_Fault 

Function Documentation

◆ battery_disable()

void battery_disable ( void )
inline

Disable battery voltage measurement.

This inline function disables the ADC hardware module used for battery voltage measurement. Calling this function reduces power consumption by shutting down the ADC when battery monitoring is not needed.

Note
Ensure that no battery measurement is required before calling this function, as it will disable all ADC functionality until reinitialized.
See also
adc_disable() for generic ADC disable function.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ battery_init()

void battery_init ( void )

Initialize the battery measurement interface.

This function initializes the ADC module and configures the ADC channel used for battery voltage measurement as defined by the BATTERY_CHANNEL macro. Must be called before reading battery status to ensure proper ADC setup.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ battery_status()

BATTERY_Status battery_status ( void )

Check the current battery status.

Returns
Returns BATTERY_Ok if the battery voltage is above the configured minimum threshold, otherwise returns BATTERY_Fault.

This function reads the battery voltage using the ADC and compares the value against the BATTERY_EMPTY_VALUE threshold to determine if the battery is considered empty or faulty.

Here is the call graph for this function:
Here is the caller graph for this function: