Measure time between OutP <-> InP

Technical questions regarding the XTC tools and programming with XMOS.
abk
Junior Member
Posts: 5
Joined: Mon Jul 04, 2011 9:43 am

Measure time between OutP <-> InP

Post by abk »

I try to measure the time between a signal I create (emitter) and the signal I receive. Emitter and receiver are in different threads, the receiving signal returns quite fast, about 0 to 12,5us. Since the frequency of one thread is 100MHz, I assume the minimal response time I can detect is 10ns (in theory).
I'd be nice to start a async timer with the value of 0 when I emit a signal, stop the timer when I receive the signal. The timervalue would contain the number of cycles passed until the signal was received. Is this possible with xc? I've tried to use the "global" timer value like this (code akin)

Code: Select all

emit(chanend c) {
timer t;
unsigned time;  
portEmit <: 1;
  t :> time;
  c <: time;
}

receiver(chanend c){
timer t;
int dataIn = 0;
unsigned time, emitTime;
  select {
     case portReceive pinsneq(dataIn) :> dataIn
       t :> time;
       printf("diff: %u ", time - emitTime);
     break;
     case c :> emitTime:
     break;
  }
}
and I've tried to connect the out- and in port with a clockblock, using the "@ timerVal" statement to timestamp and compare the timervalues.
The best resolution I got was in a range of 200ns ..

Is one of this approches useful? Is there a better solution?