cancel
Showing results for 
Search instead for 
Did you mean: 

I work with the TIMER2 in INPUT CAPTURE mode, the interrupt is triggered on rising or falling edge. I want to get both trigger times on both fronts using the conditional statement "if" and the HAL library.

AGHAZ
Associate II
 
8 REPLIES 8

Your best course of action is to use Indirect mode on a second channel. ie CH1 Direct for one edge, CH2 Indirect (from CH1) for the other edge. This will tend to be safer as it gives you more leeway on the interrupt latency. You can also do a quick A-B measurement of time for the two edges.

The measurements will be in TIMx->CCR1 and CCR2

CH3 and CH4 can also pair in a similar fashion.

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

What is the core SYSCLK frequency and what is the max frequency of the incoming signal to measure rise and fall edge? What Clive mention (A-B) is usually the best. If you can't have 2 pins on the same signals, if there is enough time, you can also capture the timer compare value, double confirm the edge by sensing the GPIO level (it's low or high during the interrupt) then save it for later substraction.

AGHAZ
Associate II

thank you for your answers, I will try both solutions.

S.Ma
Principal

Bonne chance!

AGHAZ
Associate II

The core frequency SYSCLK I defined it at 100HZ, the frequency of the signal to be measured I will check it as soon as possible. Firstly, I want to find a starting solution.

I put you in the frame: I work with an UltraSon sensor and I want to measure the two rise and fall times of the Echo signal, so I only have one input. I think I can not work on two TIMER channels for the moment.

S.Ma
Principal

So use timer channel 1 and 2 of a timer and activate interrupt on both rise and fall edge of both channel.

Activate the interrupt on both channels.

The higher the timer frequency the more precise the delta measurement.

AGHAZ
Associate II

but how can I use two channels of a timer for only one input !

S.Ma
Principal

You are mentionning 2 rise and 2 fall time, meaning you probably have 2 signals to measure or 1 as output and 1 as echo feedback. If they are both pulses, they should be generated possibly from the same timer.