From 77d70d856aa5f5afb114379e2a23c7b6224b7535 Mon Sep 17 00:00:00 2001 From: yincheng.zhong <634916154@qq.com> Date: 星期四, 03 十一月 2022 10:13:05 +0800 Subject: [PATCH] V1.38 1.修改电量检测逻辑 2.修改UWB冲突避免逻辑 3.优化代码节省电量 功耗测试: 0hz 0.07ma 1hz 0.8ma 2hz 1.5ma 5hz 3.5ma 10hz 7.1ma --- Src/main.c | 200 ++++++++++++++++++++++--------------------------- 1 files changed, 91 insertions(+), 109 deletions(-) diff --git a/Src/main.c b/Src/main.c index 497bc01..50d3684 100644 --- a/Src/main.c +++ b/Src/main.c @@ -75,7 +75,7 @@ static void MX_LPTIM1_Init(void); static void MX_USART1_UART_Init(void); static void MX_SPI1_Init(void); -static void MX_ADC_Init(void); +void MX_ADC_Init(void); static void MX_DMA_Init(void); static void MX_TIM2_Init(void); /* USER CODE BEGIN PFP */ @@ -115,80 +115,17 @@ float motor_keeptime; void IdleTask(void) {u16 current_time; - - UART_CheckReceive(); - UART_CheckSend(); - if(huart1.Instance->ISR&USART_ISR_FE) { SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader } -//if(!HAL_GPIO_ReadPin(PWR_ON_GPIO_Port,PWR_ON_Pin)) -//{ -// LED_TR_ON; -// LED_TB_OFF; -//}else{ -// LED_TR_OFF; - current_time=GetLPTime(); - //motor_state=2; -// if(g_com_map[MOTOR_ONTIME]>0) -// { -// g_com_map[MOTOR_ONTIME]--; -// motor_state = 1; -// } -if(0)//g_com_map[MOTOR_ENABLE]) -{ - - - switch(motor_state) - {case 0: - if(hardware_type==NSH1) - {MOTOR_OFF; - }else if(hardware_type==GP) - { - HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3); - } - break; - case 1: - if(current_time<MOTOR_ONTIME) - { - if(hardware_type==NSH1) - {MOTOR_ON; - }else if(hardware_type==GP) - { - HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3); - } - }else{ - if(hardware_type==NSH1) - {MOTOR_OFF; - }else if(hardware_type==GP) - { - HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3); - } - } - break; - case 2: - if(hardware_type==NSH1) - {MOTOR_ON; - }else if(hardware_type==GP) - { - HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3); - } - break; - case 3: - if(hardware_type==NSH1) - {MOTOR_OFF; - }else if(hardware_type==GP) - { - HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3); - } - break; - } -} if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) { + + UART_CheckReceive(); + UART_CheckSend(); nomove_count = 0; - bat_percent=Get_Battary(); + // bat_percent=Get_Battary(); if(state5v==0) { state5v=1; @@ -250,27 +187,33 @@ u16 total_slotnum,current_slotnum; extern int32_t offsettimeus; - +u16 last_lpcount = 0; void SetNextPollTime(u16 time) { int32_t lpcount,lptime,target_time; - if(current_slotnum>=total_slotnum) - current_slotnum-=total_slotnum; - - target_time=((current_slotnum*g_com_map[COM_INTERVAL])+time)*1000; - //if(target_time<90000) - { - lptime=target_time-offsettimeus; - lpcount = lptime/LPTIMER_LSB; - if(lpcount>LPTIMER_1S_COUNT) - lpcount-=LPTIMER_1S_COUNT; - if(lpcount<0) - { - lpcount+=LPTIMER_1S_COUNT; - } +// if(current_slotnum>=total_slotnum) +// current_slotnum-=total_slotnum; +// +// target_time=((current_slotnum*g_com_map[COM_INTERVAL])+time)*1000; +// //if(target_time<90000) +// { +// lptime=target_time-offsettimeus; +// lpcount = lptime/LPTIMER_LSB; +// if(lpcount>LPTIMER_1S_COUNT) +// lpcount-=LPTIMER_1S_COUNT; +// if(lpcount<0) +// { +// lpcount+=LPTIMER_1S_COUNT; +// } + lpcount = last_lpcount+g_com_map[COM_INTERVAL]*32.768; + while(lpcount>LPTIMER_1S_COUNT) + { + lpcount-=LPTIMER_1S_COUNT; + } + last_lpcount = lpcount; __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount); -} + } void HardWareTypeDiffConfig(void) @@ -307,7 +250,7 @@ hardware_pici = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+2); hardware_type = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+4); //deca_sleep(1000); - g_com_map[VERSION] = (1<<8)|30; + g_com_map[VERSION] = (1<<8)|38; active_flag = g_com_map[ACTIVE_INDEX]; module_power = g_com_map[POWER]; imu_enable=g_com_map[IMU_ENABLE]; @@ -335,6 +278,7 @@ // g_com_map[MAX_REPORT_ANC_NUM]=1; // g_com_map[NOMOVESLEEP_TIME]=10; #endif + // g_com_map[COM_INTERVAL]=100; if(g_com_map[COM_INTERVAL]==0) { g_com_map[COM_INTERVAL]=100; @@ -390,6 +334,39 @@ * @brief The application entry point. * @retval int */ +uint16_t temp2; +float dw_vbat,last_vbat; +uint8_t Get_Battary_UWB(void) +{ + static uint8_t first = 1; + static float last_value = 100; + static uint16_t bat_count = 0; + //if(bat_count++%600==0) + { + temp2=dwt_readtempvbat(1); + dw_vbat=(float)((temp2&0xff)-173)/173+3.3; + if(fabs(dw_vbat-dw_vbat)>0.2) + { + last_vbat = dw_vbat; + return last_value; + } + last_vbat = dw_vbat; + if(dw_vbat>=3.0) + { + if(first) + { + first = 0; + last_value =(dw_vbat-3.0)*167;//(bat_volt-3.5)/0.6*100 + } + last_value = 0.9*last_value + (dw_vbat-3.0)*16.7; + if(last_value>100) + last_value = 100; + if(last_value<0) + last_value = 0; + } + } + return last_value; +} int main(void) { /* USER CODE BEGIN 1 */ @@ -418,25 +395,24 @@ MX_DMA_Init(); MX_USART1_UART_Init(); MX_SPI1_Init(); - MX_ADC_Init(); + // MX_ADC_Init(); // MX_TIM2_Init(); /* USER CODE BEGIN 2 */ LED_LG_ON; Program_Init(); - LIS3DH_Data_Init(); +// LIS3DH_Data_Init(); Dw1000_Init(); Dw1000_App_Init(); - HardWareTypeDiffConfig(); +// HardWareTypeDiffConfig(); dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN); dwt_entersleep(); - waitusart_timer=tag_frequency*USART_KEEPWAKE_TIME;; DW_DISABLE; if(HAL_UART_Receive_DMA(&huart1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE)) { Error_Handler(); } -// HAL_Delay(2000); + HAL_Delay(2000); // mcu_sleep(); //LED0_BLINK; // SystemPower_Config(); @@ -463,7 +439,7 @@ // } // LED_TR_BLINK;s - bat_percent=Get_Battary(); + if(bat_percent>15) { LED_TB_ON; Tag_App(); @@ -479,7 +455,7 @@ { waitusart_timer--; } - if(m_bEUARTTxEn==0&&waitusart_timer==0&&(motor_state==0||motor_state==3)) + if(m_bEUARTTxEn==0&&waitusart_timer==0) { #ifndef DEBUG_MODE if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) @@ -559,7 +535,12 @@ * @param None * @retval None */ -static void MX_ADC_Init(void) +void MX_ADC_DeInit(void) +{ + HAL_ADC_DeInit(&hadc); + HAL_ADCEx_DisableVREFINT(); +} +void MX_ADC_Init(void) { /* USER CODE BEGIN ADC_Init 0 */ @@ -596,14 +577,15 @@ } /** Configure for the selected ADC regular channel to be converted. */ - sConfig.Channel = ADC_CHANNEL_1; + sConfig.Channel = ADC_CHANNEL_VREFINT; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN ADC_Init 2 */ -HAL_ADCEx_Calibration_Start(&hadc,ADC_SINGLE_ENDED); + HAL_ADCEx_EnableVREFINT(); + HAL_ADCEx_Calibration_Start(&hadc,ADC_SINGLE_ENDED); /* USER CODE END ADC_Init 2 */ } @@ -952,20 +934,20 @@ }else{ key_keeptime=0; } - if(nomove_count>STATIONARY_TIME) - { - stationary_flag = 1; - }else{ - stationary_flag = 0; - } -if(nomove_count>=nomovesleeptime-1&&imu_enable) - { - tx_near_msg[TAGSTATE] = tx_near_msg[TAGSTATE]|GOINGSLEEPBIT; - } - if(nomove_count>nomovesleeptime&&imu_enable) - { - mcu_sleep(); - } +// if(nomove_count>STATIONARY_TIME) +// { +// stationary_flag = 1; +// }else{ +// stationary_flag = 0; +// } +//if(nomove_count>=nomovesleeptime-1&&imu_enable) +// { +// tx_near_msg[TAGSTATE] = tx_near_msg[TAGSTATE]|GOINGSLEEPBIT; +// } +// if(nomove_count>nomovesleeptime&&imu_enable) +// { +// mcu_sleep(); +// } } /* USER CODE END 4 */ -- Gitblit v1.9.3