Cog timers
Christofer A
Posts: 9
Hi all,
I'm hoping to get some help with the timer CTRA.
I would like to measure the pulse with with timer CRTA using the %01X00 POS/NEG detector mode, I only need to measure the pulse with when pin is high.
I'm using this method (code below) today but would like to learn how to do it without waitpeq command.
Would be grateful fore spin example of how to to this.
Thanks in advance.
Christofer A.
I'm hoping to get some help with the timer CTRA.
I would like to measure the pulse with with timer CRTA using the %01X00 POS/NEG detector mode, I only need to measure the pulse with when pin is high.
I'm using this method (code below) today but would like to learn how to do it without waitpeq command.
repeat PHSA := 0 ' reset PHSA to 0 waitpeq(%10000000000000000, %10000000000000000, 0) ' Wait for pin 16 to be high FRQA := 1 ' starts the CTRA counting from 0 waitpne(%10000000000000000, %10000000000000000, 0) ' Wait for pin 16 to be low waitpeq(%10000000000000000, %10000000000000000, 0) ' Wait for pin 16 to be high FRQA := 0 ' stop the accumulation
Would be grateful fore spin example of how to to this.
Thanks in advance.
Christofer A.
Comments
An excellent source for info like this is to have a look at Martin Hebels BS2function.obj
goto the www.obex.parallax.com.au website and download that object..
Look thru the object and find the pulse in PUB.. it is all there.
cheers Ron Nollet Mel OZ
As far as I can understand in BS2, PUB PULSIN_Clk you use a method similar to my example, or am I misunderstanding something?
What I was looking for was a solution when the cog don't need to intervene unless for initialize and reading the result.
Similar to generating one puls by:
maybe it's not possible? After reading the PropellerDatasheet-v1.0.pdf I got this Idea that this was possible! but no luck so far.
Any suggestions?
//Christofer
Graham
Thank you very much Mike Green. I didn't see that It was that simple, just to read PHSA and clear it between pulses.
Thanks everyone for posting.
The trick here is that you don't want to read phsa while the input is high since phsa will be incrementing
and you don't want to sample phsa too close to the next pulse since there's a little delay between the
waitpne and when phsa is sampled and you don't want the next pulse to begin before you've read phsa.
even CNT read from SPIN can give a good result without prior calibration, if done in the right way:
count2-count1 will give you the length of the pulse most likely up to 12.5 ns !!
However, the pulse must be at least 15 µs long, which will restrict this simple approach to a few situations only.