Timer counter in Input Compare

Hi,

I am new in topics on timer with registers in programming. My problem is that I need to get the phase difference between two signals. In the electronic I have two Schmitt triggers that make rissing edge when the reference signal and output signals goes through 0 and my intention is to measure the time between the singals but the phase is around 100-200 nano seconds. So I need to program the Arduino Due with registers to use the TIMER_CLOCK1 which is 84MHz / 2 = 42MHz, around 23 nano seconds period to get the higher speed and accurracy.

Searching in the datasheet I found various tables in page 857-863 and the registers in page 881. The page don't allow two images, sorry. Datasheet

I think (not secure) I need to use two input capture pins (one for each singal) to start and finish the count but I dont know how to do because I don't understand how the registers work, peripheral A and B... and I'm getting confused.

Here you have an image to help you understand the situation:


Subtracting the time of the second timer to the first time and divide by 2 I get the phase in time.

If someone could tell me how to set them up and explain it to me so I can understand it, please.

Thanks so much.

(Sorry for my english is not my matern language)

That's used for rotary encoder (quadrature) phase A and phase B, that's used to determine rotation direction and counted pulses.

you could use two interrupts inputs and calculate the time between the two rising edges for the phase shift. And the time between two calls from the same input to determine the period (frequency) of the signal.

The QDEC function is not really designed for what you want to do.

Since 100 ns is very short compared to a clock cycle duration (~ 8 clock cycles), using interruptions would be a no go.

Maybe a blocking code by reading PIO_PDSR for Pulse 1 high level then Pulse 2
high level plus SysTick-VAL timer counter to get the highest granularity. Anyway the error upon measurement could be 1 to 4 clock cycles .....

But acting on an interruption is slower than acting directly on the records? or for my application would the interruption be sufficient?

you could use two interrupts inputs and calculate the time between the two rising edges for the phase shift. And the time between two calls from the same input to determine the period (frequency) of the signal.

Exactly that's what I want to do, but I don't know how to configure the two timers in input capture to get the difference...

Do you mean to tell me to use two normal digital inputs? But Systick is a single timer, isn't it? How would I get the phase difference between the two signals according to the schematic I showed? Or are you trying to tell me to directly collect the time between the high state of pulse 1 and pulse 2?

if the time is only + - 10 cycles you need a faster CPU. It seems to me that another type of card like the rasberry PI can be an alternative.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.