一款电池监控解决方案,可提供宝贵的电池性能洞察,帮助您识别问题并优化其使用。
A
A
硬件概览
它是如何工作的?
BATT-MON Click基于STMicroelectronics的STC3115,这是一款高精度电池电量计IC,带有手持设备报警输出。它包含所有必要组件,以确保STC3115的正常功能,并保持Click板™的监控精度。监控功能包括电池电压、电流和温度的测量。还提供了库仑计数器,用于在电池以高速率充电或放电时跟踪SOC。一个sigma-delta A/D转换器用于测量电压、电流和温度。STC3115可以在两种不同的模式下运行,具有不同的功耗。模式选择通过寄存器0中的VMODE位进行。有关寄存器和工作模式的更多信息,请参阅
STC3115数据表。电池电压通过每4秒进行一次A/D转换器转换周期来测量。转换周期需要8192个时钟周期,这意味着当使用内部32768Hz时钟时,转换周期时间为250ms。电压范围为0至4.5V,分辨率为2.20mV。电压测量的精度在温度范围内为±0.5%。这允许从电池开路电压获得准确的SOC信息。通过内部14位sigma-delta A/D转换器测量用于电流感应的感应电阻(R9)上的电压降。使用32768Hz内部时钟,14位分辨率的转换周期时间为500ms。LSB值为5.88μV。A/D转换器输出为二进制补码格式。当转换周期完
成时,结果会添加到库仑计数器累加器中,转换次数会在16位计数器中递增。电流寄存器仅在最接近电压转换的转换后更新(每4秒测量周期一次)。结果存储在REG_CURRENT寄存器中。该Click板™可以通过VCC SEL跳线选择3.3V或5V逻辑电压水平运行。这样,具有3.3V和5V功能的MCU都可以正确使用通信线路。此外,Click板™还配备了一个库,包含易于使用的函数和示例代码,可用作进一步开发的参考。
功能概述
开发板
Clicker 2 for Kinetis 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位 ARM Cortex-M4F 微控制器,NXP 半导体公司的 MK64FN1M0VDC12,两个 mikroBUS™ 插槽用于 Click 板™连接,一个 USB 连接器,LED 指示灯,按钮,一个 JTAG 程序员连接器以及两个 26 针头用于与外部电子设备的接口。其紧凑的设计和清晰、易识别的丝网标记让您能够迅速构建具有独特功能和特性
的小工具。Clicker 2 for Kinetis 开发套件的每个部分 都包含了使同一板块运行最高效的必要组件。除了可以选择 Clicker 2 for Kinetis 的编程方式,使用 USB HID mikroBootloader 或外部 mikroProg 连接器进行 Kinetis 编程外,Clicker 2 板还包括一个干净且调节过的开发套件电源供应模块。它提供了两种供电方式;通过 USB Micro-B 电缆,其中板载电压调节器为板上每个组件提供适当的电压水平,或使用锂聚合物 电池通过板载电池连接器供电。所有 mikroBUS™ 本
身支持的通信方法都在这块板上,包括已经建立良好的 mikroBUS™ 插槽、重置按钮和几个用户可配置的按钮及 LED 指示灯。Clicker 2 for Kinetis 是 Mikroe 生态系统的一个组成部分,允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。
微控制器概述
MCU卡片 / MCU

建筑
ARM Cortex-M4
MCU 内存 (KB)
1024
硅供应商
NXP
引脚数
121
RAM (字节)
262144
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
Click board™ 原理图

