cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Fx external input counting and triggering ADC

priven
Associate II

Hi,

I have a PWM signal input to STM32Fx MCU, I would like to count the number of pulses and trigger ADC on each rising edge of the PWM.

If I use the input as the clock source for the Timer I don't know how to generate a trigger to the ADC on each pulse without using GPIO EXTI

Please assist,

Michael

6 REPLIES 6

Find a TIM where the TIMx_CHx can trigger an ADC, and be routed the external count clock. This, or an Indirect (CH1<->CH2) input capture method should work.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

You can have your ADC PWM pulse go directly to ADC trigger pin AND the timer if you wish to count periods. If ADC uses DMA to automatically fill a buffer, by simply checking DMA counters, you'll be able to know how many pulses and how many ADC sampled data are in the buffer.

Hi Clive,

Thank you for your replay.

From what I understand ADC is triggered by TIM-TRGO or TIM-CC or Ext_IT, and for counting I need to use TIM_Base with the clock being my input?

Maybe I can use TIMx-CH1 as input, than split it to TI1FP1 and TIFP2 set CC_register_1 to base mode and CC_register_2 to capture mode with period of 1?

Don't know what part you're using.

The input capture does CCR2 = CNT, it wouldn't really matter what CNT was doing, which presumably be a maximal setting, as you would just be using it as a trigger event. The ADC would explicitly have support for TIMx_CHx, or be mapped at the TIM to be TIMx_TRGO

The Reference Manual for the part should have a list of trigger sources.

0690X000006DNIjQAO.jpg

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I'm using STM32F051 - this is the ADC trigger

0690X000006DNepQAG.jpg

Can use TIMx_CH1 for timer clock and also for input capture?

Nice work-around, I'll consider it

Thanks