Skip to main content
Grozea.Ion
Associate III
April 23, 2023
Question

Timer setup to measure the time between 2 events using Input Capture

  • April 23, 2023
  • 2 replies
  • 3667 views

Hello all,

On and STM32F722 I am measuring the speed of an object that is passing between 2 photogates using external interrupts.

I would like to automate the time measure using Input Capture direct mode on channel 3 and 4 of timer 4, however I do not know how to setup TIM4 in order to start the timer when CH3 is triggered and to stop it when CH4 is triggered.

Can anyone guide me?

Thank you.

This topic has been closed for replies.

2 replies

waclawek.jan
Super User
April 23, 2023

You can't.

Only CH1 and CH2 are inputs to slave-mode controller, and that can only stay the time, not stop it (it can gate, but that's not what you want anyway).

Use DMA to store captured values to memory, for to be processed later.

JW

Grozea.Ion
Associate III
April 24, 2023

Hello Jan,

Thank you for your quick reply.

On my board I can also use TIM2 or 5 CH1/2.

Can you offer more details (step by step) on how to use your solution?

waclawek.jan
Super User
April 24, 2023

With CH1/CH2, you can use a similar trick than what's described in "PWM input" in RM: use CH1 as input to slave-mode controller set to Reset mode, and then CH2 captures the difference between the two channels, so that you'll find the result in TIMx_CCR2. Note, that there's an undocumented small (couple of cycles) delay between CH1 capture event and the reset, so the result will be a bit smaller than the actual time difference.

What I was mentioning above was to trigger DMA transfer by CH2 (or CH4 in the previous case), which would use the DMAR/DCR mechanism to transfer both CCR3 and CCR4 into memory, and that would be then processed any time later. This is more complicated than the above mentioned method.

JW

Grozea.Ion
Associate III
April 25, 2023

Thank you for your reply Jan.

I have looked in to RM0431 chapter 19.3.6 and unfortunately i am not able to figure this out.

Is it possible to provide me the configuration code for TIM2?

I know I am asking too much, but this set up is above my skills.