XK-1A board: timer reading instability

Technical questions regarding the XTC tools and programming with XMOS.
cicga
Active Member
Posts: 51
Joined: Tue Oct 11, 2011 4:48 pm

XK-1A board: timer reading instability

Post by cicga »

Hi all

little help needed...

I am watching periodic pulse signal. Period is not stable - the is some time variation. And this is what I need - check instability of period. In 99% timer giving a right values, but some time it show 0 or very small numbers - 33 or 12 or 58 etc. (normal number for process in the order of ~1000).

here is a code:

while(1)
{
h_b when pinseq(0):>void;
h_cntr++;

switch(h_cntr)
{
case 1:t:>t_start; break;
case 2:t:>t_stop;

us_per = (t_stop-t_start)/1000;

low_b = us_per&0xFF;
high_b = us_per>>8;
uart_send(low_b,high_b);

h_cntr = 0;
break;
}

h_b when pinseq(1):>void;
}

2.)how many timers has each XK-1A?
3) Is it possible to reset timer to zero value for allways start from 0?

regards
cicga


User avatar
yamada
Member
Posts: 9
Joined: Wed Nov 02, 2011 2:49 am

Post by yamada »

Hello, cicga

1)
[a] If you use console out function, such as printf, timer counting will stop during sending data to PC.
There is this limitation when you use old XTAG or old XDE.

Did you try to loop-back test? Make other thread to output same wave continuously and connect the output port to port h_b.


2) XK-1A includes single XS1-L1.
XS1-L1 has two tile.
Each tile has 10 timers.

3) I don't know how to, and why to...
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

Let's unroll your code so it is a bit clearer, and rotate
the loop a bit:

Code: Select all

	while(1) {
		h_b when pinseq(1):>void;
		h_b when pinseq(0):>void;
		t:>t_start;

		h_b when pinseq(1):>void;
		h_b when pinseq(0):>void;
		t:>t_stop;

		us_per = (t_stop-t_start)/1000;
                low_b = us_per&0xFF;
                high_b = us_per>>8;            
                uart_send(low_b,high_b);
	}
(Let's hope t_start and t_stop are unsigned!)

So now it's clear the code measures the (approximate) time between falling
edges on h_b, and it does not give wrong numbers when it misses a pulse
when uart_send takes too long.

That leaves two questions:
i) Is this actually the correct thing to measure, or do you need the rising
edges instead? Is the pulse length (almost) constant?
ii) Did you check that the pulses actually are like you expect them to be?
3) Is it possible to reset timer to zero value for allways start from 0?
Even if you can, you do not want to: all timers have the same value at all
times, so resetting one timer's value resets all of them, which will cause
havoc for every other timer user.
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

yamada wrote:Hello, cicga

1)
[a] If you use console out function, such as printf, timer counting will stop during sending data to PC.
There is this limitation when you use old XTAG or old XDE.

Did you try to loop-back test? Make other thread to output same wave continuously and connect the output port to port h_b.


2) XK-1A includes single XS1-L1.
XS1-L1 has two tile.
Each tile has 10 timers.

3) I don't know how to, and why to...


XS1-L1's are single tile, thus 10 timers
cicga
Active Member
Posts: 51
Joined: Tue Oct 11, 2011 4:48 pm

Post by cicga »

Hi all

thanks for all answers...

segher:
- your process is sligtly different from mine, but it does not look that this is a process flow that causing reading instability...
- process cannot miss mise a pulse when uart_send takes too long because uart is working 115200 speed and process period is about 10ms (time between falling edges)- way to long compare to uart sending time
- plus uart is sending data after it made all measurements and even if will send data too long it does not matter - process start from the begining after data was send.


thats sad that all timers have the same value - that limiting process handling...

yamada:
" Did you try to loop-back test? Make other thread to output same wave continuously and connect the output port to port h_b."
thats exactly what I am doing - one thread generate signals imitating real process and it is connected to port h_b. :)

Bianco:
thanks for info about timers. can u point where did you find this info?

best,
cicga
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

The number of tiles is in the first page of the datasheet.
The number of timers per tile can be found in the block diagram in the datasheet.