From 18d0cbe4c8b198ae25db4c25d81db16dd889f192 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Sat, 6 Feb 2021 18:01:43 +0100 Subject: [PATCH] still timer --- cube/Core/Src/tim.c | 2 +- cube/Makefile | 2 +- cube/Makefile-bak | 2 +- cube/User/Src/main2.c | 24 ++++++++++++++++++++++++ cube/cube.ioc | 6 ++++-- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/cube/Core/Src/tim.c b/cube/Core/Src/tim.c index 199fce9..93a3fa9 100644 --- a/cube/Core/Src/tim.c +++ b/cube/Core/Src/tim.c @@ -34,7 +34,7 @@ void MX_TIM1_Init(void) TIM_IC_InitTypeDef sConfigIC = {0}; htim1.Instance = TIM1; - htim1.Init.Prescaler = 0; + htim1.Init.Prescaler = 71; htim1.Init.CounterMode = TIM_COUNTERMODE_UP; htim1.Init.Period = 65535; htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; diff --git a/cube/Makefile b/cube/Makefile index 9e77137..d28f157 100644 --- a/cube/Makefile +++ b/cube/Makefile @@ -1,6 +1,6 @@ # Processed by ../tools/insertMyCode.sh ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sat Feb 06 15:53:10 CET 2021] +# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sat Feb 06 17:58:19 CET 2021] ########################################################################################################################## # ------------------------------------------------ diff --git a/cube/Makefile-bak b/cube/Makefile-bak index 22fa11b..674fb6c 100644 --- a/cube/Makefile-bak +++ b/cube/Makefile-bak @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sat Feb 06 15:53:10 CET 2021] +# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sat Feb 06 17:58:19 CET 2021] ########################################################################################################################## # ------------------------------------------------ diff --git a/cube/User/Src/main2.c b/cube/User/Src/main2.c index 34d4002..328e3c2 100644 --- a/cube/User/Src/main2.c +++ b/cube/User/Src/main2.c @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -47,6 +48,10 @@ void my_setup_2() { // cmdHandlerInit(); schAdd(second_tick, NULL, 0, 60*1000); + + + HAL_TIM_IC_Start_IT(&mainsCnt, TIM_CHANNEL_1); + logMsg("Application running"); } @@ -78,3 +83,22 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) { } } +void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) { + static uint8_t state = 0; + static uint32_t savedV = 0; + if (htim == &mainsCnt) { + uint32_t v = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1); + if (state == 0) { + show(DEBUG_2, ON); + savedV = v; + state = 1; + } else if (state == 1) { + show(DEBUG_2, OFF); + uint32_t captured = (savedV < v) ? (v - savedV) : ((htim->Init.Period - savedV) + v); + logMsg("CCR: %ld", captured); + state = 0; + } else { + state = 0; + } + } +} \ No newline at end of file diff --git a/cube/cube.ioc b/cube/cube.ioc index 08ded81..1be07cf 100644 --- a/cube/cube.ioc +++ b/cube/cube.ioc @@ -152,7 +152,7 @@ ProjectManager.StackSize=0x400 ProjectManager.TargetToolchain=Makefile ProjectManager.ToolChainLocation= ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_IWDG_Init-IWDG-false-HAL-true,3-MX_SPI1_Init-SPI1-false-HAL-true,4-MX_SPI2_Init-SPI2-false-HAL-true,5-MX_TIM1_Init-TIM1-false-HAL-true,6-MX_USART1_UART_Init-USART1-false-HAL-true +ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_SPI1_Init-SPI1-false-HAL-true,4-MX_SPI2_Init-SPI2-false-HAL-true,5-MX_TIM1_Init-TIM1-false-HAL-true,6-MX_USART1_UART_Init-USART1-false-HAL-true RCC.ADCFreqValue=36000000 RCC.AHBFreq_Value=72000000 RCC.APB1CLKDivider=RCC_HCLK_DIV2 @@ -188,7 +188,9 @@ SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate SPI2.Mode=SPI_MODE_MASTER SPI2.VirtualType=VM_MASTER TIM1.Channel-Input_Capture1_from_TI1=TIM_CHANNEL_1 -TIM1.IPParameters=Channel-Input_Capture1_from_TI1 +TIM1.ClockDivision=TIM_CLOCKDIVISION_DIV1 +TIM1.IPParameters=Channel-Input_Capture1_from_TI1,Prescaler,ClockDivision +TIM1.Prescaler=71 USART1.IPParameters=VirtualMode USART1.VirtualMode=VM_ASYNC VP_SYS_VS_Systick.Mode=SysTick