haasurf.blogg.se

Stm32 hal input capture
Stm32 hal input capture




stm32 hal input capture

Single_producer_single_consumer_queue.I am working on a TV output library for stm32duino (STM32F103CBT6 bluepill) for a project.

stm32 hal input capture

If (htim->Instance = TIM1 & htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4 )Īuto now = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4) So here is the code for reference: void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef * htim) I had the same issue quite some time ago but instead of a PWM I had a saw tooth with variable frequency so I was just counting saw tooth edges. Because the sampling frequency should be at least double the PWM frequency ,you have to handle the period asynchronously (because the main loop may be slow to handle these frequencies). What you can do is to create a queue on the interrupt to store the period. I'm really a newbie in MCU programming, especialy with ARM Cortex architecture so any help would be appreciated. For some reason this doesn't work properly.(buffer values are mostly 0, except on 20th and 0th index) I'd like to know if there is a smarter way to do this and make it work. System clock frequency is 48MHz, and the timer prescaler value is 47999+1 which gives a time base of 1000 Hz. I'm calling this function every 1000ms, the PWM signal period has variable length (few ms to 100 ms approximatly). HAL_TIM_IC_Stop_IT(&htim2, TIM_CHANNEL_1) Īll the variables used that aren't locally defined are global volatile variables. HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1) Basicly i want to make a function which starts the timer in interrupt mode takes 20 samples divides them by 20 and returns the precise value and after that disables the timer. Now i want to make a buffer and take 20 samples which i'll divide with the length of a buffer to get a precise reading. Input_capture= _HAL_TIM_GET_COMPARE(&htim2, TIM_CHANNEL_1) //read TIM2 channel 1 capture valueįrequency=input_capture-input_capture_prev Įvery time an external interrupt happens i take the timer time and subtract it with the time when a previous interrupt happened. void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)

stm32 hal input capture

The callback routine is mentioned in the code below. I'm using GPT (General purpouse timer) in input capture mode. Point is to determine the frequency of the signal. I'm trying to measure time passed between two external interrupts generated by rising edges of a PWM signal (generated using a IC 555 timer).






Stm32 hal input capture