Timestamped input

Technical questions regarding the XTC tools and programming with XMOS.
PoohEng
New User
Posts: 3
Joined: Fri Sep 24, 2010 8:08 pm

Timestamped input

Post by PoohEng »

Hello all,

The following is a simple thread that captures an input port and time stamps it.

Code: Select all

void inp()
{
	unsigned short pinState;
	unsigned int timeIn;
	timer t;

	p3Capture :> pinState;
	while(1)
	{
		p3Capture when pinsneq(pinState) :> pinState @ timeIn;
		//p3Capture when pinsneq(pinState) :> pinState;
		//t :> timeIn;
	    if(timeIn > 65535)
	    {
	    	printhex(pinState); printstr("@");printuintln(timeIn);
	    }
	}
}
The following line

Code: Select all

		p3Capture when pinsneq(pinState) :> pinState @ timeIn;
yields a timeIn value that rolls over in 16-bits. However, replacing this
with the commented lines

Code: Select all

		p3Capture when pinsneq(pinState) :> pinState;
		t :> timeIn;
yields a value that does not roll over in 16-bits (as expected). What is going on?

Thanks.


User avatar
bsmithyman
Experienced Member
Posts: 126
Joined: Fri Feb 12, 2010 10:31 pm

Post by bsmithyman »

PoohEng wrote:... What is going on?
Hi PoohEng,

Page 43 of "Programming XC on XMOS Devices" talks about timestamped outputs (i.e. using the @ character). These return the value of the port counter, not a timer value. I believe port counters are 16-bit and timers are 32-bit. They're also not necessarily in sync with each other.

If you're trying to time things with the rest of the program, it's probably best to use the timer method. If you're trying to work with a reference clock, using a port counter is probably the right way to go.

Hope this helps :)
PoohEng
New User
Posts: 3
Joined: Fri Sep 24, 2010 8:08 pm

Post by PoohEng »

bsmithyman wrote:
PoohEng wrote:... What is going on?
Hi PoohEng,

...
These return the value of the port counter, not a timer value. I believe port counters are 16-bit and timers are 32-bit.
...

Hope this helps :)
bsmithyman,
Thanks. I looked at the assembly for the two different code snippets and
in the case of the timestamped input (using @) one of the the instructions
generated is a GETTS instruction ("XMOS XS1 Architecture" manual, pages 30 and 109).
This instruction grabs a port timer (as you have rightly pointed out) which is
16-bits wide.

Thanks again,
PoohEng
User avatar
bsmithyman
Experienced Member
Posts: 126
Joined: Fri Feb 12, 2010 10:31 pm

Post by bsmithyman »

No worries, glad to help :)