timestamp output problem

Technical discussions around xCORE processors (e.g. xcore-200 & xcore.ai).
habmbaramburu
Newbie
Posts: 1
Joined: Sun Jun 09, 2013 5:17 pm

timestamp output problem

Post by habmbaramburu »

I execute this code modified from XC-Programming-Guide:

Code: Select all

#include <platform.h>
#include <xs1.h>
#include <stdio.h>

out port freq_port = XS1_PORT_1G;

void doToggle(out port toggle) {
	int count;
	timer timer1;
	unsigned c1, c2, c3, c4, c5;

	toggle <: 0 @ count; 				// timestamped output
	timer1 :> c1;

	while (1) {
		count += 300;
		toggle @ count <: 1; 			// timed output

		timer1 :> c2;

		count += 300;
		toggle @ count <: 0; 			// timed output

		timer1 :> c3;

		count += 300;
		toggle @ count <: 1; 			// timed output

		timer1 :> c4;
		break;
	}

	printf("c2-c1 = %u \n", c2-c1);
	printf("c3-c2 = %u \n", c3-c2);
	printf("c4-c3 = %u \n", c4-c3);

	printf("stop");
}

int main(void) {

	par {
		doToggle(freq_port);
	}
}
and receive result:
c2-c1 = 16
c3-c2 = 284
c4-c3 = 299
why so different especially the first value?


richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

When you do a timed output the instruction doesn't wait for the output to happen, instead it sets some state in the port to ensure that the specified value is output at the specified time in the future and returns. This explains why a short period of time is measured between c1 and c2.

The port is only able to buffer a single timed output in the future. If you do a timed output and there is already a pending timed output the instruction must pause until the first timed output has taken place before setting up the second timed output. This explains why the time between subsequent output instructions is longer.

To explain the difference between the (c3 - c2) and (c4 - c3) consider the times when the outputs will complete. We know the first output completes at count since we took a timestamp. The second output will complete at count + x (where x is the number of ticks needed to execute the instructions between the first and second output). The third output will pause until the second output has taken place, i.e. it will complete at count + 300. The fourth output will pause until the third output has taken place, i.e. it will complete at count + 600
Therefore we have:

(c2 - c1) = x
(c3 - c2) = (300 - x)
(c4 - c3) = 300

From this point onwards the time elapsed between pairs of output instructions should be 300. The values measured using the timer may might be slightly off these expected values because the timer will be input from slightly after the output instruction actually completes.
lokesh327
Member++
Posts: 29
Joined: Wed Feb 06, 2013 2:24 pm

Post by lokesh327 »

It might also be due to use of printf, i think we have simple_printf() function for xc source
User avatar
Ross
XCore Expert
Posts: 966
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Please note that timer ticks are not the same as port counter values.

You might also like to take a look at sync() (see xs1.h) depending on your application...