Parallel measures on two signals

Hello,

For a project, I have to make measurements on radar signals : an A signal, continous, squared and symmetrical, with a frequency of 4 kHz/a period of 250 µs, representing the 16 384 radar pulses, and a B signal, a single pulse lasting 125 µs every 4.096 seconds, showing that a new lap has started.

I want to make two measures on each signal : counting the number of pulses (so in theory 16 384 signal A pulses between two signal B pulses), and couting the length of each pulse (still in theory 250 / 2 = 125 µs).

Using interrupts, I managed to count accurately the pulses of both signals, so this part is ok.

The problem is measuring in parallel the length of the pulses of both signals : at first I used the micros() function on rising and falling edges, then calculated the substraction to get the length of the pulses. Unfortunately, this function "only" offers a 4 µs accuracy, and I want 1 µs accuracy.

Then I tried the pulseIn() function, which seems to offer 1 µs accuracy, but it is blocking : the signal B pulses are separated by about 4 seconds, so in the meantime, the length of the signal A pulses are not measured.

Today I worked with protothreads and a library offering 0.5 µs accuracy, but I didn't manage to do what I want.

So, before being lost in a huge amount of code, I'm here to ask you for your help : do you have any advice on this project ? Is it feasible ? Do you have any idea to help me progress ?

Thank you in advance ! :)

PS : I also posted in the French subsection as French is my native language, so it is easier for me to explain things, but the Project Guidance subsection fits better my needs. I'll keep both topics updated.

The best accuracy is with the input capture mode of one of the internal timers.

aarg: The best accuracy is with the input capture mode of one of the internal timers.

Right, then the timer prescaler can be set to 1:1, so that the timer clock equals the system clock (16MHz). Please note that the trigger edge has to be changed in the ISR, in order to also capture the second edge. See "Using the Input Capture Unit" in the controller data sheet. Take care not to miss very short pulses, where the second edge arrives before the first edge time is read and the trigger edge is changed in code.

The B signal should not require timing, I suppose, it's only required to determine the start of the next scan/sweep. This can be accomplished with any interrupt.

With an Arduino DUE, code 2 timer capture with 2 timers (TC_CMR register in capture mode), do the calculations inside the loop() and you are done.

aarg: The best accuracy is with the input capture mode of one of the internal timers.

I'd like to have 1 µs accuracy, which the library I used seems to offer, using the Timer2 input timer I think.

DrDiettrich: Please note that the trigger edge has to be changed in the ISR, in order to also capture the second edge. See "Using the Input Capture Unit" in the controller data sheet. Take care not to miss very short pulses, where the second edge arrives before the first edge time is read and the trigger edge is changed in code.

The B signal should not require timing, I suppose, it's only required to determine the start of the next scan/sweep. This can be accomplished with any interrupt.

Yes, I already did that trigger edge change in each function called by the interrupts ;) I count the A signal pulses on the falling edges and the B signal ones on the rising edges, so I'm sure that even when two pulses happen at the same time, they are both counted.

ard_newbie: With an Arduino DUE, code 2 timer capture with 2 timers (TC_CMR register in capture mode), do the calculations inside the loop() and you are done.

Are you 100 % sure that using an Arduino Due would allow me to display all my data in the Arduino console via Serial.print() ? If so, I'll keep that in mind if I can't do what I want with an Uno ! ;)