Measuring microseconds?

Hello forum,

To measure the round trip time of a packet from wixel1 to wixel2 back to wixel1 I want a better resolution than getMs().
I think the DelayMicroseconds of time.h won’t help here.

  1. Doese someone already know how long it takes to send a packet or even how long the round trip time with good connection would be?
  2. Does anyone have experience with changing the interrupt prescaler to get better resolution?
  3. Suggestions for a better solution than 2?

I don’t want to add an external timer IC to the wixel.

Thanks!
Mathias

Some data: when I set the prescaler of Timer4 (who is in charge of getMS) to other values than 111, I can measure sub-ms intervals.
So I set up a busy loop that takes on average 209 ms with a prescaler of 0b111 (i.e., T4CTL = 0b11111010, first 3 bits are prescale value) and compare it to the output of getMs for different values of the prescaler:

T4CTL ### loop time units ### factor relative to original ms
0b111… ### 209 ### 1.00
0b110… ### 420 ### 2.001
0b101… ### 847 ### 4.05
0b100… ### 1721 ### 8.234
0b011… ### 3560 ### 17.03
0b010… ### 7644 ### 36.57
0b001… ### 17924 ### 85.76

As expected, the extra overhead of more and more interrupts is visible.
However, with a setting of T4CTL = 0b01111010 I get 1/17ths ms tics, which is ok for me (i.e., getMs() now returns values of 17ths miliseconds).
For the lower prescaler steeing I don’t expect the wixel to do anything much more than counting time :wink:

Hello. It generally takes around 400 microseconds to send a packet, so if you aren’t losing any packets and you know what you are doing you could probably get a round trip in about a millisecond.

I haven’t tried changing the getMs() timer for better resolution. Several libraries depend on getMs(), so changing its behavior could cause problems. The Wixel has three other timers you could use, and one of them (Timer 1) is 16-bit.

–David

I endend up with summing the round trip time 1000 times and measured via USB serial.
The round trip time in my particular setting is on average 1.2 ms including average 4% packet loss (with a timeout of 2ms).

That’s a very nice result for me although I have to check it with about 10m distance.

Thanks,
Mathias