Best way to measure pulse width greater than timer size.

Technical questions regarding the XTC tools and programming with XMOS.
Matt
Active Member
Posts: 50
Joined: Sat Feb 13, 2010 12:04 pm

Best way to measure pulse width greater than timer size.

Post by Matt »

Hey Guys,

I am trying to figure the best way to measure the time between transitions on a one bit port.
The problem is some transitions are longer than the 32 bit counter period.
Secondly I need to log the times of up to 100 sequential transitions.
I have experimented with the
inp when pinsneq(pinstate) :> pinstate @ ttime;
and then do the math on sequential reads but this gives me numbers that are not useful

I am guessing that I could use a case statement that uses a variable to track if the counter rolls over but I am also guessing that someone has already figured the best way and wouldnt mind letting me know.

Cheers

Matt


User avatar
paul
XCore Addict
Posts: 169
Joined: Fri Jan 08, 2010 12:13 am

Post by paul »

A good way (depending on the resolution you need) is to attach a clock block to the port and then divide down the clock rate - you can use the function listed below which is documented in the xs1.h section of the documentation in <xmos tool root>/doc/libs/html/index.html

Code: Select all

configure_clock_rate	(	clock 	clk,
unsigned 	a,
unsigned 	b	 
)	
This should allow you with a standard ref clock get down to ref / (2*255).

By the way- port timers (using the @ syntax) are only 16 bit and by default run at the reference clock speed, which is usually 100MHz unless you have explicitly set it to another value.
Paul

On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.