SY883x_For_Client_JLAB_JS07/UsrSrc/bat/bat.c
Alex xu a29b5cb50b 更改内容:1、将全局变量在定义时不赋初值,需要赋初值的变量在系统初始化函数中赋值,节省ROM占用月100Bytes;
2、删除按键短按显示电量功能;
3、增加开盖Vox输出5V给耳机充电功能,有耳机入盒灯效,无出盒灯效,Vox检测到轻载后延迟10分钟后关闭Vox输出5V,转入ADT模式;
4、增加Vox充电过程中电池电压触发3.6V低电报警阈值后,Vox发送电量码pattern功能。
2025-02-10 11:37:49 +08:00

184 lines
2.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
******************************************************************************
*
* @file bat.c
* @brief Voltage-based RC model gauge algorithm
*
*
* @version 1.0
* @date 2023/02/20 17:35:40
* @author Alex Xu
*
* Copyright (c) 2013-2099,Tkplusemi Technology Co.,Ltd.
* All Rights Reserved
*
* History:
* Revision Date Author Desc
* 1.0.0 2023/02/20 Alex build this file
******************************************************************************
*/
#include "bat.h"
#include "adc.h"
#include "hall.h"
#include "userapp.h"
#include "system.h"
#include "sleep.h"
#include "led.h"
#include "vox_module.h"
uint8_t bat_level;
uint8_t bat_level_pdata;
bit F_batlevel_low; //电池低压
bit Bat_Low_TX_Flag; //电池电压≤3.6VVox发电量码标志位发完清零。
#if BAT_VALUE
#define C_offset_bat_level_MAX 190
#define C_offset_bat_level_MIN 10
bit F_batlevel_protect; //低电保护
uint8_t offset_bat_level;
/*充电电池电压会浮高,具体电压需要测试。*/
#define C_batLevel_SetMax 11
const uint16_t Boost_batlevel_Threshold[C_batLevel_SetMax] =
{
3200, //0
3500, //10%
3600, //20%
3700, //30%
3800, //40%
3900, //50%
3950, //60%
4000, //70%
4100, //80%
4150, //90%
4200 //100%
};
const uint8_t batlev_data[C_batLevel_SetMax] =
{
0x0A, //0 0b001010
0x18, //10% 0b011000
0x1A, //20% 0b011010
0x20, //30% 0b100000
0x22, //40% 0b100010
0x28, //50% 0b101000
0x29, //60% 0b101001
0x2A, //70% 0b101010
0x30, //80% 0b110000
0x31, //90% 0b110001
0x32 //100% 0b110010
};
//uint8_t bat_level_bk = 0;
void check_bat_level(void)
{
uint8_t i = 0;
//static uint8_t bat_level;
static uint8_t bat_level_bk;
//get bat level
#if ADC_ENABLE
for(i=0; i < C_batLevel_SetMax; i++)
{
if( Vbat_Adc < Boost_batlevel_Threshold[i] )
{
break;
}
}
#endif
#if 1
/*系统重启后,快速采集电量*/
if( RST_FLAG )
{
RST_FLAG = 0;
bat_level = i;
}
#endif
if( i > bat_level )
{
offset_bat_level++;
}
else
{
offset_bat_level--;
}
//debounce
if( (offset_bat_level > C_offset_bat_level_MAX) || (offset_bat_level < C_offset_bat_level_MIN) )
{
//update
bat_level = i;
if( bat_level_bk != bat_level )
{
bat_level_pdata = batlev_data[i];
bat_level_bk = bat_level;
}
offset_bat_level = ( C_offset_bat_level_MAX + C_offset_bat_level_MIN ) / 2;
}
if( bat_level <= C_bat_level_protect )
{
F_batlevel_protect = 1;
}
#if 0
else
if( bat_level > ( C_bat_level_protect + 1 ) )
{
F_batlevel_protect = 0;
}
#endif
if( bat_level <= C_bat_level_lowpower )
{
F_batlevel_low = 1;
// Bat_Low_TX_Flag = 1;
}
#if 0
else if( bat_level > (C_bat_level_lowpower + 2) )
{
F_batlevel_low = 0;
}
#endif
}
#endif