From b98ba4a635e5a213edb43ca2d76f6acfca7159fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B7=E5=BA=8A=E5=B0=B1=E7=8A=AF=E5=9B=B0?= <11730503+psx123456@user.noreply.gitee.com> Date: Sat, 7 Dec 2024 17:52:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E8=A6=81=E4=B8=BA=E6=B7=BB=E5=8A=A0ad?= =?UTF-8?q?c=E9=87=87=E9=9B=86+=E4=B8=80=E4=BA=9B=E5=A4=96=E8=AE=BE?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .mxproject | 16 +- .vscode/settings.json | 8 +- APP/application/Inc/comm.h | 1 + APP/application/Src/chargControl.c | 10 +- APP/application/Src/start.c | 2 + APP/businessLogic/Inc/Init.h | 11 + APP/businessLogic/Inc/abnormalManage.h | 15 + APP/businessLogic/Inc/parameter.h | 63 +++- APP/businessLogic/Src/Init.c | 21 ++ APP/businessLogic/Src/abnormalManage.c | 25 ++ APP/businessLogic/Src/bl_chargControl.c | 12 +- APP/businessLogic/Src/bl_comm.c | 3 - APP/businessLogic/Src/inFlash.c | 6 +- APP/businessLogic/Src/parameter.c | 403 ++++++++++++++++++++- APP/functionalModule/Inc/FM_GPIO.h | 3 + APP/functionalModule/Inc/FM_TIM.h | 4 +- APP/functionalModule/Inc/capture.h | 33 ++ APP/functionalModule/Src/FM_GPIO.c | 30 ++ APP/functionalModule/Src/FM_TIM.c | 29 +- APP/functionalModule/Src/capture.c | 446 ++++++++++++++++++++++++ APP/hardwareDriver/Inc/HD_ADC.h | 20 ++ APP/hardwareDriver/Inc/HD_TIM.h | 2 + APP/hardwareDriver/Src/HD_ADC.c | 61 ++++ APP/hardwareDriver/Src/HD_TIM.c | 32 +- Core/Inc/stm32g4xx_it.h | 2 + Core/Inc/tim.h | 6 + Core/Src/main.c | 2 + Core/Src/stm32g4xx_it.c | 40 ++- Core/Src/tim.c | 123 ++++++- EWARM/chargeController.ewd | 72 ++-- EWARM/chargeController.ewp | 15 +- EWARM/chargeController.ewt | 9 + chargeController.ioc | 32 +- tools/RingQueue/ring_queue.c | 30 +- 34 files changed, 1474 insertions(+), 113 deletions(-) create mode 100644 APP/businessLogic/Inc/Init.h create mode 100644 APP/businessLogic/Inc/abnormalManage.h create mode 100644 APP/businessLogic/Src/Init.c create mode 100644 APP/businessLogic/Src/abnormalManage.c create mode 100644 APP/functionalModule/Inc/capture.h create mode 100644 APP/functionalModule/Src/capture.c create mode 100644 APP/hardwareDriver/Inc/HD_ADC.h create mode 100644 APP/hardwareDriver/Src/HD_ADC.c diff --git a/.mxproject b/.mxproject index 377981b..dbb9a2a 100644 --- a/.mxproject +++ b/.mxproject @@ -1,3 +1,11 @@ +[PreviousLibFiles] +LibFiles=Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_def.h;Drivers\STM32G4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_bus.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_system.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_utils.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_crs.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ramfunc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dmamux.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_spi.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_spi.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_spi_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_uart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_usart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_lpuart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_uart_ex.h;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_adc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ramfunc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_gpio.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_exti.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cortex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart_ex.c;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_def.h;Drivers\STM32G4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_bus.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_system.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_utils.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_crs.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ramfunc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dmamux.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_spi.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_spi.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_spi_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_uart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_usart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_lpuart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_uart_ex.h;Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g431xx.h;Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g4xx.h;Drivers\CMSIS\Device\ST\STM32G4xx\Include\system_stm32g4xx.h;Drivers\CMSIS\Device\ST\STM32G4xx\Include\system_stm32g4xx.h;Drivers\CMSIS\Device\ST\STM32G4xx\Source\Templates\system_stm32g4xx.c;Drivers\CMSIS\Include\cmsis_armcc.h;Drivers\CMSIS\Include\cmsis_armclang.h;Drivers\CMSIS\Include\cmsis_armclang_ltm.h;Drivers\CMSIS\Include\cmsis_compiler.h;Drivers\CMSIS\Include\cmsis_gcc.h;Drivers\CMSIS\Include\cmsis_iccarm.h;Drivers\CMSIS\Include\cmsis_version.h;Drivers\CMSIS\Include\core_armv81mml.h;Drivers\CMSIS\Include\core_armv8mbl.h;Drivers\CMSIS\Include\core_armv8mml.h;Drivers\CMSIS\Include\core_cm0.h;Drivers\CMSIS\Include\core_cm0plus.h;Drivers\CMSIS\Include\core_cm1.h;Drivers\CMSIS\Include\core_cm23.h;Drivers\CMSIS\Include\core_cm3.h;Drivers\CMSIS\Include\core_cm33.h;Drivers\CMSIS\Include\core_cm35p.h;Drivers\CMSIS\Include\core_cm4.h;Drivers\CMSIS\Include\core_cm7.h;Drivers\CMSIS\Include\core_sc000.h;Drivers\CMSIS\Include\core_sc300.h;Drivers\CMSIS\Include\mpu_armv7.h;Drivers\CMSIS\Include\mpu_armv8.h;Drivers\CMSIS\Include\tz_context.h; + +[PreviousUsedIarFiles] +SourceFiles=..\Core\Src\main.c;..\Core\Src\gpio.c;..\Core\Src\adc.c;..\Core\Src\dma.c;..\Core\Src\spi.c;..\Core\Src\tim.c;..\Core\Src\usart.c;..\Core\Src\stm32g4xx_it.c;..\Core\Src\stm32g4xx_hal_msp.c;..\Core\Src\stm32g4xx_hal_timebase_tim.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_adc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ramfunc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_gpio.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_exti.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cortex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart_ex.c;..\Drivers\CMSIS\Device\ST\STM32G4xx\Source\Templates\system_stm32g4xx.c;..\Core\Src\system_stm32g4xx.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_adc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ramfunc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_gpio.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_exti.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cortex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart_ex.c;..\Drivers\CMSIS\Device\ST\STM32G4xx\Source\Templates\system_stm32g4xx.c;..\Core\Src\system_stm32g4xx.c;;; +HeaderPath=..\Drivers\STM32G4xx_HAL_Driver\Inc;..\Drivers\STM32G4xx_HAL_Driver\Inc\Legacy;..\Drivers\CMSIS\Device\ST\STM32G4xx\Include;..\Drivers\CMSIS\Include;..\Middlewares\ST\ARM\DSP\Inc;..\Core\Inc; +CDefines=USE_HAL_DRIVER;STM32G431xx;USE_HAL_DRIVER;USE_HAL_DRIVER; + [PreviousGenFiles] AdvancedFolderStructure=true HeaderFileListSize=9 @@ -28,9 +36,6 @@ SourceFolderListSize=1 SourcePath#0=..\Core\Src SourceFiles=; -[PreviousLibFiles] -LibFiles=Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_def.h;Drivers\STM32G4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_bus.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_system.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_utils.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_crs.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ramfunc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dmamux.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_spi.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_spi.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_spi_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_uart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_usart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_lpuart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_uart_ex.h;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_adc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ramfunc.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_gpio.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_exti.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cortex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi_ex.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart.c;Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart_ex.c;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_tim_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_adc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_adc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_def.h;Drivers\STM32G4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_rcc_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_bus.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_rcc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_system.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_utils.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_crs.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_flash_ramfunc.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_gpio_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_gpio.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_exti.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_dma_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dma.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_dmamux.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_pwr_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_pwr.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_cortex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_spi.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_spi.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_spi_ex.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_tim.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_uart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_usart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_ll_lpuart.h;Drivers\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_uart_ex.h;Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g431xx.h;Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g4xx.h;Drivers\CMSIS\Device\ST\STM32G4xx\Include\system_stm32g4xx.h;Drivers\CMSIS\Device\ST\STM32G4xx\Include\system_stm32g4xx.h;Drivers\CMSIS\Device\ST\STM32G4xx\Source\Templates\system_stm32g4xx.c;Drivers\CMSIS\Include\cmsis_armcc.h;Drivers\CMSIS\Include\cmsis_armclang.h;Drivers\CMSIS\Include\cmsis_armclang_ltm.h;Drivers\CMSIS\Include\cmsis_compiler.h;Drivers\CMSIS\Include\cmsis_gcc.h;Drivers\CMSIS\Include\cmsis_iccarm.h;Drivers\CMSIS\Include\cmsis_version.h;Drivers\CMSIS\Include\core_armv81mml.h;Drivers\CMSIS\Include\core_armv8mbl.h;Drivers\CMSIS\Include\core_armv8mml.h;Drivers\CMSIS\Include\core_cm0.h;Drivers\CMSIS\Include\core_cm0plus.h;Drivers\CMSIS\Include\core_cm1.h;Drivers\CMSIS\Include\core_cm23.h;Drivers\CMSIS\Include\core_cm3.h;Drivers\CMSIS\Include\core_cm33.h;Drivers\CMSIS\Include\core_cm35p.h;Drivers\CMSIS\Include\core_cm4.h;Drivers\CMSIS\Include\core_cm7.h;Drivers\CMSIS\Include\core_sc000.h;Drivers\CMSIS\Include\core_sc300.h;Drivers\CMSIS\Include\mpu_armv7.h;Drivers\CMSIS\Include\mpu_armv8.h;Drivers\CMSIS\Include\tz_context.h; - [ThirdPartyIp] ThirdPartyIpNumber=1 ThirdPartyIpName#0=STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0 @@ -39,8 +44,3 @@ ThirdPartyIpName#0=STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0 library=..\Middlewares\ST\ARM\DSP\Lib\iar_cortexM4lf_math.a; header=..\Middlewares\ST\ARM\DSP\Inc\arm_math.h; -[PreviousUsedIarFiles] -SourceFiles=..\Core\Src\main.c;..\Core\Src\gpio.c;..\Core\Src\adc.c;..\Core\Src\dma.c;..\Core\Src\spi.c;..\Core\Src\tim.c;..\Core\Src\usart.c;..\Core\Src\stm32g4xx_it.c;..\Core\Src\stm32g4xx_hal_msp.c;..\Core\Src\stm32g4xx_hal_timebase_tim.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_adc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ramfunc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_gpio.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_exti.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cortex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart_ex.c;..\Drivers\CMSIS\Device\ST\STM32G4xx\Source\Templates\system_stm32g4xx.c;..\Core\Src\system_stm32g4xx.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_adc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ramfunc.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_gpio.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_exti.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cortex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi_ex.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart.c;..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart_ex.c;..\Drivers\CMSIS\Device\ST\STM32G4xx\Source\Templates\system_stm32g4xx.c;..\Core\Src\system_stm32g4xx.c;;; -HeaderPath=..\Drivers\STM32G4xx_HAL_Driver\Inc;..\Drivers\STM32G4xx_HAL_Driver\Inc\Legacy;..\Drivers\CMSIS\Device\ST\STM32G4xx\Include;..\Drivers\CMSIS\Include;..\Middlewares\ST\ARM\DSP\Inc;..\Core\Inc; -CDefines=USE_HAL_DRIVER;STM32G431xx;USE_HAL_DRIVER;USE_HAL_DRIVER; - diff --git a/.vscode/settings.json b/.vscode/settings.json index 89e87ea..a43d3e5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,12 @@ "fm_tim.h": "c", "timesliceoffset.h": "c", "fm_gpio.h": "c", - "pdebug.h": "c" + "pdebug.h": "c", + "start.h": "c", + "bl_comm.h": "c", + "capture.h": "c", + "arm_math.h": "c", + "abnormalmanage.h": "c", + "stm32g431xx.h": "c" } } \ No newline at end of file diff --git a/APP/application/Inc/comm.h b/APP/application/Inc/comm.h index ccbd4ee..4953f60 100644 --- a/APP/application/Inc/comm.h +++ b/APP/application/Inc/comm.h @@ -3,6 +3,7 @@ #define APP_COMM_H_ #include "comm_types.h" +#include "bl_comm.h" void uart_comm(void); diff --git a/APP/application/Src/chargControl.c b/APP/application/Src/chargControl.c index c8a42f5..5c49ca4 100644 --- a/APP/application/Src/chargControl.c +++ b/APP/application/Src/chargControl.c @@ -3,6 +3,12 @@ #include "parameter.h" #include "comm_types.h" +/** + * @brief 完成充电控制 + * @param + * @retval + * + */ void chargControl(void) { getCVData(); @@ -10,11 +16,11 @@ void chargControl(void) chargControlMode(); - if (g_otherParameter.MPPT_Mode == noWork) { + if (getMPPT_Mode() == noWork) { return; } - if (g_otherParameter.batteryState) { + if (getBatteryState()) { BatteryChargControl(); } else { noBatteryChargControl(); diff --git a/APP/application/Src/start.c b/APP/application/Src/start.c index 52092e4..1ca98a1 100644 --- a/APP/application/Src/start.c +++ b/APP/application/Src/start.c @@ -1,6 +1,8 @@ #include "start.h" #include "inFlash.h" +#include "TimeSliceOffset.h" + void start(void) { diff --git a/APP/businessLogic/Inc/Init.h b/APP/businessLogic/Inc/Init.h new file mode 100644 index 0000000..b3948db --- /dev/null +++ b/APP/businessLogic/Inc/Init.h @@ -0,0 +1,11 @@ + +#ifndef BL_PARAMETER_H_ +#define BL_PARAMETER_H_ + + + +void Init(void); + + + +#endif diff --git a/APP/businessLogic/Inc/abnormalManage.h b/APP/businessLogic/Inc/abnormalManage.h new file mode 100644 index 0000000..e3dfcfb --- /dev/null +++ b/APP/businessLogic/Inc/abnormalManage.h @@ -0,0 +1,15 @@ + +#ifndef BL_ABNORMAL_MANAGE_H_ +#define BL_ABNORMAL_MANAGE_H_ + +#include "FM_TIM.h" + + + + +void checkAbnormal(void); + + + + +#endif \ No newline at end of file diff --git a/APP/businessLogic/Inc/parameter.h b/APP/businessLogic/Inc/parameter.h index 02d6dbc..0e87bb4 100644 --- a/APP/businessLogic/Inc/parameter.h +++ b/APP/businessLogic/Inc/parameter.h @@ -1,12 +1,12 @@ - #ifndef BL_PARAMETER_H_ #define BL_PARAMETER_H_ #include "main.h" +#include "comm_types.h" #define softVer "SV01_24101501" -#pragma pack(push,1) +// #pragma pack(push,1) /* 主要有配置文件读取出来的数据 */ typedef struct _config_parameter{ @@ -30,10 +30,10 @@ typedef struct _config_parameter{ uint32_t collectOpenCircuitVoltageTime; /* 开路电压采集时间间隔 */ /* SL */ - uint8_t address[7]; /* 地址 */ uint16_t Access_Node_Type; /* 接入节点类型 */ uint16_t Communication_Methods; /* 通信方式 */ uint16_t Registration_Status; /* 注册状态 */ + uint8_t address[7]; /* 地址 */ uint8_t startFlagSL[2]; /* 起始标志 */ uint8_t endFlagSL; /* 结束标志 */ @@ -51,7 +51,6 @@ typedef struct _config_parameter{ uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */ } config_parameter; extern config_parameter g_cfgParameter; - typedef struct _otherParameter{ float Battery_Voltage; /* 电池电压 (V) */ float Output_Voltage; /* 输出电压 */ @@ -62,26 +61,56 @@ typedef struct _otherParameter{ float HighSideMos_Temperature; /* 高端mos的温度 (°C) */ float Solar_In_Circuit_Voltage; /* 太阳能板输入电压 (V) */ - float Charg_BatteryCurrent; /* 电池充电电流(流向电池) (A) */ float totalElectricityConsumption; /* 总电量消耗(W*H) */ float totalChargCapacity; /* 总充电电量(W*H) */ float SOC; /* 剩余电量 */ - uint16_t chargMos_State; /* 充电开关状态 */ - uint16_t DischargMos_State; /* 放电mos的状态 */ - uint16_t MPPT_Mode; /* 工作模式 */ + uint16_t MPPT_Mode; /* 工作模式 */ - uint8_t versionInformation[13]; /* 软件版本信息 */ + uint8_t versionInformation[13]; /* 软件版本信息 */ - uint8_t batteryState; /* 有无电池(估计) */ - - - - - - float dutyRatio; /* 占空比 */ }otherParameter; -extern otherParameter g_otherParameter; + +// #pragma pack(pop) + + +BOOL getBatteryState(void); +void setBatteryState(BOOL state); +float getDutyRatio(void); +void setDutyRatio(float DutyRatio); +void setDutyRatioToZero(void); + +float getBatteryVoltage(void); +void setBatteryVoltage(void); +float getOutputVoltage(void); +void setOutputVoltage(void); +float getChargCurrent(void); +void setChargCurrent(void); +float getDischargCurrent(void); +void setDischargCurrent(void); +float getInputVoltage(void); +void setInputVoltage(void); +float getSolarOpenCircuitVoltage(void); +void setSolarOpenCircuitVoltage(void); +float getHighSideMosTemperature(void); +void setHighSideMosTemperature(void); +float getSolarInCircuitVoltage(void); +void setSolarInCircuitVoltage(void); +float getTotalElectricityConsumption(void); +void setTotalElectricityConsumption(void); +void totalElectricityConsumptionInt(float totalPower); +float getTotalChargCapacity(void); +void setTotalChargCapacity(void); +void totalChargCapacityInt(float totalPower); +float getSOC(void); +void setSOC(void); +int getMPPT_Mode(void); +void setMPPT_Mode(int MPPT_Mode); +float getChargBatteryCurrent(void); +BOOL getChargMosState(void); +void setChargMosState(BOOL state); +BOOL getDischargMosState(void); +uint8_t *getVersionInformation(void); diff --git a/APP/businessLogic/Src/Init.c b/APP/businessLogic/Src/Init.c new file mode 100644 index 0000000..0d52924 --- /dev/null +++ b/APP/businessLogic/Src/Init.c @@ -0,0 +1,21 @@ + +#include "Init.h" +#include "capture.h" +#include "FM_GPIO.h" +#include "inFlash.h" +#include "parameter.h" +#include "FM_GPIO.h" +#include "FM_TIM.h" + +void Init(void) +{ + config_info_start(); + ADC_Capture_Init(); + proportionalInt(getMPPT_Mode()); + + FM_GPIO_Init(); + tim_Init(); + + + +} diff --git a/APP/businessLogic/Src/abnormalManage.c b/APP/businessLogic/Src/abnormalManage.c new file mode 100644 index 0000000..cc34350 --- /dev/null +++ b/APP/businessLogic/Src/abnormalManage.c @@ -0,0 +1,25 @@ + +#include "abnormalManage.h" +#include "parameter.h" +#include "capture.h" + + + + +void checkAbnormal(void) +{ + /* 滤波 */ + adcCaptureFir(); + + /* 转换 */ + setChargCurrent(); + setDischargCurrent(); + setOutputVoltage(); + setSolarInCircuitVoltage(); + + /* 判断异常状态 */ + + + +} + diff --git a/APP/businessLogic/Src/bl_chargControl.c b/APP/businessLogic/Src/bl_chargControl.c index c6a3273..ccd7a09 100644 --- a/APP/businessLogic/Src/bl_chargControl.c +++ b/APP/businessLogic/Src/bl_chargControl.c @@ -86,19 +86,19 @@ void chargControlMode(void) { if (stopChargConditions()) { stopChargWork(); - g_otherParameter.MPPT_Mode = noWork; + setMPPT_Mode(noWork); } if (floatChargConditions()) { - g_otherParameter.MPPT_Mode = floatCharg; + setMPPT_Mode(floatCharg); } if (mpptChargConditions()) { - g_otherParameter.MPPT_Mode = MPPT; + setMPPT_Mode(MPPT); } if (constantVChargConditions()) { - g_otherParameter.MPPT_Mode = constantVoltage; + setMPPT_Mode(constantVoltage); } } @@ -177,7 +177,7 @@ void constantVoltageCharge(void) */ void BatteryChargControl(void) { - switch(g_otherParameter.MPPT_Mode) { + switch(getMPPT_Mode()) { case MPPT: mpptCharge(); @@ -192,7 +192,7 @@ void BatteryChargControl(void) break; default: - g_otherParameter.MPPT_Mode = noWork; + setMPPT_Mode(noWork); stopChargWork(); break; } diff --git a/APP/businessLogic/Src/bl_comm.c b/APP/businessLogic/Src/bl_comm.c index 5b4655a..373eaa9 100644 --- a/APP/businessLogic/Src/bl_comm.c +++ b/APP/businessLogic/Src/bl_comm.c @@ -5,9 +5,6 @@ - - - void GW485_comm(void) { diff --git a/APP/businessLogic/Src/inFlash.c b/APP/businessLogic/Src/inFlash.c index 263990a..9b27191 100644 --- a/APP/businessLogic/Src/inFlash.c +++ b/APP/businessLogic/Src/inFlash.c @@ -218,8 +218,10 @@ void config_info_start(void) g_cfgParameter.loopImpedance = 0; saveLoopImpedance(&g_cfgParameter.loopImpedance); } - readtotalElectricityConsumption(&g_otherParameter.totalElectricityConsumption); - readtotalChargCapacity(&g_otherParameter.totalChargCapacity); + readtotalElectricityConsumption(&fTemp); + totalElectricityConsumptionInt(fTemp); + readtotalChargCapacity(&fTemp); + totalChargCapacityInt(fTemp); } /** diff --git a/APP/businessLogic/Src/parameter.c b/APP/businessLogic/Src/parameter.c index 1355057..9ebff0b 100644 --- a/APP/businessLogic/Src/parameter.c +++ b/APP/businessLogic/Src/parameter.c @@ -1,7 +1,408 @@ #include "parameter.h" +#include "FM_TIM.h" +#include "FM_GPIO.h" +#include "capture.h" + + + config_parameter g_cfgParameter = {0}; -otherParameter g_otherParameter = {0}; +static otherParameter g_otherParameter = {0}; + +static BOOL batteryState = FALSE; /* 有无电池(估计) */ +static float dutyRatio; /* 占空比 */ + +/** + * @brief 获取电池状态 + * @param + * @retval batteryState电池状态 FALSE:无 + * TRUE: 有 + */ +BOOL getBatteryState(void) +{ + return batteryState; +} + +/** + * @brief 设置电池状态 + * @param state 电池状态 + * @retval + * + */ +void setBatteryState(BOOL state) +{ + if (state != TRUE && state != FALSE) { + return; + } + batteryState = state; +} + +/** + * @brief 获取占空比大小 + * @param + * @retval dutyRatio 占空比 + */ +float getDutyRatio(void) +{ + return dutyRatio; +} + +/** + * @brief 设置占空比大小,在一个范围内,不能设置为0,1等 + * @param dutyRatio 占空比 + * @retval + */ +void setDutyRatio(float DutyRatio) +{ + if (DutyRatio > 0.9f) { + dutyRatio = 0.9f; + } + else if (DutyRatio < 0.05f) { + dutyRatio = 0.05f; + } + else { + dutyRatio = DutyRatio; + } + set_pwmDutyRatio(dutyRatio); +} + +/** + * @brief 设置占空比大小为0,同时关闭pwm下桥的输出 + * @param + * @retval + */ +void setDutyRatioToZero(void) +{ + EN_PWMOUT_Diseable(); + dutyRatio = 0; + set_pwmDutyRatio(dutyRatio); +} + +/** + * @brief 得到电池电压 + * @param + * @retval 电池电压 + */ +float getBatteryVoltage(void) +{ + return g_otherParameter.Battery_Voltage; +} + +/** + * @brief 设置电池电压 + * @param + * @retval + */ +void setBatteryVoltage(void) +{ + g_otherParameter.Battery_Voltage = g_otherParameter.Output_Voltage + + getChargBatteryCurrent() * g_cfgParameter.loopImpedance; +} + +/** + * @brief 得到输出电压 + * @param + * @retval 输出电压 + */ +float getOutputVoltage(void) +{ + return g_otherParameter.Output_Voltage; +} + +/** + * @brief 设置输出电压 + * @param + * @retval + */ +void setOutputVoltage(void) +{ + g_otherParameter.Output_Voltage = get_PV_VOLT_OUT() ; +} + +/** + * @brief 得到充电电流 + * @param + * @retval 充电电流 + */ +float getChargCurrent(void) +{ + return g_otherParameter.Charg_Current; +} + +/** + * @brief 设置充电电流 + * @param + * @retval + */ +void setChargCurrent(void) +{ + g_otherParameter.Charg_Current = get_CHG_CURR(); +} + +/** + * @brief 得到放电电流 + * @param + * @retval 放电电流 + */ +float getDischargCurrent(void) +{ + return g_otherParameter.Discharg_Current; +} + +/** + * @brief 设置放电电流 + * @param + * @retval + */ +void setDischargCurrent(void) +{ + g_otherParameter.Discharg_Current = get_DSG_CURR(); +} + +/** + * @brief 得到系统输入电压 + * @param + * @retval 系统输入电压 + */ +float getInputVoltage(void) +{ + return g_otherParameter.Input_Voltage; +} + +/** + * @brief 设置系统输入电压 + * @param + * @retval + */ +void setInputVoltage(void) +{ + g_otherParameter.Discharg_Current = get_PV_VOLT_IN1(); +} + +/** + * @brief 返回太阳能开路电压(不具备实时性) + * @param + * @retval 太阳能开路电压 + */ +float getSolarOpenCircuitVoltage(void) +{ + return g_otherParameter.Solar_Open_Circuit_Voltage; +} + +/** + * @brief 设置太阳能开路电压(特定情况下才能测量) + * @param + * @retval + */ +void setSolarOpenCircuitVoltage(void) +{ + g_otherParameter.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN(); +} + +/** + * @brief 返回mos管的温度 + * @param + * @retval mos管的温度 + */ +float getHighSideMosTemperature(void) +{ + return g_otherParameter.HighSideMos_Temperature; +} + +/** + * @brief 设置mos管温度 + * @param + * @retval + */ +void setHighSideMosTemperature(void) +{ + g_otherParameter.HighSideMos_Temperature = get_MOSFET_Temper(); +} + +/** + * @brief 返回太阳能板输出电压 + * @param + * @retval 太阳能板输出电压 + */ +float getSolarInCircuitVoltage(void) +{ + return g_otherParameter.Solar_In_Circuit_Voltage; +} + +/** + * @brief 设置太阳能板输出电压 + * @param + * @retval + */ +void setSolarInCircuitVoltage(void) +{ + g_otherParameter.Solar_In_Circuit_Voltage = get_PV1_VOLT_IN(); +} + +/** + * @brief 得到总用电量 + * @param + * @retval 总用电量 + */ +float getTotalElectricityConsumption(void) +{ + return g_otherParameter.totalElectricityConsumption; +} + +/** + * @brief 设置总用电量 + * @param + * @retval + */ +void setTotalElectricityConsumption(void) +{ + g_otherParameter.totalElectricityConsumption += g_otherParameter.Discharg_Current * g_otherParameter.Output_Voltage; +} + +/** + * @brief 初始化总用电量 + * @param totalPower 初始值 + * @retval + */ +void totalElectricityConsumptionInt(float totalPower) +{ + g_otherParameter.totalElectricityConsumption = totalPower; +} + +/** + * @brief 得到总充电量 + * @param + * @retval 总用电量 + */ +float getTotalChargCapacity(void) +{ + return g_otherParameter.totalChargCapacity; +} + +/** + * @brief 设置总充电量 + * @param + * @retval + */ +void setTotalChargCapacity(void) +{ + g_otherParameter.totalChargCapacity += g_otherParameter.Charg_Current * g_otherParameter.Output_Voltage; +} + +/** + * @brief 初始化总充电量 + * @param totalPower 初始值 + * @retval + */ +void totalChargCapacityInt(float totalPower) +{ + g_otherParameter.totalChargCapacity = totalPower; +} + +/** + * @brief 得到电池电量 + * @param + * @retval 电池电量 + */ +float getSOC(void) +{ + return g_otherParameter.SOC; +} + +/** + * @brief 设置电池电量 + * @param + * @retval + */ +void setSOC(void) +{ + +} + +/** + * @brief 得到工作模式 + * @param + * @retval 工作模式 + */ +int getMPPT_Mode(void) +{ + return g_otherParameter.MPPT_Mode; +} + +/** + * @brief 设置工作模式 + * @param + * @retval + */ +void setMPPT_Mode(int MPPT_Mode) +{ + g_otherParameter.MPPT_Mode = MPPT_Mode; +} + +/** + * @brief 得到流向电池的电流 + * @param + * @retval 流向电池的电流 + */ +float getChargBatteryCurrent(void) +{ + return (g_otherParameter.Charg_Current - g_otherParameter.Discharg_Current); +} + +/** + * @brief 得到充电开关状态 + * @param + * @retval 充电开关状态 + */ +BOOL getChargMosState(void) +{ + if (getDutyRatio() > 0 && getDutyRatio() < 1) { + return TRUE; + } else { + return FALSE; + } +} + +/** + * @brief 设置充电开关状态 + * @param state 开关状态,FALSE 关闭 + * @retval + */ +void setChargMosState(BOOL state) +{ + if (state == FALSE) { + /* 关闭充电 */ + + } else if (state == TRUE) { + /* 打开充电 */ + + } +} + +/** + * @brief 得到放电状态 + * @param + * @retval state 状态,FALSE 关闭 + */ +BOOL getDischargMosState(void) +{ + if (g_cfgParameter.onlyPower) { + return readOnlyPowerOutputState(); + } else { + return readOutputState(); + } +} + +/** + * @brief 得到软件版本号 + * @param + * @retval softVer 软件版本号 + */ +uint8_t *getVersionInformation(void) +{ + return softVer; +} + diff --git a/APP/functionalModule/Inc/FM_GPIO.h b/APP/functionalModule/Inc/FM_GPIO.h index b55dfd4..e2007e2 100644 --- a/APP/functionalModule/Inc/FM_GPIO.h +++ b/APP/functionalModule/Inc/FM_GPIO.h @@ -20,6 +20,9 @@ void FFMOS_CON_Close(void); void EN_PWMOUT_Eable(void); void EN_PWMOUT_Diseable(void); +BOOL readOnlyPowerOutputState(void); +BOOL readOutputState(void); + // extern void WORK_VOLT_Interrupt(void); // extern void DSG_PROT_Interrupt(void); diff --git a/APP/functionalModule/Inc/FM_TIM.h b/APP/functionalModule/Inc/FM_TIM.h index 1d8ea05..b96b3c5 100644 --- a/APP/functionalModule/Inc/FM_TIM.h +++ b/APP/functionalModule/Inc/FM_TIM.h @@ -4,10 +4,12 @@ #include "HD_TIM.h" -void pwm_Init(void); +void tim_Init(void); +void pwm_Stop(void); void set_pwmDutyRatio(float DutyRatio); void set_pwmPulse(uint32_t Pulse); extern void chargControl(void); +extern void checkAbnormal(void); #endif diff --git a/APP/functionalModule/Inc/capture.h b/APP/functionalModule/Inc/capture.h new file mode 100644 index 0000000..a86addc --- /dev/null +++ b/APP/functionalModule/Inc/capture.h @@ -0,0 +1,33 @@ + +#ifndef FM_CAPTURE_H_ +#define FM_CAPTURE_H_ + +#include "arm_math.h" + + +#pragma pack(push,4) +typedef struct _adcCapture +{ + float32_t inDataF[6]; + int16_t outData; +}adcCapture; +#pragma pack(pop) + +extern adcCapture WORK_VOLT_capture; +extern adcCapture DSG_CURR_capture; +extern adcCapture PV_VOLT_IN_capture; +extern adcCapture CHG_CURR_capture; + +void ADC_Capture_Init(void); +void proportionalInt(uint8_t mode); + +float get_CHG_CURR(void); +float get_PV_VOLT_OUT(void); +float get_DSG_CURR(void); +float get_PV1_VOLT_IN(void); +float get_PV_VOLT_IN1(void); +float get_MOSFET_Temper(void); + +void adcCaptureFir(); + +#endif \ No newline at end of file diff --git a/APP/functionalModule/Src/FM_GPIO.c b/APP/functionalModule/Src/FM_GPIO.c index b37e4c2..7f27341 100644 --- a/APP/functionalModule/Src/FM_GPIO.c +++ b/APP/functionalModule/Src/FM_GPIO.c @@ -106,6 +106,36 @@ void EN_PWMOUT_Diseable(void) HAL_GPIO_WritePin(EN_PWMOUT_GPIO_Port, EN_PWMOUT_Pin, GPIO_PIN_SET); } +/** + * @brief 仅有充电控制器时,判断输出开关是否打开 + * @param None + * @retval None + */ +BOOL readOnlyPowerOutputState(void) +{ + if (HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin) + && HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin) + && HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin)) { + return TRUE; + } + + return FALSE; +} + +/** + * @brief 带网关时,判断输出开关是否打开 + * @param None + * @retval None + */ +BOOL readOutputState(void) +{ + if (1) { + return TRUE; + } + + return FALSE; +} + /** * @brief GPIO外部中断的回调函数 * @param GPIO_Pin 引发外部中断的引脚 diff --git a/APP/functionalModule/Src/FM_TIM.c b/APP/functionalModule/Src/FM_TIM.c index 97c5231..dc51be4 100644 --- a/APP/functionalModule/Src/FM_TIM.c +++ b/APP/functionalModule/Src/FM_TIM.c @@ -1,19 +1,31 @@ #include "FM_TIM.h" #include "timeSliceOffset.h" +#include "capture.h" static int PWM_RESOLUTION; -void pwm_Init(void) +/** + * @brief 定时器初始化 + * @param None + * @retval None + */ +void tim_Init(void) { HD_PWM_Init(); + /* 得到pwm的分辨率 */ PWM_RESOLUTION = HAL_RCC_GetHCLKFreq() / 100000; + + HD_controlTim_Init(); + HD_taskBaseTim_Init(); + HD_checkAbnormalTim_Init(); } void pwm_Stop(void) { set_pwmPulse(0); - HAL_TIM_OC_MspDeInit(&htim3); + // HAL_TIM_OC_MspDeInit(&htim3); + HAL_TIM_PWM_MspDeInit(&htim3); } /** @@ -36,10 +48,6 @@ void set_pwmPulse(uint32_t Pulse) */ void set_pwmDutyRatio(float DutyRatio) { - if (DutyRatio > (float)0.9 || DutyRatio < (float)0.05) { - return; - } - uint32_t Pulse = (int)(DutyRatio * PWM_RESOLUTION); set_pwmPulse(Pulse); @@ -69,9 +77,16 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE BEGIN Callback 1 */ if (htim->Instance == TIM7) { - TimeSliceOffset_Produce(); chargControl(); } + if (htim->Instance == TIM16) { + TimeSliceOffset_Produce(); + } + + if (htim->Instance == TIM17) { + checkAbnormal(); + } + /* USER CODE END Callback 1 */ } \ No newline at end of file diff --git a/APP/functionalModule/Src/capture.c b/APP/functionalModule/Src/capture.c new file mode 100644 index 0000000..d1c0d15 --- /dev/null +++ b/APP/functionalModule/Src/capture.c @@ -0,0 +1,446 @@ + +#include "capture.h" +#include "HD_ADC.h" + +/* 温度的adc值的个数 */ +#define mosTemperADCLen 241 +///* 3.3V参考电压温度adc值 */ +//const uint16_t mosTemperADC[mosTemperADCLen] = { +// 3707, 3697, 3687, 3676, 3665, 3654, 3643, 3632, 3620, 3608, /* -20 - -15.5 ℃ */ +// 3596, 3584, 3571, 3559, 3546, 3533, 3519, 3506, 3492, 3478, /* -15 - -10.5 ℃ */ +// 3464, 3449, 3434, 3419, 3404, 3389, 3373, 3358, 3341, 3325, /* -10 - -5.5 ℃ */ +// 3309, 3292, 3275, 3258, 3241, 3223, 3205, 3187, 3169, 3151, /* -5 - -0.5 ℃ */ +// 3132, 3114, 3095, 3075, 3056, 3037, 3017, 2997, 2977, 2957, /* 0 - 4.5 ℃ */ +// 2936, 2916, 2895, 2874, 2854, 2832, 2811, 2790, 2768, 2747, /* 9 - 9.5 ℃ */ +// 2725, 2703, 2681, 2659, 2637, 2615, 2592, 2570, 2548, 2525, /* 10 - 14.5 ℃ */ +// 2503, 2480, 2457, 2435, 2412, 2389, 2366, 2343, 2321, 2298, /* 15 - 19.5 ℃ */ +// 2275, 2252, 2229, 2207, 2184, 2161, 2138, 2116, 2093, 2071, /* 20 - 24.5 ℃ */ +// 2048, 2026, 2003, 1981, 1959, 1937, 1914, 1893, 1871, 1849, /* 25 - 29.5 ℃ */ +// 1827, 1806, 1784, 1763, 1742, 1721, 1700, 1679, 1658, 1638, /* 30 - 34.5 ℃ */ +// 1617, 1597, 1577, 1557, 1537, 1518, 1498, 1479, 1460, 1441, /* 35 - 39.5 ℃ */ +// 1422, 1403, 1385, 1366, 1348, 1330, 1312, 1295, 1277, 1260, /* 40 - 44.5 ℃ */ +// 1243, 1226, 1209, 1192, 1176, 1160, 1144, 1128, 1112, 1097, /* 45 - 49.5 ℃ */ +// 1081, 1066, 1051, 1036, 1022, 1007, 993, 979, 965, 951, /* 50 - 54.5 ℃ */ +// 938, 924, 911, 898, 885, 872, 860, 848, 835, 823, /* 55 - 59.5 ℃ */ +// 811, 800, 788, 777, 765, 754, 743, 732, 722, 711, /* 60 - 64.5 ℃ */ +// 701, 691, 681, 671, 661, 651, 642, 632, 623, 614, /* 65 - 69.5 ℃ */ +// 605, 596, 588, 579, 571, 562, 554, 546, 538, 530, /* 70 - 74.5 ℃ */ +// 522, 515, 507, 500, 493, 486, 478, 471, 465, 458, /* 75 - 79.5 ℃ */ +// 451, 445, 438, 432, 426, 420, 414, 408, 402, 396, /* 80 - 84.5 ℃ */ +// 390, 385, 379, 374, 368, 363, 358, 353, 348, 343, /* 85 - 89.5 ℃ */ +// 338, 333, 328, 324, 319, 315, 310, 306, 301, 297, /* 90 - 94.5 ℃ */ +// 293, 289, 285, 281, 277, 273, 269, 266, 262, 258, /* 95 - 99.5 ℃ */ +// 255 /* 100 ℃ */ +//}; + + +/* 3.0V参考电压温度adc值 */ +const uint16_t mosTemperADC[mosTemperADCLen] = { + 4077, 4066, 4055, 4043, 4031, 4019, 4007, 3994, 3982, 3969, /* -20 - -15.5 ℃ */ + 3955, 3942, 3928, 3914, 3900, 3885, 3871, 3856, 3841, 3825, /* -15 - -10.5 ℃ */ + 3809, 3794, 3777, 3761, 3744, 3727, 3710, 3693, 3675, 3657, /* -10 - -5.5 ℃ */ + 3639, 3621, 3602, 3583, 3564, 3545, 3525, 3506, 3486, 3465, /* -5 - -0.5 ℃ */ + 3445, 3424, 3404, 3383, 3361, 3340, 3318, 3296, 3274, 3252, /* 0 - 4.5 ℃ */ + 3230, 3207, 3184, 3162, 3138, 3115, 3092, 3068, 3045, 3021, /* 5 - 9.5 ℃ */ + 2997, 2973, 2949, 2925, 2900, 2876, 2851, 2827, 2802, 2777, /* 10 - 14.5 ℃ */ + 2752, 2728, 2703, 2678, 2653, 2628, 2602, 2577, 2552, 2527, /* 15 - 19.5 ℃ */ + 2502, 2477, 2452, 2427, 2402, 2377, 2352, 2327, 2302, 2277, /* 20 - 24.5 ℃ */ + 2253, 2228, 2203, 2179, 2154, 2130, 2106, 2082, 2057, 2034, /* 25 - 29.5 ℃ */ + 2010, 1986, 1962, 1939, 1916, 1893, 1869, 1847, 1824, 1801, /* 30 - 34.5 ℃ */ + 1779, 1757, 1734, 1713, 1691, 1669, 1648, 1626, 1605, 1584, /* 35 - 39.5 ℃ */ + 1564, 1543, 1523, 1503, 1483, 1463, 1443, 1424, 1405, 1386, /* 40 - 44.5 ℃ */ + 1367, 1348, 1330, 1312, 1293, 1276, 1258, 1241, 1223, 1206, /* 45 - 49.5 ℃ */ + 1189, 1173, 1156, 1140, 1124, 1108, 1092, 1077, 1061, 1046, /* 50 - 54.5 ℃ */ + 1031, 1017, 1002, 988, 974, 960, 946, 932, 919, 905, /* 55 - 59.5 ℃ */ + 892, 879, 867, 854, 842, 829, 817, 806, 794, 782, /* 60 - 64.5 ℃ */ + 771, 760, 749, 738, 727, 716, 706, 696, 685, 675, /* 65 - 69.5 ℃ */ + 666, 656, 646, 637, 627, 618, 609, 600, 592, 583, /* 70 - 74.5 ℃ */ + 575, 566, 558, 550, 542, 534, 526, 519, 511, 504, /* 75 - 79.5 ℃ */ + 496, 489, 482, 475, 468, 461, 455, 448, 442, 435, /* 80 - 84.5 ℃ */ + 429, 423, 417, 411, 405, 399, 394, 388, 382, 377, /* 85 - 89.5 ℃ */ + 372, 366, 361, 356, 351, 346, 341, 336, 332, 327, /* 90 - 94.5 ℃ */ + 322, 318, 313, 309, 305, 300, 296, 292, 288, 284, /* 95 - 99.5 ℃ */ + 280 /* 100 ℃ */ +}; + +// /* 2.5V参考电压温度adc值 */ +// const uint16_t mosTemperADC[mosTemperADCLen] = { +// 4893, 4879, 4866, 4852, 4838, 4823, 4808, 4793, 4778, 4762, /* -20 - -15.5 ℃ */ +// 4746, 4730, 4714, 4697, 4680, 4663, 4645, 4627, 4609, 4590, /* -15 - -10.5 ℃ */ +// 4571, 4552, 4533, 4513, 4493, 4473, 4452, 4431, 4410, 4389, /* -10 - -5.5 ℃ */ +// 4367, 4345, 4323, 4300, 4277, 4254, 4231, 4207, 4183, 4159, /* -5 - -0.5 ℃ */ +// 4134, 4109, 4084, 4059, 4034, 4008, 3982, 3956, 3929, 3903, /* 0 - 4.5 ℃ */ +// 3876, 3849, 3821, 3794, 3766, 3738, 3710, 3682, 3654, 3625, /* 5 - 9.5 ℃ */ +// 3596, 3568, 3539, 3510, 3480, 3451, 3422, 3392, 3362, 3333, /* 10 - 14.5 ℃ */ +// 3303, 3273, 3243, 3213, 3183, 3153, 3123, 3093, 3063, 3033, /* 15 - 19.5 ℃ */ +// 3003, 2972, 2942, 2912, 2882, 2852, 2822, 2792, 2762, 2733, /* 20 - 24.5 ℃ */ +// 2703, 2673, 2644, 2614, 2585, 2556, 2527, 2498, 2469, 2440, /* 25 - 29.5 ℃ */ +// 2412, 2383, 2355, 2327, 2299, 2271, 2243, 2216, 2189, 2162, /* 30 - 34.5 ℃ */ +// 2135, 2108, 2081, 2055, 2029, 2003, 1977, 1952, 1926, 1901, /* 35 - 39.5 ℃ */ +// 1876, 1852, 1827, 1803, 1779, 1755, 1732, 1709, 1686, 1663, /* 40 - 44.5 ℃ */ +// 1640, 1618, 1596, 1574, 1552, 1531, 1510, 1489, 1468, 1447, /* 45 - 49.5 ℃ */ +// 1427, 1407, 1387, 1368, 1349, 1330, 1311, 1292, 1274, 1256, /* 50 - 54.5 ℃ */ +// 1238, 1220, 1203, 1185, 1168, 1151, 1135, 1119, 1102, 1086, /* 55 - 59.5 ℃ */ +// 1071, 1055, 1040, 1025, 1010, 995, 981, 967, 953, 939, /* 60 - 64.5 ℃ */ +// 925, 912, 898, 885, 872, 860, 847, 835, 822, 810, /* 65 - 69.5 ℃ */ +// 799, 787, 775, 764, 753, 742, 731, 721, 710, 700, /* 70 - 74.5 ℃ */ +// 690, 679, 670, 660, 650, 641, 631, 622, 613, 604, /* 75 - 79.5 ℃ */ +// 596, 587, 578, 570, 562, 554, 546, 538, 530, 523, /* 80 - 84.5 ℃ */ +// 515, 508, 500, 493, 486, 479, 472, 466, 459, 452, /* 85 - 89.5 ℃ */ +// 446, 440, 433, 427, 421, 415, 409, 404, 398, 392, /* 90 - 94.5 ℃ */ +// 387, 381, 376, 371, 366, 361, 355, 350, 346, 341, /* 95 - 99.5 ℃ */ +// 336 /* 100 ℃ */ +// }; + +enum { + WORK_VOLT_NUM = 0, + DSG_CURR_NUM = 1, + PV_VOLT_IN_NUM = 2, + CHG_CURR_NUM = 3, +}; +int16_t adcBuff[4]; + +adcCapture WORK_VOLT_capture = {0}; +adcCapture DSG_CURR_capture = {0}; +adcCapture PV_VOLT_IN_capture = {0}; +adcCapture CHG_CURR_capture = {0}; + +/* 电流电压采集转换的 */ +static float P_CHG_CURR = 0; +static float P_PV_VOLT_OUT = 0; +static float P_DSG_CURR = 0; +static float P_PV1_VOLT_IN = 0; +static float P_PV_VOLT_IN1 = 0; + +/* 2.5为adc的电压,4095是2^adc的位数 - 1 */ +// const float32_t Proportion = 2.5 / 4095; +const float32_t Proportion = 3.0 / 4095.0; + +/* matlab生成的5阶滤波器系数 */ +const int firLen = 6; +const float firLP[6] = { + 0.01861755922, -0.1146286726, 0.5962908864, 0.5962908864, -0.1146286726, + 0.01861755922 +}; + +/** + * @brief 初始化adc + * @param + * @retval None + */ +void ADC_Capture_Init(void) +{ + HD_adc_Init(); + /* 将回调函数与dma的转换完成中断绑定 */ + // hdma_adc1.XferCpltCallback = dmaFerCpltCallback; + HAL_Delay(100); + + /* adc校准 */ + HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED); + HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED); + + HAL_TIM_Base_Start(&htim6); + HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adcBuff, 4); + + // /* 光伏充电输出电流比例,放大倍数*电阻 */ + // P_CHG_CURR = (1.0 / (50 * (1 / (1 / 0.01 + 1 / 0.002)))) * Proportion; + // /* 充电控制盒输出电压比例,分压系数 */ + // P_PV_VOLT_OUT = ((47.0 + 10.0) / 10.0) * Proportion; + // /* 放电电流采集电流倍数 */ + // P_DSG_CURR = (1.0 / (50 * (1 / (1 / 0.002 * 2)))) * Proportion; + // /* 光伏板输出电压比例 */ + // P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion; + // /* 系统电源电压比例 */ + // P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion; +} + +/** + * @brief 初始化电流电压转换的比例(及放大或者缩小倍数) + * @param + * @retval None + */ +void proportionalInt(uint8_t mode) +{ + /* 仅充当电源盒 */ + if (mode) { + /* 光伏充电输出电流比例,放大倍数*电阻 */ + P_CHG_CURR = (1.0 / (50 * (1 / (1 / 0.01 + 1 / 0.002)))) * Proportion; + /* 充电控制盒输出电压比例,分压系数 */ + P_PV_VOLT_OUT = ((47.0 + 10.0) / 10.0) * Proportion; + /* 放电电流采集电流倍数 */ + P_DSG_CURR = (1.0 / (50 * (1 / (1 / 0.002 * 2)))) * Proportion; + /* 光伏板输出电压比例 */ + P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion; + /* 系统电源电压比例 */ + P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion; + } + + /* 电源盒外还有网关功能 */ + else { + /* 光伏充电输出电流比例,放大倍数*电阻 */ + P_CHG_CURR = (1.0 / (50 * 0.005)) * Proportion; + /* 光伏充电输出电压比例,分压系数 */ + P_PV_VOLT_OUT = ((47.0 + 4.7) / 4.7) * Proportion; + /* 放电电流采集电流倍数 */ + P_DSG_CURR = (1.0 / (50 * 0.005)) * Proportion; + /* 光伏1开路输出电压比例 */ + P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion; + /* 系统电源电压比例 */ + P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion; + } +} + +#define N 4 +/** + * @brief 中位值平均滤波 + * @param funtion 获取ADC的函数 + * @param ADC_Channel ADC通道 + * @retval None + */ +static int16_t middleAverageFilter(int16_t funtion(uint32_t Channel), uint32_t ADC_Channel) +{ + int16_t i,j,k; + int16_t temp,sum = 0; + int16_t value_buf[N]; + for (i = 0; i < N; ++i) { + value_buf[i] = funtion(ADC_Channel); + } + /*从小到大冒泡排序*/ + for(j = 0; j < N-1; ++j) { + for (k = 0; k < N-j-1; ++k) { + if(value_buf[k] > value_buf[k+1]) { + temp = value_buf[k]; + value_buf[k] = value_buf[k+1]; + value_buf[k+1] = temp; + } + } + } + for(i = 1; i < N-1; ++i) { + sum += value_buf[i]; + } + return sum / (N-2); +} + +/** + * @brief 获取adc2的采集值 + * @param Channel ADC通道 + * @retval None + */ +static int16_t ADC2_Capture(uint32_t Channel) +{ + return middleAverageFilter(get_adc2Value, Channel); +} + +// /** +// * @brief 获取adc1的采集值 +// * @param Channel ADC通道 +// * @retval None +// */ +// static int16_t ADC1_Capture(uint32_t Channel) +// { +// return middleAverageFilter(get_adc1Value, Channel); +// } + + + +/** + * @brief 得到充电电流 + * @param + * @retval I 电流值 + */ +float get_CHG_CURR(void) +{ + float I; + + I = CHG_CURR_capture.outData * P_CHG_CURR; + // I = ADC1_Capture(ADC_CHANNEL_11) * P_CHG_CURR; + +#ifdef enable_Printf_VI + debug("\n CHG_CURR ADC : %d \n", (int)CHG_CURR_capture.outDataF); + debug(" CHG_CURR I : %f \n", I); +#endif + + return I; +} + +/** + * @brief 得到光伏输出电压 + * @param + * @retval V 电压值 + */ +float get_PV_VOLT_OUT(void) +{ + float V; + + V = WORK_VOLT_capture.outData * P_PV_VOLT_OUT; + // V = ADC1_Capture(ADC_CHANNEL_7) * P_PV_VOLT_OUT; + + +#ifdef enable_Printf_VI + debug("\n PV_VOLT_OUT ADC : %d \n", (int)WORK_VOLT_capture.outDataF); + debug(" PV_VOLT_OUT V : %f \n", V); +#endif + + return V; +} + +/** + * @brief 得到放电电流 + * @param + * @retval I 电流值 + */ +float get_DSG_CURR(void) +{ + float I; + + I = DSG_CURR_capture.outData * P_DSG_CURR; + // I = ADC1_Capture(ADC_CHANNEL_8) * P_DSG_CURR; + +#ifdef enable_Printf_VI + debug("\n DSG_CURR ADC : %d \n", (int)DSG_CURR_capture.outDataF); + debug(" DSG_CURR I : %f \n", I); +#endif + + return I; +} + +/** + * @brief 得到光伏电压 + * @param + * @retval V 电压值 + */ +float get_PV1_VOLT_IN(void) +{ + float V; + + V = PV_VOLT_IN_capture.outData * P_PV1_VOLT_IN; + // V = ADC1_Capture(ADC_CHANNEL_15) * P_PV1_VOLT_IN; + +#ifdef enable_Printf_VI + debug("\n PV1_VOLT_IN ADC : %d \n", (int)PV_VOLT_IN_capture.outDataF); + debug(" PV1_VOLT_IN V1 : %f \n", V); +#endif + + return V; +} + +/** + * @brief 得到系统电压电压 + * @param + * @retval V 电压值 + */ +float get_PV_VOLT_IN1(void) +{ + float V; + uint16_t V_ADC; + + V_ADC = ADC2_Capture(SYS_VOLT_IN_CHANNEL); + + V = (float)(V_ADC) * P_PV_VOLT_IN1; + +#ifdef enable_Printf_VI + debug("\n PV_VOLT_IN1 ADC : %d \n", V_ADC); + debug(" PV_VOLT_IN1 V : %f \n", V); +#endif + + return V; +} + + +//const float Rp = 10000.0; //10K +//const float T2 = (273.15+25.0);//T2 +//const float Bx = 3950.0;//B +//const float Bx = 3435.0;//B +//const float Ka = 273.15; +/** + * @brief 得到温度 + * @param + * @retval V 电压值 + */ +float get_MOSFET_Temper(void) +{ + float T = 0; + uint16_t T_ADC; + + T_ADC = ADC2_Capture(MOSFET_Temper_CHANNEL); + + for (int i = 0; i < mosTemperADCLen; ++i) { + if (T_ADC >= mosTemperADC[i]) { + T = -20 + i * 0.5; + break; + } + } + +#ifdef enable_Printf_VI + debug("\n MOSFET_Temper ADC : %d \n", T_ADC); + debug(" MOSFET_Temper T : %f \n", T); +#endif + + return T; +} + +/** + * @brief adc转换并传输完成后进入该回调函数 + * @param hdma dma + * @retval None + */ +void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hdma) +{ + if (hdma->Instance == ADC1) { + arm_copy_f32(WORK_VOLT_capture.inDataF, WORK_VOLT_capture.inDataF + 1, 5); + arm_copy_f32(DSG_CURR_capture.inDataF, DSG_CURR_capture.inDataF + 1, 5); + arm_copy_f32(PV_VOLT_IN_capture.inDataF, PV_VOLT_IN_capture.inDataF + 1, 5); + arm_copy_f32(CHG_CURR_capture.inDataF, CHG_CURR_capture.inDataF + 1, 5); + + WORK_VOLT_capture.inDataF[5] = (float32_t)adcBuff[WORK_VOLT_NUM]; + DSG_CURR_capture.inDataF[5] = (float32_t)adcBuff[DSG_CURR_NUM]; + PV_VOLT_IN_capture.inDataF[5] = (float32_t)adcBuff[PV_VOLT_IN_NUM]; + CHG_CURR_capture.inDataF[5] = (float32_t)adcBuff[CHG_CURR_NUM]; + } +} + +/** + * @brief 将采集得到的adc进行滤波 + * @param None + * @retval None + */ +void adcCaptureFir(void) +{ + static arm_fir_instance_f32 armFirInstanceF32; + static float32_t *inputF32, *outputF32; + static uint32_t blockSize = 1; + static float32_t firStateF32[6]; /* 状态缓存 */ + static float32_t outputf; + + /* 初始化结构体 */ + arm_fir_init_f32(&armFirInstanceF32, + firLen, + (float_t *)&firLP[0], + &firStateF32[0], + blockSize); + + /* 初始化输入输出缓存指针 */ + inputF32 = &WORK_VOLT_capture.inDataF[0]; + outputF32 = &outputf; + arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize); + WORK_VOLT_capture.outData = (int16_t)outputf; + + /* 初始化输入输出缓存指针 */ + inputF32 = &DSG_CURR_capture.inDataF[0]; + outputF32 = &outputf; + arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize); + DSG_CURR_capture.outData = (int16_t)outputf; + + /* 初始化输入输出缓存指针 */ + inputF32 = &PV_VOLT_IN_capture.inDataF[0]; + outputF32 = &outputf; + arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize); + PV_VOLT_IN_capture.outData = (int16_t)outputf; + + /* 初始化输入输出缓存指针 */ + inputF32 = &CHG_CURR_capture.inDataF[0]; + outputF32 = &outputf; + arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize); + CHG_CURR_capture.outData = (int16_t)outputf; +} + diff --git a/APP/hardwareDriver/Inc/HD_ADC.h b/APP/hardwareDriver/Inc/HD_ADC.h new file mode 100644 index 0000000..474213f --- /dev/null +++ b/APP/hardwareDriver/Inc/HD_ADC.h @@ -0,0 +1,20 @@ + +#ifndef HD_ADC_H_ +#define HD_ADC_H_ + +#include "main.h" +#include "adc.h" +#include "dma.h" +#include "tim.h" +#include "comm_types.h" +#include "stm32g431xx.h" + +#define SYS_VOLT_IN_CHANNEL ADC_CHANNEL_1 +#define MOSFET_Temper_CHANNEL ADC_CHANNEL_15 + +void HD_adc_Init(void); +int16_t get_adc1Value(uint32_t Channel); +int16_t get_adc2Value(uint32_t Channel); + + +#endif \ No newline at end of file diff --git a/APP/hardwareDriver/Inc/HD_TIM.h b/APP/hardwareDriver/Inc/HD_TIM.h index 8dbcacd..aeeb962 100644 --- a/APP/hardwareDriver/Inc/HD_TIM.h +++ b/APP/hardwareDriver/Inc/HD_TIM.h @@ -8,6 +8,8 @@ void HD_PWM_Init(void); void HD_controlTim_Init(void); +void HD_taskBaseTim_Init(void); +void HD_checkAbnormalTim_Init(void); #endif \ No newline at end of file diff --git a/APP/hardwareDriver/Src/HD_ADC.c b/APP/hardwareDriver/Src/HD_ADC.c new file mode 100644 index 0000000..3d4bfce --- /dev/null +++ b/APP/hardwareDriver/Src/HD_ADC.c @@ -0,0 +1,61 @@ +#include "HD_ADC.h" + +#define ADC_SAMPLETIME ADC_SAMPLETIME_2CYCLES_5 //采样时间 + + +void HD_adc_Init(void) +{ + MX_DMA_Init(); + MX_TIM6_Init(); + MX_ADC1_Init(); + MX_ADC2_Init(); +} + +/** + * @brief 获取adc1中某通道的值 + * @param Channel 通道 + */ +int16_t get_adc1Value(uint32_t Channel) +{ + ADC_ChannelConfTypeDef sConfig; + + /* 更改读取的adc的通道 */ + sConfig.Channel = Channel; + sConfig.Rank = ADC_REGULAR_RANK_1; + sConfig.SamplingTime = ADC_SAMPLETIME; + sConfig.SingleDiff = ADC_SINGLE_ENDED; + sConfig.OffsetNumber = ADC_OFFSET_NONE; + sConfig.Offset = 0; + HAL_ADC_ConfigChannel(&hadc1, &sConfig); + + /* 启动转换 */ + HAL_ADC_Start(&hadc1); + /* 等待转化结束 */ + HAL_ADC_PollForConversion(&hadc1, 30); + u_int16_t adcValue = HAL_ADC_GetValue(&hadc1); + + return adcValue; +} + +int16_t get_adc2Value(uint32_t Channel) +{ + ADC_ChannelConfTypeDef sConfig; + + /* 更改读取的adc的通道 */ + sConfig.Channel = Channel; + sConfig.Rank = ADC_REGULAR_RANK_1; + sConfig.SamplingTime = ADC_SAMPLETIME; + sConfig.SingleDiff = ADC_SINGLE_ENDED; + sConfig.OffsetNumber = ADC_OFFSET_NONE; + sConfig.Offset = 0; + HAL_ADC_ConfigChannel(&hadc2, &sConfig); + + /* 启动转换 */ + HAL_ADC_Start(&hadc2); + /* 等待转化结束 */ + HAL_ADC_PollForConversion(&hadc2, 30); + u_int16_t adcValue = HAL_ADC_GetValue(&hadc2); + + return adcValue; +} + diff --git a/APP/hardwareDriver/Src/HD_TIM.c b/APP/hardwareDriver/Src/HD_TIM.c index 4f67bf6..5459a20 100644 --- a/APP/hardwareDriver/Src/HD_TIM.c +++ b/APP/hardwareDriver/Src/HD_TIM.c @@ -1,11 +1,41 @@ #include "HD_TIM.h" +/** + * @brief 控制pwm的定时器初始化 + * @param None + * @retval None + */ void HD_PWM_Init(void) { MX_TIM3_Init(); } +/** + * @brief 该定时器中断中完成充电控制器的控制 + * @param None + * @retval None + */ void HD_controlTim_Init(void) { MX_TIM7_Init(); -} \ No newline at end of file +} + +/** + * @brief 该定时器中断中设置普通任务的时间基准 + * @param None + * @retval None + */ +void HD_taskBaseTim_Init(void) +{ + MX_TIM16_Init(); +} + +/** + * @brief 该定时器中断中检测异常情况,并完成数据的采集 + * @param None + * @retval None + */ +void HD_checkAbnormalTim_Init(void) +{ + MX_TIM17_Init(); +} diff --git a/Core/Inc/stm32g4xx_it.h b/Core/Inc/stm32g4xx_it.h index 1cc7f6c..64476a6 100644 --- a/Core/Inc/stm32g4xx_it.h +++ b/Core/Inc/stm32g4xx_it.h @@ -57,10 +57,12 @@ void PendSV_Handler(void); void SysTick_Handler(void); void DMA1_Channel1_IRQHandler(void); void TIM1_UP_TIM16_IRQHandler(void); +void TIM1_TRG_COM_TIM17_IRQHandler(void); void USART2_IRQHandler(void); void USART3_IRQHandler(void); void EXTI15_10_IRQHandler(void); void TIM6_DAC_IRQHandler(void); +void TIM7_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/Core/Inc/tim.h b/Core/Inc/tim.h index 5c31add..48d1397 100644 --- a/Core/Inc/tim.h +++ b/Core/Inc/tim.h @@ -38,6 +38,10 @@ extern TIM_HandleTypeDef htim6; extern TIM_HandleTypeDef htim7; +extern TIM_HandleTypeDef htim16; + +extern TIM_HandleTypeDef htim17; + /* USER CODE BEGIN Private defines */ /* USER CODE END Private defines */ @@ -45,6 +49,8 @@ extern TIM_HandleTypeDef htim7; void MX_TIM3_Init(void); void MX_TIM6_Init(void); void MX_TIM7_Init(void); +void MX_TIM16_Init(void); +void MX_TIM17_Init(void); void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); diff --git a/Core/Src/main.c b/Core/Src/main.c index 45147ad..d90e6c6 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -101,6 +101,8 @@ int main(void) MX_USART2_UART_Init(); MX_USART3_UART_Init(); MX_TIM7_Init(); + MX_TIM16_Init(); + MX_TIM17_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ diff --git a/Core/Src/stm32g4xx_it.c b/Core/Src/stm32g4xx_it.c index 7f867d0..28b0465 100644 --- a/Core/Src/stm32g4xx_it.c +++ b/Core/Src/stm32g4xx_it.c @@ -57,6 +57,9 @@ /* External variables --------------------------------------------------------*/ extern DMA_HandleTypeDef hdma_adc1; extern TIM_HandleTypeDef htim6; +extern TIM_HandleTypeDef htim7; +extern TIM_HandleTypeDef htim16; +extern TIM_HandleTypeDef htim17; extern UART_HandleTypeDef huart2; extern UART_HandleTypeDef huart3; extern TIM_HandleTypeDef htim1; @@ -225,12 +228,33 @@ void TIM1_UP_TIM16_IRQHandler(void) /* USER CODE BEGIN TIM1_UP_TIM16_IRQn 0 */ /* USER CODE END TIM1_UP_TIM16_IRQn 0 */ - HAL_TIM_IRQHandler(&htim1); + if (htim1.Instance != NULL) + { + HAL_TIM_IRQHandler(&htim1); + } + if (htim16.Instance != NULL) + { + HAL_TIM_IRQHandler(&htim16); + } /* USER CODE BEGIN TIM1_UP_TIM16_IRQn 1 */ /* USER CODE END TIM1_UP_TIM16_IRQn 1 */ } +/** + * @brief This function handles TIM1 trigger and commutation interrupts and TIM17 global interrupt. + */ +void TIM1_TRG_COM_TIM17_IRQHandler(void) +{ + /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 0 */ + + /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 0 */ + HAL_TIM_IRQHandler(&htim17); + /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 1 */ + + /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 1 */ +} + /** * @brief This function handles USART2 global interrupt / USART2 wake-up interrupt through EXTI line 26. */ @@ -288,6 +312,20 @@ void TIM6_DAC_IRQHandler(void) /* USER CODE END TIM6_DAC_IRQn 1 */ } +/** + * @brief This function handles TIM7 global interrupt. + */ +void TIM7_IRQHandler(void) +{ + /* USER CODE BEGIN TIM7_IRQn 0 */ + + /* USER CODE END TIM7_IRQn 0 */ + HAL_TIM_IRQHandler(&htim7); + /* USER CODE BEGIN TIM7_IRQn 1 */ + + /* USER CODE END TIM7_IRQn 1 */ +} + /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ diff --git a/Core/Src/tim.c b/Core/Src/tim.c index 4a18084..31848aa 100644 --- a/Core/Src/tim.c +++ b/Core/Src/tim.c @@ -27,6 +27,8 @@ TIM_HandleTypeDef htim3; TIM_HandleTypeDef htim6; TIM_HandleTypeDef htim7; +TIM_HandleTypeDef htim16; +TIM_HandleTypeDef htim17; /* TIM3 init function */ void MX_TIM3_Init(void) @@ -88,7 +90,7 @@ void MX_TIM6_Init(void) htim6.Instance = TIM6; htim6.Init.Prescaler = 71; htim6.Init.CounterMode = TIM_COUNTERMODE_UP; - htim6.Init.Period = 499; + htim6.Init.Period = 29; htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim6) != HAL_OK) { @@ -137,6 +139,60 @@ void MX_TIM7_Init(void) /* USER CODE END TIM7_Init 2 */ +} +/* TIM16 init function */ +void MX_TIM16_Init(void) +{ + + /* USER CODE BEGIN TIM16_Init 0 */ + + /* USER CODE END TIM16_Init 0 */ + + /* USER CODE BEGIN TIM16_Init 1 */ + + /* USER CODE END TIM16_Init 1 */ + htim16.Instance = TIM16; + htim16.Init.Prescaler = 71; + htim16.Init.CounterMode = TIM_COUNTERMODE_UP; + htim16.Init.Period = 999; + htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim16.Init.RepetitionCounter = 0; + htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim16) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM16_Init 2 */ + + /* USER CODE END TIM16_Init 2 */ + +} +/* TIM17 init function */ +void MX_TIM17_Init(void) +{ + + /* USER CODE BEGIN TIM17_Init 0 */ + + /* USER CODE END TIM17_Init 0 */ + + /* USER CODE BEGIN TIM17_Init 1 */ + + /* USER CODE END TIM17_Init 1 */ + htim17.Instance = TIM17; + htim17.Init.Prescaler = 71; + htim17.Init.CounterMode = TIM_COUNTERMODE_UP; + htim17.Init.Period = 199; + htim17.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim17.Init.RepetitionCounter = 0; + htim17.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim17) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM17_Init 2 */ + + /* USER CODE END TIM17_Init 2 */ + } void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle) @@ -180,10 +236,44 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) /* USER CODE END TIM7_MspInit 0 */ /* TIM7 clock enable */ __HAL_RCC_TIM7_CLK_ENABLE(); + + /* TIM7 interrupt Init */ + HAL_NVIC_SetPriority(TIM7_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM7_IRQn); /* USER CODE BEGIN TIM7_MspInit 1 */ /* USER CODE END TIM7_MspInit 1 */ } + else if(tim_baseHandle->Instance==TIM16) + { + /* USER CODE BEGIN TIM16_MspInit 0 */ + + /* USER CODE END TIM16_MspInit 0 */ + /* TIM16 clock enable */ + __HAL_RCC_TIM16_CLK_ENABLE(); + + /* TIM16 interrupt Init */ + HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn); + /* USER CODE BEGIN TIM16_MspInit 1 */ + + /* USER CODE END TIM16_MspInit 1 */ + } + else if(tim_baseHandle->Instance==TIM17) + { + /* USER CODE BEGIN TIM17_MspInit 0 */ + + /* USER CODE END TIM17_MspInit 0 */ + /* TIM17 clock enable */ + __HAL_RCC_TIM17_CLK_ENABLE(); + + /* TIM17 interrupt Init */ + HAL_NVIC_SetPriority(TIM1_TRG_COM_TIM17_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM1_TRG_COM_TIM17_IRQn); + /* USER CODE BEGIN TIM17_MspInit 1 */ + + /* USER CODE END TIM17_MspInit 1 */ + } } void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) { @@ -253,10 +343,41 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) /* USER CODE END TIM7_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_TIM7_CLK_DISABLE(); + + /* TIM7 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM7_IRQn); /* USER CODE BEGIN TIM7_MspDeInit 1 */ /* USER CODE END TIM7_MspDeInit 1 */ } + else if(tim_baseHandle->Instance==TIM16) + { + /* USER CODE BEGIN TIM16_MspDeInit 0 */ + + /* USER CODE END TIM16_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM16_CLK_DISABLE(); + + /* TIM16 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM1_UP_TIM16_IRQn); + /* USER CODE BEGIN TIM16_MspDeInit 1 */ + + /* USER CODE END TIM16_MspDeInit 1 */ + } + else if(tim_baseHandle->Instance==TIM17) + { + /* USER CODE BEGIN TIM17_MspDeInit 0 */ + + /* USER CODE END TIM17_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM17_CLK_DISABLE(); + + /* TIM17 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM1_TRG_COM_TIM17_IRQn); + /* USER CODE BEGIN TIM17_MspDeInit 1 */ + + /* USER CODE END TIM17_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ diff --git a/EWARM/chargeController.ewd b/EWARM/chargeController.ewd index 80d4cd1..b6097fb 100644 --- a/EWARM/chargeController.ewd +++ b/EWARM/chargeController.ewd @@ -36,7 +36,7 @@ @@ -294,7 +294,7 @@