Skip to main content
piotrek700
Associate
May 17, 2013
Question

STM32F4 Timer External Pulse counting

Posted on May 18, 2013 at 00:23

Since 4 day I'm trying write code which will be able to count external pulses. I tried to use encoder mode but i supposed that this work only with 2 quadrature encoders. I have only one pulse signal and i have no idea how to do it. Could you help me or show examples how to count external pulses using timer?

#counter #timer #off-topic #pulce
This topic has been closed for replies.

35 replies

patrob680
Visitor II
October 27, 2015
Posted on October 27, 2015 at 15:11

Thank you for your guidance. External input(~10Hz) is connected to 32bit TIM5_Ch1. TIM5 uses systemcore clock 32MHz in STM32L1. Can I prescale it down for power saving. If a timer uses system clock, it may not work in LP sleep mode, am I right?

For L1 HD devices, RTC wakeup interrupt can be configured from 122us to 32s using highest prescaler 16, hence, I thought to use RTC for 10ms iteruupt.

I need to count pulses for 2 min. Need to store it in a format for further MATLAB processing. I found your ADC_SDIO example here: https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Problem%20with%20ADC%20DMA%20and%20timer&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=336

Tesla DeLorean
Guru
October 27, 2015
Posted on October 27, 2015 at 16:04

I'm mainly using F2/F4 device, you'll need to work out the specifics for your L1 implementation.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
patrob680
Visitor II
November 1, 2015
yuanchen
Visitor II
November 17, 2015
Posted on November 17, 2015 at 22:19

Hello Clive1,

I'm also trying to count external pulses using the Timer peripheral. I'm confused between using different clock selections.  From my understanding, TIM_TIxExternalClockConfig() is used when I'm using a channel like TIM3_CHAN1/2 and  TIM_ETRConfig() is used for TIM3_ETR pin. Other than that, the rest of the implementation is the same. Is my understanding correct? 

Also I have this scenario: I'm using TIM4 to generate a PWM output at a 1Hz frequency (which is working properly). Wire a TIM3_ETR pin to my TIM4 PWM output pin. I then use TIM_ETRConfig(TIM3,...) to set up the external trigger. For timer3, I call SelectInputTrigger(TIM3,???) and SelectSlaveMode(TIM3, TIM_SlaveMode_Reset). In this case, TIM3 will clock only on a rising/falling edge of TIM4 PWM, and TIM3->CNT stores the number of pwm pulses. Am I on the right track? and what parameter should I use for ???

Thank you in advance.

Tesla DeLorean
Guru
November 17, 2015
Posted on November 17, 2015 at 22:43

Well TI1 and TI2 are filtered, down wind, versions of CH1 and CH2, you can also use TI1ED which is the edged version of CH1. The filter is controlled by the rate of ClockDivision specified in the Time Base settings.

Depending on the ITR wiring you may be able to pull the external clock from an internal node, via TIM_ITRxExternalClockConfig().

You may want to looks at TIM_ETRClockMode1Config(), and TIM_ETRClockMode2Config(), as they also use TIM_ETRConfig(). Can't say I've played with those myself.

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