一步一步来
项目组装
实时跟踪您的结果
应用程序输出
1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程。

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持
库描述
此库包含BATT-MON Click驱动程序的API。
关键功能:
battmon_get_data
- 数据获取功能battmon_get_alm_pin
- ALM引脚获取功能battmon_reset_conv_cnt
- 转换计数器重置功能
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* \file
* \brief BattMon Click example
*
* # 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.
*
* ## 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.
*
* *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.
*
* \author MikroE Team
*
*/
// ------------------------------------------------------------------- INCLUDES
#include "board.h"
#include "log.h"
#include "battmon.h"
// ------------------------------------------------------------------ VARIABLES
static battmon_t battmon;
static log_t logger;
static uint8_t reg_read;
// ------------------------------------------------------ APPLICATION FUNCTIONS
void application_init ( void )
{
log_cfg_t log_cfg;
battmon_cfg_t cfg;
/**
* Logger initialization.
* Default baud rate: 115200
* Default log level: LOG_LEVEL_DEBUG
* @note If USB_UART_RX and USB_UART_TX
* are defined as HAL_PIN_NC, you will
* need to define them manually for log to work.
* See @b LOG_MAP_USB_UART macro definition for detailed explanation.
*/
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
// Click initialization.
battmon_cfg_setup( &cfg );
BATTMON_MAP_MIKROBUS( cfg, MIKROBUS_1 );
battmon_init( &battmon, &cfg );
Delay_ms ( 500 );
battmon_read_bytes( &battmon, BATTMON_REG_ID, ®_read, 1 );
log_printf( &logger, " ** Part ID: 0x%d \r\n", (uint16_t) reg_read );
battmon_default_cfg( &battmon );
log_printf( &logger, "** BattMon initialization done ** \r\n" );
log_printf( &logger, "********************************* \r\n" );
}
void application_task ( void )
{
char cels_symbol[ 3 ] = { 176, 'C', 0 };
float data_read;
uint16_t conv_cnt;
conv_cnt = battmon_get_data( &battmon, BATTMON_REG_COUNTER );
if ( ( ( conv_cnt % 4 ) == 0 ) && ( conv_cnt > 0 ) )
{
data_read = battmon_get_data( &battmon, BATTMON_REG_SOC );
log_printf( &logger, "** Gas Gauge Relative SOC : %.2f %% \r\n ", data_read );
data_read = battmon_get_data( &battmon, BATTMON_REG_CURRENT );
log_printf( &logger, "** Battery Current : %.2f mA \r\n", data_read );
data_read = battmon_get_data( &battmon, BATTMON_REG_VOLTAGE );
log_printf( &logger, "** Battery Voltage : %.2f mV \r\n", data_read );
if ( ( conv_cnt % 16 ) == 0 )
{
data_read = battmon_get_data( &battmon, BATTMON_REG_TEMPERATURE );
battmon_reset_conv_cnt( &battmon );
log_printf( &logger, "** Temperature : %.2f %s\r\n", data_read, cels_symbol );
}
reg_read = battmon_check_clear_alarm( &battmon );
if ( ( reg_read & BATTMON_ALM_SOC_DET_MASK ) != BATTMON_LOG_LOW )
{
log_printf( &logger, "** Low-SOC Condition! \r\n" );
}
if ( ( reg_read & BATTMON_ALM_VOLT_DET_MASK ) != BATTMON_LOG_LOW )
{
log_printf( &logger, "** Low-Voltage Condition! \r\n" );
}
log_printf( &logger, "********************************* \r\n" );
Delay_ms ( 1000 );
}
else
{
Delay_ms ( 200 );
}
}
int main ( void )
{
/* Do not remove this line or clock might not be set correctly. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init( );
for ( ; ; )
{
application_task( );
}
return 0;
}
// ------------------------------------------------------------------------ END
/*!
* \file
* \brief BattMon Click example
*
* # 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.
*
* ## 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.
*
* *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.
*
* \author MikroE Team
*
*/
// ------------------------------------------------------------------- INCLUDES
#include "board.h"
#include "log.h"
#include "battmon.h"
// ------------------------------------------------------------------ VARIABLES
static battmon_t battmon;
static log_t logger;
static uint8_t reg_read;
// ------------------------------------------------------ APPLICATION FUNCTIONS
void application_init ( void )
{
log_cfg_t log_cfg;
battmon_cfg_t cfg;
/**
* Logger initialization.
* Default baud rate: 115200
* Default log level: LOG_LEVEL_DEBUG
* @note If USB_UART_RX and USB_UART_TX
* are defined as HAL_PIN_NC, you will
* need to define them manually for log to work.
* See @b LOG_MAP_USB_UART macro definition for detailed explanation.
*/
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
// Click initialization.
battmon_cfg_setup( &cfg );
BATTMON_MAP_MIKROBUS( cfg, MIKROBUS_1 );
battmon_init( &battmon, &cfg );
Delay_ms ( 500 );
battmon_read_bytes( &battmon, BATTMON_REG_ID, ®_read, 1 );
log_printf( &logger, " ** Part ID: 0x%d \r\n", (uint16_t) reg_read );
battmon_default_cfg( &battmon );
log_printf( &logger, "** BattMon initialization done ** \r\n" );
log_printf( &logger, "********************************* \r\n" );
}
void application_task ( void )
{
char cels_symbol[ 3 ] = { 176, 'C', 0 };
float data_read;
uint16_t conv_cnt;
conv_cnt = battmon_get_data( &battmon, BATTMON_REG_COUNTER );
if ( ( ( conv_cnt % 4 ) == 0 ) && ( conv_cnt > 0 ) )
{
data_read = battmon_get_data( &battmon, BATTMON_REG_SOC );
log_printf( &logger, "** Gas Gauge Relative SOC : %.2f %% \r\n ", data_read );
data_read = battmon_get_data( &battmon, BATTMON_REG_CURRENT );
log_printf( &logger, "** Battery Current : %.2f mA \r\n", data_read );
data_read = battmon_get_data( &battmon, BATTMON_REG_VOLTAGE );
log_printf( &logger, "** Battery Voltage : %.2f mV \r\n", data_read );
if ( ( conv_cnt % 16 ) == 0 )
{
data_read = battmon_get_data( &battmon, BATTMON_REG_TEMPERATURE );
battmon_reset_conv_cnt( &battmon );
log_printf( &logger, "** Temperature : %.2f %s\r\n", data_read, cels_symbol );
}
reg_read = battmon_check_clear_alarm( &battmon );
if ( ( reg_read & BATTMON_ALM_SOC_DET_MASK ) != BATTMON_LOG_LOW )
{
log_printf( &logger, "** Low-SOC Condition! \r\n" );
}
if ( ( reg_read & BATTMON_ALM_VOLT_DET_MASK ) != BATTMON_LOG_LOW )
{
log_printf( &logger, "** Low-Voltage Condition! \r\n" );
}
log_printf( &logger, "********************************* \r\n" );
Delay_ms ( 1000 );
}
else
{
Delay_ms ( 200 );
}
}
int main ( void )
{
/* Do not remove this line or clock might not be set correctly. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init( );
for ( ; ; )
{
application_task( );
}
return 0;
}
// ------------------------------------------------------------------------ END
/*!
* \file
* \brief BattMon Click example
*
* # 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.
*
* ## 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.
*
* *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.
*
* \author MikroE Team
*
*/
// ------------------------------------------------------------------- INCLUDES
#include "board.h"
#include "log.h"
#include "battmon.h"
// ------------------------------------------------------------------ VARIABLES
static battmon_t battmon;
static log_t logger;
static uint8_t reg_read;
// ------------------------------------------------------ APPLICATION FUNCTIONS
void application_init ( void )
{
log_cfg_t log_cfg;
battmon_cfg_t cfg;
/**
* Logger initialization.
* Default baud rate: 115200
* Default log level: LOG_LEVEL_DEBUG
* @note If USB_UART_RX and USB_UART_TX
* are defined as HAL_PIN_NC, you will
* need to define them manually for log to work.
* See @b LOG_MAP_USB_UART macro definition for detailed explanation.
*/
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
// Click initialization.
battmon_cfg_setup( &cfg );
BATTMON_MAP_MIKROBUS( cfg, MIKROBUS_1 );
battmon_init( &battmon, &cfg );
Delay_ms ( 500 );
battmon_read_bytes( &battmon, BATTMON_REG_ID, ®_read, 1 );
log_printf( &logger, " ** Part ID: 0x%d \r\n", (uint16_t) reg_read );
battmon_default_cfg( &battmon );
log_printf( &logger, "** BattMon initialization done ** \r\n" );
log_printf( &logger, "********************************* \r\n" );
}
void application_task ( void )
{
char cels_symbol[ 3 ] = { 176, 'C', 0 };
float data_read;
uint16_t conv_cnt;
conv_cnt = battmon_get_data( &battmon, BATTMON_REG_COUNTER );
if ( ( ( conv_cnt % 4 ) == 0 ) && ( conv_cnt > 0 ) )
{
data_read = battmon_get_data( &battmon, BATTMON_REG_SOC );
log_printf( &logger, "** Gas Gauge Relative SOC : %.2f %% \r\n ", data_read );
data_read = battmon_get_data( &battmon, BATTMON_REG_CURRENT );
log_printf( &logger, "** Battery Current : %.2f mA \r\n", data_read );
data_read = battmon_get_data( &battmon, BATTMON_REG_VOLTAGE );
log_printf( &logger, "** Battery Voltage : %.2f mV \r\n", data_read );
if ( ( conv_cnt % 16 ) == 0 )
{
data_read = battmon_get_data( &battmon, BATTMON_REG_TEMPERATURE );
battmon_reset_conv_cnt( &battmon );
log_printf( &logger, "** Temperature : %.2f %s\r\n", data_read, cels_symbol );
}
reg_read = battmon_check_clear_alarm( &battmon );
if ( ( reg_read & BATTMON_ALM_SOC_DET_MASK ) != BATTMON_LOG_LOW )
{
log_printf( &logger, "** Low-SOC Condition! \r\n" );
}
if ( ( reg_read & BATTMON_ALM_VOLT_DET_MASK ) != BATTMON_LOG_LOW )
{
log_printf( &logger, "** Low-Voltage Condition! \r\n" );
}
log_printf( &logger, "********************************* \r\n" );
Delay_ms ( 1000 );
}
else
{
Delay_ms ( 200 );
}
}
int main ( void )
{
/* Do not remove this line or clock might not be set correctly. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init( );
for ( ; ; )
{
application_task( );
}
return 0;
}
// ------------------------------------------------------------------------ END