Skip to main content
Associate III
February 4, 2019
Question

STM32Fx external input counting and triggering ADC

  • February 4, 2019
  • 2 replies
  • 1826 views

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

This topic has been closed for replies.

2 replies

Tesla DeLorean
Guru
February 4, 2019

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 VenmoUp vote any posts that you find helpful, it shows what's working..
privenAuthor
Associate III
February 4, 2019

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?

Tesla DeLorean
Guru
February 4, 2019

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 VenmoUp vote any posts that you find helpful, it shows what's working..
S.Ma
Principal
February 4, 2019

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.

privenAuthor
Associate III
February 5, 2019

Nice work-around, I'll consider it

Thanks