forked from gary/BCU
2
0
Fork 0

高压采集问题解决

This commit is contained in:
guzz 2025-02-15 19:57:30 +08:00
parent f02582475f
commit b4ce65176d
10 changed files with 199 additions and 2264058 deletions

View File

@ -14,7 +14,7 @@
#include "drv_ads8688.h" #include "drv_ads8688.h"
#define CUR_FILTER_ENABLE (0u) #define CUR_FILTER_ENABLE (0u)
#define ADCIC_SAMPLE_CNT (4u) #define ADCIC_SAMPLE_CNT (20u)
ADS8688_STATIC_INIT(ads8688, kSpiDev_2, kGpioType_ADC_Cs); ADS8688_STATIC_INIT(ads8688, kSpiDev_2, kGpioType_ADC_Cs);
@ -195,8 +195,8 @@ int16_t bms_caculate_current(uint32_t base_time)
{ {
case kCurSensor_Shunt: case kCurSensor_Shunt:
// 分流器 cur_hv_item.cur_volt_avg / cur_prop.shunt_volt * cur_prop.cur_scale; // 分流器 cur_hv_item.cur_volt_avg / cur_prop.shunt_volt * cur_prop.cur_scale;
//current = (int32_t)cur_hv_item.value[kAdIc_Cur] * prop->scale / cur_item.shunt_volt; current = (int32_t)cur_hv_item.value[kAdIc_Cur] * prop->scale / cur_item.shunt_volt;
current = HighResCurTrans(cur_hv_item.value[kAdIc_Cur]); //current = HighResCurTrans(cur_hv_item.value[kAdIc_Cur]);
break; break;
case kCurSensor_SigHall: case kCurSensor_SigHall:
// 霍尔电流 // 霍尔电流
@ -289,8 +289,23 @@ void get_ad_sample(void)
int32_t i =0; int32_t i =0;
uint16_t ad =0; uint16_t ad =0;
//auto scan mode #if ADC_AUTO_MODE
drv_enter_auto_rst_mode_Data(outputdata, 6); //auto scan mode
drv_enter_auto_rst_mode_Data(outputdata, 6);
#else
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_0);
i += 1;
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_1);
i += 1;
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_2);
i += 1;
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_3);
i += 1;
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_4);
i += 1;
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_5);
i += 1;
#endif
for (i = 0; i < kAdIc_End; i++) for (i = 0; i < kAdIc_End; i++)
{ {
@ -309,24 +324,24 @@ void get_ad_sample(void)
} }
if (i == kAdIc_HvBat) if (i == kAdIc_HvBat)
{ {
cur_hv_item.value[i] = (ad / 100) * 512 * 10 / (0x01 << 16); //单位是mv cur_hv_item.value[i] = (376 * ad * 512 * 10 / (0x01 << 15)) / 100; //单位是mv
bms_set_iso_volt_ad(kIsoVolt_TotalVolt, cur_hv_item.value[i]); bms_set_iso_volt_ad(kIsoVolt_TotalVolt, cur_hv_item.value[i]);
} }
if(i == kAdIc_Hv1) if(i == kAdIc_Hv1)
{ {
cur_hv_item.value[i] = (ad / 100) * 512 * 10 / (0x01 << 16); //单位是mv cur_hv_item.value[i] = (376 * ad * 512 * 10 / (0x01 << 15)) / 100; //单位是mv
} }
if(i == kAdIc_Cur) if(i == kAdIc_Cur)
{ {
ad = ad - adIc_adjust_value[i].zero; ad = ad - adIc_adjust_value[i].zero;
ad = (10 * ad / 82000) * 512 * 1000/ (0x01 << 16); //单位是mv ad = (ad * 5120 * 10 / (0x01 << 15)) / 82; //单位是mv
// 防止eeprom中没有设置电压校准系数 // 防止eeprom中没有设置电压校准系数
if (get_eeprom_data(kEep_Volt1CalFactor, kEepromDataType_Full) <= 900 || get_eeprom_data(kEep_Volt1CalFactor, kEepromDataType_Full) >= 1100) if (get_eeprom_data(kEep_Volt1CalFactor, kEepromDataType_Full) <= 900 || get_eeprom_data(kEep_Volt1CalFactor, kEepromDataType_Full) >= 1100)
{ {
bsp_eeprom_save_data(kEep_Volt1CalFactor, 1000, kEepromDataType_Full); bsp_eeprom_save_data(kEep_Volt1CalFactor, 1000, kEepromDataType_Full);
} }
cur_hv_item.value[i] = ad / 1000 * adIc_adjust_value[i].rate *get_eeprom_data(kEep_Volt1CalFactor, kEepromDataType_Full) / 1000;//转为V cur_hv_item.value[i] = ad ;/// 1000 * adIc_adjust_value[i].rate *get_eeprom_data(kEep_Volt1CalFactor, kEepromDataType_Full) / 1000;//转为V
} }
if (cur_hv_item.ad_buf_pos[i] >= ADCIC_SAMPLE_CNT) if (cur_hv_item.ad_buf_pos[i] >= ADCIC_SAMPLE_CNT)

