forked from gary/BCU
2
0
Fork 0

bcu功能基本ok

This commit is contained in:
guzz 2025-03-01 16:33:40 +08:00
parent a6ddf7f43d
commit 6b4089ed1e
9 changed files with 1765 additions and 10091 deletions

View File

@ -283,42 +283,70 @@ uint32_t HighVolTrans(uint16_t voldata)
AdjustValue adIc_adjust_value[kAdIc_End];
uint16_t adIc_reg_map[kAdIc_End] = {MAN_Ch_0, MAN_Ch_1, MAN_Ch_2, MAN_Ch_3, MAN_Ch_4};
uint16_t zero_calc(uint16_t value)
{
if(value > 32700 && value < 32788)
{
return 0;
}
else if(value < 20)
{
return 0;
}
else
{
return value;
}
}
void get_ad_sample(void)
{
static uint16_t outputdata[16] = {0};
int32_t i =0;
uint16_t ad =0;
int32_t i =0,dir = 1;
//uint16_t ad =0;
uint16_t ad = 0,value = 0;
#if ADC_AUTO_MODE
//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;
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++)
{
//ad = drv_get_ads8688_ch_data(adIc_reg_map[i]);
//0漂处理
if(i == kAdIc_Cur)
{
outputdata[i] = zero_calc(outputdata[i]);
}
cur_hv_item.ad_buf[i][cur_hv_item.ad_buf_pos[i]++] = drv_ads8688_value(outputdata[i]);
ad = cur_hv_item.ad_avg[i] = kit_get_int32_avg_filter_max_min(cur_hv_item.ad_buf[i], ADCIC_SAMPLE_CNT);
cur_hv_item.ad_avg[i] = kit_get_int32_avg_filter_max_min(cur_hv_item.ad_buf[i], ADCIC_SAMPLE_CNT);
if(cur_hv_item.ad_avg[i] < 0)
{
dir = -1;
}
ad = KIT_ABS(cur_hv_item.ad_avg[i]);
if (i == kAdIc_HvIso)
{
//cur_hv_item.value[i] = HighVolTrans2(ad)/100;
bms_set_iso_volt_ad(kIsoVolt_Other, ad);
bms_set_iso_volt_ad(kIsoVolt_Other, dir * ad);
}
if(i == kAdIc_HvIsoNagtive)
{
@ -326,24 +354,26 @@ void get_ad_sample(void)
}
if (i == kAdIc_HvBat)
{
cur_hv_item.value[i] = (376 * ad * 512 * 10 / (0x01 << 15)) / 100; //单位是mv
cur_hv_item.value[i] = dir * (376 * ad * 512 * 10 / (0x01 << 15)) / 100; //单位是mv
bms_set_iso_volt_ad(kIsoVolt_TotalVolt, cur_hv_item.value[i]);
}
if(i == kAdIc_Hv1)
{
cur_hv_item.value[i] = (376 * ad * 512 * 10 / (0x01 << 15)) / 100; //单位是mv
cur_hv_item.value[i] = dir * (376 * ad * 512 * 10 / (0x01 << 15)) / 100; //单位是mv
}
if(i == kAdIc_Cur)
{
ad = ad - adIc_adjust_value[i].zero;
ad = (ad * 5120 * 10 / (0x01 << 15)) / 82; //单位是mv
//ad = ad - adIc_adjust_value[i].zero;
//ad = (ad * 5120 * 10 / (0x01 << 15)) / 82; //单位是mv
ad = (ad * 2560 * 10 * 100 / (0x01 << 15)) / 82; //单位是0.1 mv
// 防止eeprom中没有设置电压校准系数
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);
}
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 * dir;/// 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)

View File

@ -562,8 +562,8 @@ void bms_integral_soc(int32_t current, uint16_t base_time)
return;
// /*soc test add 2-19
current = 168;
soc_run_calibrate(168, base_time);
// current = 168;
// soc_run_calibrate(168, base_time);
// */
tmp_32u = kit_time_get_tick();
integral_time = kit_time_get_interval(sox_item.last_tick, tmp_32u);

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -139,7 +139,7 @@
</Flash1>
<bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3></Flash3>
<Flash3>"" ()</Flash3>
<Flash4></Flash4>
<pFcarmOut></pFcarmOut>
<pFcarmGrp></pFcarmGrp>

File diff suppressed because it is too large Load Diff

View File

@ -588,8 +588,8 @@ void SystemInit(void)
/* Configure the System clock source, PLL Multiplier and Divider factors,
AHB/APBx prescalers and Flash settings ----------------------------------*/
SetSysClock();
//SystemClock_Config();
//SetSysClock();
SystemClock_Config();
/* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */

View File

@ -518,8 +518,8 @@ void SystemInit(void)
/* Configure the System clock source, PLL Multiplier and Divider factors,
AHB/APBx prescalers and Flash settings ----------------------------------*/
SetSysClock();
//SystemClock_Config();
//SetSysClock();
SystemClock_Config();
/* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM

View File

@ -29,35 +29,41 @@ uint8_t drv_ads8688_spi_send_rev(uint8_t data)
bool drv_ads8688_Init(void)
{
uint8_t i = 0, value = 0;
drv_spi_init(kSpiDev_2, kSpiFreq_Div64, kSpiMode_C1E1, 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_reset_ads8688();
OSTimeDly(20);
OSTimeDly(20);
kit_time_dly_ms(20);
drv_enter_standby_mode();
kit_time_dly_ms(20);
//drv_enter_pwrdn_mode();
//OSTimeDly(20);
drv_ads8688_write_reg(AUTO_SEQ_EN, 0xFF);
kit_time_dly_ms(10);
drv_ads8688_write_reg(Feature_Select, 0x28);
kit_time_dly_ms(20);
drv_set_ch_range(Channel_0_Input_Range,VREF_125_125);
OSTimeDly(20);
drv_set_ch_range(Channel_1_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_2_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_2_Input_Range,VREF_0625_0625);
drv_set_ch_range(Channel_3_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_4_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_5_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_6_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_7_Input_Range,VREF_125_125);
//value = drv_ads8688_read_reg(Channel_0_Input_Range);
drv_set_ch_pwrdn(0xC0);
drv_set_ch_pwrdn(Channel_6_Input_Range);
drv_set_ch_pwrdn(Channel_7_Input_Range);
//
#if ADC_AUTO_MODE
{
drv_ads8688_write_reg(AUTO_SEQ_EN, 0x3F);
i = drv_ads8688_read_reg(AUTO_SEQ_EN);
if (i != 0x3F)
@ -128,7 +134,8 @@ void drv_reset_ads8688(void) //
// 退出此模式需执行AUTO_RST或者MAN_CH_n命令且需要等待至少20us以保证正常数据的AD转换
void drv_enter_standby_mode(void)
{
drv_ads8688_write_cmd_reg(STDBY);
//drv_ads8688_write_cmd_reg(STDBY);
drv_ads8688_write_cmd_reg(NO_OP);
}
// 进入PWR_DN模式且命令发送后CS立刻置高不读数据帧
@ -218,11 +225,13 @@ void drv_set_auto_scan_sequence(uint8_t seq) //
void drv_set_ch_pwrdn(uint8_t chn) // 设置通道n为Power Down
{
drv_ads8688_write_reg(0X02, chn);
}
void drv_set_ch_range(uint8_t ch, uint8_t range) // 设置各个通道的范围
{
drv_ads8688_write_reg(ch, range);
kit_time_dly_ms(20);
}
int16_t drv_ads8688_value(uint16_t value)