2016-10-01 06:54 AM
Hi you all,
I'm new to STM32 and I have been trying to find my way around the peripherals using STM's HAL library and STM32Cube.I've already configured my board in order to use some peripherals:
Timer 2 for running an interrupt with a certain frequency
Timer 3 for running PWMs on 3 channels of it.
ADC with 4 channels, into DMA mode, for reading some analog input.
Let us suppose, now, that the PWM's whole period is 100 ms and its duty cycle is 50% (50 ms PWM on and 50 ms PWM off).
I would like to trigger an interrupt after a certain time of the PWM on level, let us say 50% of it.
Hence, I would like to run an interrupt at 25 ms in order to trigger the ADC for sampling it's analog inputs.
Do you have any suggestion on how could I implement such a kind of interrupt?
Thank you in advance for your help!
#!stm32 #!stm32-!tim-!adc-!pwm2016-10-01 10:01 PM
I'm going to assume that you're using an STM32F4 part.
Assuming that you're using the ADC in Regular mode, not Injected mode, you can trigger it from TIM3 CH1 and use CH2,3,4 for your PWM outputs. If you configure TIM3 CH1 for Output Compare mode 0 (TIM3->CCMR1.OC1M = 0) and TIM3->CCR1 to whatever value gives you 25% of duty then it will generate TIM3_CH1 events that can be used to trigger ADC start-of-conversion at 25% of your TIM3 timebase. Alternatively, you can slave TIM4 or TIM5 to TIM3. Any of TIM4_CH1, TIM5_CH1 and TIM5_CH2 can also be used to trigger an ADC conversion. Lastly, I suggest that you read the reference manual chapters on the ADC (Ch 13) and general-purpose timers (Ch 18).2016-10-02 03:11 AM
Hi markt,
I'm using a STM32F411, so your assumption is right. I'll implement the first approach you proposed, I think it is better not wasting other timers, by slaving them, for such a little thing. Thank you for answering so quickly!