From 7b8a137768f244173209f115738366efa7878b2f Mon Sep 17 00:00:00 2001 From: yincheng.zhong <634916154@qq.com> Date: 星期五, 28 十月 2022 10:32:55 +0800 Subject: [PATCH] V1.36 1.增加UWB芯片电量检测 2.解决基站轮流丢包的问题。 --- Src/main.c | 95 +++++++++++++++++++++++++++++++++-------------- 1 files changed, 67 insertions(+), 28 deletions(-) diff --git a/Src/main.c b/Src/main.c index c704710..21dc8d0 100644 --- a/Src/main.c +++ b/Src/main.c @@ -188,7 +188,7 @@ if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) { nomove_count = 0; - bat_percent=Get_Battary(); + // bat_percent=Get_Battary(); if(state5v==0) { state5v=1; @@ -250,27 +250,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 +313,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)|35; + g_com_map[VERSION] = (1<<8)|36; active_flag = g_com_map[ACTIVE_INDEX]; module_power = g_com_map[POWER]; imu_enable=g_com_map[IMU_ENABLE]; @@ -390,6 +396,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,16 +457,16 @@ 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;; @@ -463,7 +502,7 @@ // } // LED_TR_BLINK;s - bat_percent=Get_Battary(); + if(bat_percent>15) { LED_TB_ON; Tag_App(); @@ -952,12 +991,12 @@ }else{ key_keeptime=0; } - if(nomove_count>STATIONARY_TIME) - { - stationary_flag = 1; - }else{ - stationary_flag = 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; -- Gitblit v1.9.3