Cycle Accuracy

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Post by Andy »

Try a buffered port with the relevant bit pattern (remember bits are shifted in and out starting with the least significant bit):

Code: Select all

#include <xs1.h>

out buffered port:32 outClock = XS1_PORT_1A;

int main(void) {

	int bitpattern = 0x77777777;

	// Clock 160 times
	for (int i=0; i<160/8; i++) {

		outClock <: bitpattern;
	}

}


User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

You're first setting "count" to the value of the port timer, and then you're
doing stuff for about 640 (port) cycles. Then you do an output at port
time "count+2". That time has passed, it's a 16 bit counter, you wait
about 65k cycles.

Move the

Code: Select all

outLatch <: 0 @ count;
after the clock loop, and/or fiddle with that "+2" so things happen at
exactly the time you want. Something like "+642", perhaps.

You can also make "outAddress" clocked, etc.
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

Hi Christian,

I think you misunderstand what

Code: Select all

outOE @count <: 0;
means. It does not mean "wait for the port
counter to reach the value "count", and then output 0 on the port"; instead,
it means "output 0 on the port when the port counter reaches "count"". Your
code just keeps running, there is no waiting, so the code that outputs to port
"outLatch" gets to run before the output to "outOE" is done.

Two ways to make it do what you want:
1) Synchronise port outOE after writing to it last, before you access outLatch;
or, preferably
2) do timed accesses to outLatch as well, running off the same clock (they are,
both are the reference clock), and have their counters started together (you
don't have to do anything for that either).