Reconciling XTA and simulator results.

Technical questions regarding the XTC tools and programming with XMOS.
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Reconciling XTA and simulator results.

Post by Heater »

I'm having a bit of trouble reconciling the output of the XTA and the simulator. To me it looks as if the simulator is actually producing correct output on a pin faster than XTA says is possible!!

Whilst trying to get the hang of the XMOS tools I have been playing with a simple pin toggling loop using the port timer. The code is shown below.

First up I use XTA to tell me the execution time of the loop in the toggle_pin thread. For this I have the xta pragma shown in the code and an xta script like so:

Code: Select all

analyze loop toggle_loop
set required - 200 ns
print summary
This results in a timing analysis output like so:

Code: Select all

Route(0) loop: toggle_loop
    Pass with 2 unknowns, Num Paths: 1, Slack: 12.5 ns, Required: 200.0 ns, Worst: 187.5 ns, Min Core Frequency: 375 MHz
First question here is how to get rid of the two warnings about not knowing the execution time of a couple of instructions?

Anyway it looks as if my pin toggling loop is only good for 187ns per transition.

Next I move on to the simulator. Notice that in the code I have a PERIOD defined as 15. This gives a output on the simulator of the pin toggling every 150ns.

So there it is. The simulator is saying I can run the code about 20% faster than the timing analyser.

Why is that?

Code: Select all

#include <platform.h>
//#define PERIOD  20         // 200ns OK
#define PERIOD  15         // 150ns OK
//#define PERIOD  14         // 100ns FAIL

port p = PORT_UART_TX;
int x = 0;

int y;

void do_some_stuff()
{
	x = ~x;
}

void toggle_pin()
{
	int t;
	p <: 0 @ t;              // Timestamped output, 0 goes to p, port clock goes to t
	t += PERIOD;
	while (1)
	{
		#pragma xta endpoint "toggle_loop"
		p  @ t <: x ;        // Timed output x goes to p at time t.
		do_some_stuff();
		t += PERIOD;
	}
}

void waste_thread(){}

int main()
{
	par
	{
		on stdcore[0]: toggle_pin();
		on stdcore[0]: waste_thread();
		on stdcore[0]: waste_thread();
		on stdcore[0]: waste_thread();
		on stdcore[0]: waste_thread();
	}
	return (0);
}


User avatar
davelacey
Experienced Member
Posts: 104
Joined: Fri Dec 11, 2009 8:29 pm

Post by davelacey »

Your waste_thread function will complete and then the thread will wait for all the other threads to complete at the end of the par. At this point the thread will be descheduled. So in your example you will only have 1 thread running not 5. Try this instead:

Code: Select all

 void waste_thread() {while (1);}
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Post by Heater »

Well spotted. My waste_thread seems to have been gutted as I cut and pasted it around the place. To busy getting to grips with the tools to pay attention to the code. Retesting this will have to wait until Saturday. Have a good weekend.
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Post by Heater »

OK. This is all starting to look very good.

With the waste_thread corrected the XTA reports that the timed_loop takes 187.5 ns in the worst case.
All right, that means we can set the toggle period to 19 (190ns) and everything should work. And, according to the simulator, so it does.

Also dropping the period to 18 (180ns) should fail. And so it does.

In a rather interesting way though. It tries very hard to toggle producing 11 transitions with the following times between them:

180, 180, 180, 180, 180, 190, 170, 210, 150, 220

After which it flat lines to a logic high as shown in the attachment.
pin_toggle.png
You do not have the required permissions to view the files attached to this post.