I am using pinseq to try and find the delay between the leading edges of two square wave inputs,
thus
while{
start when pinseq(1) :> void;
tmr :> tStart;
stop when pinseq(1) :> void;
tmr :> tStop;
.......................
}
The problem is (of course, once I saw it) was that the start line triggers repeatedly while the input square wave is high.
Is there any neat way of making the code respond to edges rather than levels? I had thought that the peek() function might work in conjunction with a toggle variable but there must be a neater way?
John.
Edge triggering?
-
- Experienced Member
- Posts: 93
- Joined: Fri Dec 11, 2009 1:39 pm
-
- Active Member
- Posts: 35
- Joined: Mon Dec 14, 2009 4:40 pm
You could try
Code: Select all
start when pinseq(1) :> void;
tmr :> tStart;
stop when pinseq(1) :> void;
tmr :> tStop;
start when pinseq(0) :> void;
Laurent
lm.wibaux@gmail.com
lm.wibaux@gmail.com
-
- Experienced Member
- Posts: 93
- Joined: Fri Dec 11, 2009 1:39 pm
Hi,
The cure _was_ easy. The peek() function solved the problem, now pinseq is not called if 'start' is high, thus:
while{
if(peek(start)==0) // only wait for start with input low
{
start when pinseq(1) :> void;
tmr :> tStart;
stop when pinseq(1) :> void;
tmr :> tStop;
tmr :> t;
delay = delay + (tStop - tStart);
...........................
}
}
John.
The cure _was_ easy. The peek() function solved the problem, now pinseq is not called if 'start' is high, thus:
while{
if(peek(start)==0) // only wait for start with input low
{
start when pinseq(1) :> void;
tmr :> tStart;
stop when pinseq(1) :> void;
tmr :> tStop;
tmr :> t;
delay = delay + (tStop - tStart);
...........................
}
}
John.
-
- XCore Addict
- Posts: 165
- Joined: Wed Feb 10, 2010 2:32 pm
Or along similar lines to wibauxl:
Code: Select all
while{
start when pinseq(0) :> void;
start when pinseq(1) :> void;
tmr :> tStart;
stop when pinseq(1) :> void;
tmr :> tStop;
...
}
-
- Experienced Member
- Posts: 93
- Joined: Fri Dec 11, 2009 1:39 pm
Thanks for the code sample. I will try it shortly as it's simpler than my version.
The next problem is tackling the problem when there is no stop pulse (optics out of line, etc). In my simple code , stop when pinseq(1) :> void; , the program would hang forever if no stop pulse occurs, I think.
I could use one of the pinsneq_at(), pinseq_at() functions but they seem to be an AND sort of functions, the value and the time have both to be true. I need a sort of OR function. In the case of the value being zero, the code would bypass the data accumulation steps.
As usual any ideas are welcome.
John.
The next problem is tackling the problem when there is no stop pulse (optics out of line, etc). In my simple code , stop when pinseq(1) :> void; , the program would hang forever if no stop pulse occurs, I think.
I could use one of the pinsneq_at(), pinseq_at() functions but they seem to be an AND sort of functions, the value and the time have both to be true. I need a sort of OR function. In the case of the value being zero, the code would bypass the data accumulation steps.
As usual any ideas are welcome.
John.
-
- XCore Addict
- Posts: 165
- Joined: Wed Feb 10, 2010 2:32 pm
I guess you'd want to wait for stop to be asserted unless it takes a long time. What about this? It provides a timeout if stop isn't asserted quickly enough.
Code: Select all
select {
case stop when pinseq(1) :> void:
stopTimeout = 0;
break;
case tmr when timerafter(timeout) :> void:
stopTimeout = 1;
break;
}
-
- Experienced Member
- Posts: 93
- Joined: Fri Dec 11, 2009 1:39 pm
That's pretty neat. I will try it today.Woody wrote: select {
case stop when pinseq(1) :> void:
stopTimeout = 0;
break;
case tmr when timerafter(timeout) :> void:
stopTimeout = 1;
break;
}
The problem I can see is that this may slow down the capturing the stop signal time accurately. I am looking at time differences in the tens of nanoseconds, say 50 - 100 nsecs. I am hoping to get adequate resolution by stacking lots of data and allowing the system jitter to randomise the timing.
At the present I can resolve differences of 3 nsec or better. I guess that the select/case statements resolve to branch instructions so that should not put too much delay into the code?
John.
-
- XCore Addict
- Posts: 165
- Joined: Wed Feb 10, 2010 2:32 pm
Sounds like what you need is a timestamped output (see section 4.3 of 'Programming XC on XMOS Devices' (http://www.xmos.com/system/files/xcuser_en.pdf)). This allows you to save the time that the transition occurred rather than having to read a timer afterwards
So long as start and stop are both clocked off the 100MHz reference clock you will get resolution of about 10ns. If you need higher resolution you can try increasing the reference clock to 500MHz for 2ns resolution. That's probably +/- 2ns on that resolution though.
Code: Select all
start when pinseq(0) :> void;
start when pinseq(1) :> void @ startHiTime;
stop when pinseq(1) :> void @ stopHiTime;
}
-
- Experienced Member
- Posts: 93
- Joined: Fri Dec 11, 2009 1:39 pm
I am still having some problems measuring very short delays with the code shown below.
The input is a pair of pulses separated in this example by about 6 nsec (the top two traces in the attachment). The third trace is the test port (test <: 1, test <: 0).
Code: Select all
if(peek(start)==0) // only wait for start with input low
{
start when pinseq(1) :> void; // @ tStart;
tmr :> tStart;
test <: 1;
stop when pinseq(1) :> void; // @ tStop;
tmr :> tStop;
test <: 0;
tmr :> t;
delay = delay + (tStop - tStart);
This means that I cant measure any delays less than about 60 nsecs which might be OK for my project but I would still like to understand what is happening. Above 60 nsecs the delay measurement is as expected.
John.
You do not have the required permissions to view the files attached to this post.
-
- Experienced Member
- Posts: 93
- Joined: Fri Dec 11, 2009 1:39 pm
Hi,
I forgot to add in my previous post that I had tested the code at both 100 Mhz and 200 Mhz reference clocks but the minimum measurement time remained the same at about 60 nsecs.
John.
I forgot to add in my previous post that I had tested the code at both 100 Mhz and 200 Mhz reference clocks but the minimum measurement time remained the same at about 60 nsecs.
John.