BATT-MON click
BATT-MON Click is a very versatile, high accuracy, multiple-chemistry battery gauge for applications single-cell batteries.
click Product page
Click library
- Author : MikroE Team
- Date : Jan 2020.
- Type : I2C type
Software Support
We provide a library for the BattMon Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.
Package can be downloaded/installed directly form compilers IDE(recommended way), or downloaded from our LibStock, or found on mikroE github account.
Library Description
This library contains API for BattMon Click driver.
Standard key functions :
- Config Object Initialization function.
void battmon_cfg_setup ( battmon_cfg_t *cfg );
- Initialization function.
BATTMON_RETVAL battmon_init ( battmon_t *ctx, battmon_cfg_t *cfg );
- Click Default Configuration function.
void battmon_default_cfg ( battmon_t *ctx );
Example key functions :
- Data Get function
float battmon_get_data ( battmon_t *ctx, uint8_t data_addr );
- ALM Pin Get function
uint8_t battmon_get_alm_pin ( battmon_t *ctx );
- Conversion Counter Reset function
void battmon_reset_conv_cnt ( battmon_t *ctx );
Examples Description
This application is battery charger.
The demo application is composed of two sections :
Application Init
Initializes I2C serial interface, reads the part ID and performs a device configuration and alarm setting.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
Delay_ms ( 500 );
log_printf( &logger, " ** Part ID: 0x%d \r\n", (uint16_t) reg_read );
log_printf( &logger, "** BattMon initialization done ** \r\n" );
log_printf( &logger, "********************************* \r\n" );
}
#define BATTMON_REG_ID
Definition battmon.h:118
#define BATTMON_MAP_MIKROBUS(cfg, mikrobus)
Definition battmon.h:66
BATTMON_RETVAL battmon_init(battmon_t *ctx, battmon_cfg_t *cfg)
Initialization function.
void battmon_cfg_setup(battmon_cfg_t *cfg)
Config Object Initialization function.
void battmon_default_cfg(battmon_t *ctx)
Click Default Configuration function.
uint8_t battmon_read_bytes(battmon_t *ctx, uint8_t reg_addr, uint8_t *data_out, uint8_t n_bytes)
Bytes Read function.
void application_init(void)
Definition main.c:47
Click configuration structure definition.
Definition battmon.h:247
Application Task
Checks the conversion counter value and when conversion was done reads data calculated to the properly unit and checks the alarm status. All results will be sent to the uart terminal.
{
char cels_symbol[ 3 ] = { 176, 'C', 0 };
float data_read;
uint16_t conv_cnt;
if ( ( ( conv_cnt % 4 ) == 0 ) && ( conv_cnt > 0 ) )
{
log_printf( &logger, "** Gas Gauge Relative SOC : %.2f %% \r\n ", data_read );
log_printf( &logger, "** Battery Current : %.2f mA \r\n", data_read );
log_printf( &logger, "** Battery Voltage : %.2f mV \r\n", data_read );
if ( ( conv_cnt % 16 ) == 0 )
{
log_printf( &logger, "** Temperature : %.2f %s\r\n", data_read, cels_symbol );
}
{
log_printf( &logger, "** Low-SOC Condition! \r\n" );
}
{
log_printf( &logger, "** Low-Voltage Condition! \r\n" );
}
log_printf( &logger, "********************************* \r\n" );
Delay_ms ( 1000 );
}
else
{
Delay_ms ( 200 );
}
}
#define BATTMON_ALM_SOC_DET_MASK
Definition battmon.h:200
#define BATTMON_ALM_VOLT_DET_MASK
Definition battmon.h:201
#define BATTMON_REG_CURRENT
Definition battmon.h:105
#define BATTMON_REG_COUNTER
Definition battmon.h:104
#define BATTMON_REG_TEMPERATURE
Definition battmon.h:107
#define BATTMON_REG_VOLTAGE
Definition battmon.h:106
#define BATTMON_REG_SOC
Definition battmon.h:103
#define BATTMON_LOG_LOW
Definition battmon.h:212
uint8_t battmon_check_clear_alarm(battmon_t *ctx)
Alarm Check And Clear function.
float battmon_get_data(battmon_t *ctx, uint8_t data_addr)
Data Get function.
void battmon_reset_conv_cnt(battmon_t *ctx)
Conversion Counter Reset function.
void application_task(void)
Definition main.c:82
Note
Voltage and current conversion will be done after 4 seconds. Temperature conversion will be done after 16 seconds. After temperature reading the conversion counter will be cleared. Clearing the alarm while the corresponding low-voltage or low-SOC condition is still in progress does not generate another interrupt. This condition must disappear first and must be detected again before another interrupt (ALM pin driven low or alarm interrupt bits are set high) is generated for this alarm. Another alarm condition, if not yet triggered, can still generate an interrupt. Input voltage must be in the range from 2.7V to 4.5V. Maximal battery current is 5A.
The full application code, and ready to use projects can be installed directly form compilers IDE(recommneded) or found on LibStock page or mikroE GitHub accaunt.
Other mikroE Libraries used in the example:
- MikroSDK.Board
- MikroSDK.Log
- Click.BattMon
Additional notes and informations
Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. The terminal available in all Mikroelektronika compilers, or any other terminal application of your choice, can be used to read the message.