View File

@ -13,10 +13,8 @@ extern "C" {
typedef enum typedef enum
{ {
kHvType_Iso,
kHvType_Bat,
kHvType_Hv1, kHvType_Hv1,
kHvType_Hv2, kHvType_Bat,
kHvType_End, kHvType_End,
}HvType; }HvType;

View File

@ -230,8 +230,8 @@ void logic_same_circuit_ctrl(uint32_t base_time)
prechg_volt = bms_get_high_volt(kHvType_Bat);//sfj 获取B+B-电压 prechg_volt = bms_get_high_volt(kHvType_Bat);//sfj 获取B+B-电压
if (prechg_volt >= 300) if (prechg_volt >= 300)
{ {
prechg_type = (HvType)get_eeprom_data(kEep_PreChgVoltType_Rate,kEepromDataType_High); prechg_type = 0;// (HvType)get_eeprom_data(kEep_PreChgVoltType_Rate,kEepromDataType_High);
prechg_volt = prechg_volt * get_eeprom_data(kEep_PreChgVoltType_Rate,kEepromDataType_Low) / 100; prechg_volt = prechg_volt * 80 / 100 ;//get_eeprom_data(kEep_PreChgVoltType_Rate,kEepromDataType_Low) / 100;
if(bms_get_high_volt(prechg_type) >= prechg_volt) if(bms_get_high_volt(prechg_type) >= prechg_volt)
{ {
dly = 0; dly = 0;

View File

@ -465,13 +465,13 @@ void bms_init_soc(void)
uint64_t tmp_64u; uint64_t tmp_64u;
int32_t year, mon, day; int32_t year, mon, day;
//soc = get_eeprom_data(kEep_SOC, kEepromDataType_Full); soc = get_eeprom_data(kEep_SOC, kEepromDataType_Full);
soc = bms_check_pwr_on_ocv(soc); //soc = bms_check_pwr_on_ocv(soc);
sox_item.soc_kEep_99 = true; sox_item.soc_kEep_99 = true;
sox_item.soc_kEep_1 = true; sox_item.soc_kEep_1 = true;
if (soc == 0) if (soc == 0)
{ {
sox_item.soc_kEep_1 = false; sox_item.soc_kEep_1 = false;
} }
else if (soc == SOX_MAX_SOC_VALUE) else if (soc == SOX_MAX_SOC_VALUE)
{ {

File diff suppressed because one or more lines are too long

View File

@ -861,16 +861,16 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\app\statistic_manager.c</FilePath> <FilePath>..\app\statistic_manager.c</FilePath>
</File> </File>
<File>
<FileName>version_manager.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\version_manager.c</FilePath>
</File>
<File> <File>
<FileName>bmu_adbms1818.c</FileName> <FileName>bmu_adbms1818.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\app\bmu_adbms1818.c</FilePath> <FilePath>..\app\bmu_adbms1818.c</FilePath>
</File> </File>
<File>
<FileName>version_manager.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\version_manager.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
@ -1818,16 +1818,16 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\app\statistic_manager.c</FilePath> <FilePath>..\app\statistic_manager.c</FilePath>
</File> </File>
<File>
<FileName>version_manager.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\version_manager.c</FilePath>
</File>
<File> <File>
<FileName>bmu_adbms1818.c</FileName> <FileName>bmu_adbms1818.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\app\bmu_adbms1818.c</FilePath> <FilePath>..\app\bmu_adbms1818.c</FilePath>
</File> </File>
<File>
<FileName>version_manager.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\version_manager.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>

File diff suppressed because it is too large Load Diff

View File

@ -714,8 +714,8 @@ uint16_t bcu_total_cfg_fill(uint16_t start_addr, uint8_t reg_num, uint8_t *buf)
case 3146: // 预充超时时间s case 3146: // 预充超时时间s
data = get_eeprom_data(kEep_PreChgTimeout_Count , (EepromDataType)(1 - (address % 2))); data = get_eeprom_data(kEep_PreChgTimeout_Count , (EepromDataType)(1 - (address % 2)));
break; break;
case 3147: // HV电压比例(% case 3147: // 预充电压比例(%
case 3148: // 预充电压比例(% case 3148: // 预充类型
data = get_eeprom_data(kEep_PreChgVoltType_Rate , (EepromDataType)(1 - (address % 2))); data = get_eeprom_data(kEep_PreChgVoltType_Rate , (EepromDataType)(1 - (address % 2)));
break; break;
case 3149: // 系统时间s case 3149: // 系统时间s

View File

@ -28,40 +28,60 @@ uint8_t drv_ads8688_spi_send_rev(uint8_t data)
// 返回TURE则说明初始化正常否则错误 // 返回TURE则说明初始化正常否则错误
bool drv_ads8688_Init(void) bool drv_ads8688_Init(void)
{ {
uint8_t i = 0; uint8_t i = 0, value = 0;
drv_spi_init(kSpiDev_2, kSpiFreq_Div256, kSpiMode_C0E1, SpiFrame_MSBFirst, kGpioType_ADC_Clk, kGpioType_ADC_Miso, kGpioType_ADC_Mosi); drv_spi_init(kSpiDev_2, kSpiFreq_Div256, kSpiMode_C0E1, SpiFrame_MSBFirst, kGpioType_ADC_Clk, kGpioType_ADC_Miso, kGpioType_ADC_Mosi);
//drv_ads8688_Reset();// hardware reset
drv_reset_ads8688();
OSTimeDly(20);
OSTimeDly(20);
drv_enter_standby_mode();
drv_enter_pwrdn_mode(); drv_enter_pwrdn_mode();
OSTimeDly(20); OSTimeDly(20);
drv_enter_standby_mode();
OSTimeDly(20); drv_set_ch_range(Channel_0_Input_Range,VREF_125_125);
drv_reset_ads8688(); drv_set_ch_range(Channel_1_Input_Range,VREF_125_125);
OSTimeDly(20); drv_set_ch_range(Channel_2_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_0_Input_Range,VREF_25_25); drv_set_ch_range(Channel_3_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_1_Input_Range,VREF_25_25); drv_set_ch_range(Channel_4_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_2_Input_Range,VREF_25_25); drv_set_ch_range(Channel_5_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_3_Input_Range,VREF_25_25);
drv_set_ch_range(Channel_4_Input_Range,VREF_25_25); //value = drv_ads8688_read_reg(Channel_0_Input_Range);
drv_set_ch_range(Channel_5_Input_Range,VREF_25_25);
drv_set_ch_pwrdn(Channel_6_Input_Range); drv_set_ch_pwrdn(Channel_6_Input_Range);
drv_set_ch_pwrdn(Channel_7_Input_Range); drv_set_ch_pwrdn(Channel_7_Input_Range);
drv_ads8688_write_reg(AUTO_SEQ_EN, 0x3F); #if ADC_AUTO_MODE
{
i = drv_ads8688_read_reg(AUTO_SEQ_EN); drv_ads8688_write_reg(AUTO_SEQ_EN, 0x3F);
i = drv_ads8688_read_reg(AUTO_SEQ_EN);
if (i != 0x3F) if (i != 0x3F)
{ {
return true; return true;
} }
else else
{ {
drv_enter_auto_rst_mode(); // ½øÈë×Ô¶¯É¨Ãèģʽ drv_enter_auto_rst_mode(); // ½øÈë×Ô¶¯É¨Ãèģʽ
OSTimeDly(20); OSTimeDly(20);
return false; return false;
} }
}
#else
{
drv_manual_chn_mode(MAN_Ch_0);
drv_manual_chn_mode(MAN_Ch_1);
drv_manual_chn_mode(MAN_Ch_2);
drv_manual_chn_mode(MAN_Ch_3);
drv_manual_chn_mode(MAN_Ch_4);
drv_manual_chn_mode(MAN_Ch_5);
return false;
}
#endif
} }
void drv_ads8688_Reset(void) // hardware reset void drv_ads8688_Reset(void) // hardware reset
@ -177,17 +197,16 @@ void drv_ads8688_write_reg(uint8_t Addr, uint8_t data)
} }
// Program Register读操作 // Program Register读操作
uint8_t drv_ads8688_read_reg(uint8_t Addr) uint16_t drv_ads8688_read_reg(uint8_t Addr)
{ {
uint8_t data = 0; uint8_t datah = 0,datal = 0;
drv_set_ads8688_cs(kGpioStatus_Low); drv_set_ads8688_cs(kGpioStatus_Low);
drv_ads8688_spi_send_rev(Addr << 1 | READ); drv_ads8688_spi_send_rev(Addr << 1 | READ);
data = drv_ads8688_spi_send_rev(0xFF); datah = drv_ads8688_spi_send_rev(0xFF);
data = drv_ads8688_spi_send_rev(0xFF); datal = drv_ads8688_spi_send_rev(0xFF);
drv_set_ads8688_cs(kGpioStatus_High); drv_set_ads8688_cs(kGpioStatus_High);
return data; return datal + (datah << 8);
} }
void drv_set_auto_scan_sequence(uint8_t seq) // 设置自动扫描序列通道 void drv_set_auto_scan_sequence(uint8_t seq) // 设置自动扫描序列通道

View File

@ -84,7 +84,8 @@ kGpioType_ADC_Cs
#define VREF_0_25 0X05 #define VREF_0_25 0X05
#define VREF_0_125 0X06 #define VREF_0_125 0X06
typedef struct #define ADC_AUTO_MODE 0
typedef struct
{ {
uint8_t cs; uint8_t cs;
SpiDev spi; SpiDev spi;
@ -112,7 +113,7 @@ void drv_enter_auto_rst_mode(void);
void drv_enter_auto_rst_mode_Data(uint16_t* outputdata, uint8_t chnum); void drv_enter_auto_rst_mode_Data(uint16_t* outputdata, uint8_t chnum);
void drv_ads8688_write_reg(uint8_t Addr,uint8_t data); void drv_ads8688_write_reg(uint8_t Addr,uint8_t data);
uint8_t drv_ads8688_read_reg(uint8_t Addr); uint16_t drv_ads8688_read_reg(uint8_t Addr);
void drv_set_auto_scan_sequence(uint8_t seq); void drv_set_auto_scan_sequence(uint8_t seq);
void drv_set_ch_pwrdn(uint8_t chn); void drv_set_ch_pwrdn(uint8_t chn);
void drv_set_ch_range(uint8_t ch,uint8_t range); void drv_set_ch_range(uint8_t ch,uint8_t range);