优化ADC

This commit is contained in:
stark1898y 2025-04-13 16:23:40 +08:00
parent f01da795ed
commit abc5ced7cb
4 changed files with 18 additions and 7 deletions

View File

@ -363,7 +363,7 @@ int main(void)
valve_switch_freq = valve_switch_on_freq; valve_switch_freq = valve_switch_on_freq;
VavleDect_Switch(); VavleDect_Switch();
#endif #endif
BSP_VAVLE_Init(); // BSP_VAVLE_Init();
ShowLed(); ShowLed();
BEEP_ON; BEEP_ON;

View File

@ -32,9 +32,9 @@ uint8_t BSP_ReadVbat(void)
// VBAT // VBAT
uint32_t CountBat = 0; uint32_t CountBat = 0;
ADC_InterBATSampInit(); ADC_InterBATSampInit();
DelayUs(1); DelayUs(50);
ADC_ExcutSingleConver(); ADC_ExcutSingleConver();
DelayUs(1); DelayUs(50);
for (i = 0; i < 20; i++) for (i = 0; i < 20; i++)
{ {
adcBuff[i] = ADC_ExcutSingleConver(); // 连续采样20次 adcBuff[i] = ADC_ExcutSingleConver(); // 连续采样20次
@ -55,7 +55,7 @@ uint8_t BSP_ReadVbat(void)
// PGA=-12db // PGA=-12db
// CountBat = CountBat * 1050 / 512 - (3 * 1050); // CountBat = CountBat * 1050 / 512 - (3 * 1050);
CountBat = CountBat * 2.05078125 - 3150; CountBat = CountBat * 2.05078125 - 3150;
uint8_t vbat = (uint8_t)(CountBat / 100); uint8_t vbat = (uint8_t)((CountBat + 50) / 100);
logDebug("AverageCountBat = %dmV, vbat = %d(100mV)", CountBat, vbat); logDebug("AverageCountBat = %dmV, vbat = %d(100mV)", CountBat, vbat);
//缩小到100mV //缩小到100mV

View File

@ -286,7 +286,7 @@ void KEY_ProcessLoop(void)
if (key_wakeup_flag) if (key_wakeup_flag)
{ {
// 阻止睡眠 // 阻止睡眠
BSP_BlockSleep(); // BSP_BlockSleep();
// BSP_RequestBoost(); // BSP_RequestBoost();
// 关按键中断 // 关按键中断

View File

@ -462,6 +462,17 @@ __HIGH_CODE
__attribute__((weak)) __attribute__((weak))
void HardFault_Handler(void) void HardFault_Handler(void)
{ {
uint32_t v_mepc,v_mcause,v_mtval;
printf("hardfault\n");
v_mepc=__get_MEPC();
v_mcause=__get_MCAUSE();
v_mtval=__get_MTVAL();
printf("mepc:%08x\n",v_mepc);
printf("mcause:%08x\n",v_mcause);
printf("mtval:%08x\n",v_mtval);
FLASH_ROM_SW_RESET(); FLASH_ROM_SW_RESET();
sys_safe_access_enable(); sys_safe_access_enable();
R16_INT32K_TUNE = 0xFFFF; R16_INT32K_TUNE = 0xFFFF;