How would cnt work doing this
Hello
I want to measure time useing the counter (cnt)·
So what I was going to do was·to get·the cnt value when a pin goes high and then get the cnt value·again when it goes low and subtract the second cnt value by the frist, which will tell me how many clock tiks passed during that time.
My question is will that work?· Because if the 2 cnt values are with in the 32 bit range it would work.
But wouldn't it fail if the first value was at the end of the 32 bit counter and then the counter started at 0 again.·The second cnt value·being say 100 and the the first being 3,999,991,000, which would give me a huge wrong negative number.
So I guess what I'm trying to say is would that be an accurate way to measure time repeatedly, or would it have a possible glitch at the end of the 32 bit counter?? is there some internal program that would eliminate that??
Or what could I do to eliminate that glitch?? like writeing·code that if the counter is equal to or greater then X to just ignor that peoried of time and then start mesureing clock tiks on the next loop around the counter??
Thanks
·
I want to measure time useing the counter (cnt)·
So what I was going to do was·to get·the cnt value when a pin goes high and then get the cnt value·again when it goes low and subtract the second cnt value by the frist, which will tell me how many clock tiks passed during that time.
My question is will that work?· Because if the 2 cnt values are with in the 32 bit range it would work.
But wouldn't it fail if the first value was at the end of the 32 bit counter and then the counter started at 0 again.·The second cnt value·being say 100 and the the first being 3,999,991,000, which would give me a huge wrong negative number.
So I guess what I'm trying to say is would that be an accurate way to measure time repeatedly, or would it have a possible glitch at the end of the 32 bit counter?? is there some internal program that would eliminate that??
Or what could I do to eliminate that glitch?? like writeing·code that if the counter is equal to or greater then X to just ignor that peoried of time and then start mesureing clock tiks on the next loop around the counter??
Thanks
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Just a few PropSTICK Kit bare PCBs left!
What you might also want to do is check out this application note on the Counters...
http://www.parallax.com/Portals/0/Downloads/appnt/prop/AN001-PropellerCountersv1.1.zip
...If you set the mode to %11010 or "LOGIC A" and set·the·APIN...
·
CTRA := %11010 << 26 | APIN
FRQA := 1
·
...Then just prior to your pin going HIGH all you need to do is clear the PHSA register to "reset" it.
PHSA := 0
At some time after the·PIN goes low, simply read the PHSA register which will contain the time difference that you are looking for regardless of a counter rollover occurrence from the CNT register.
·
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 10/23/2008 8:13:00 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Well this·is what I came up with so that if·the second count value (measure2) is 100 and·the frist count value (measure1) is 4 billion, my program will ignor·then negative incorrect number and pick up on the next reading.
This would work I do belive.· If the theory of this program works I am going to convert it all over·to assembly code so that it will excute faster and be more accurate. Because I need to be as close to perfect·as I possibly can.
Also I heard someone mention that they could mesure the overhead or time the processor takes to preform all the comands. If so I want to measure the overhead and then advance my reading to be dead·perfect.
Any advise would be great thanks so much ·
·repeat
··· waitpeq (%1000000, %00000000000000000000000001000000, 0)········{wait for pin 6 to go high}
··· measure1 := cnt
··· waitpne (%1000000, %00000000000000000000000001000000, 0)······· {wait for pin 6 to go low}
··· measure2 := cnt
····· begin++··········· 'counts one every time Reader goes high
······· check := (measure2 - measure1)
········· if check < 0
········· Next
··········· degree := check / 10
1. wait for pin to go high
2. grab start cnt value
3. wait for pin to low
4. grab stop cnt value
5. subtract start from stop
If your events can be more than 53 seconds apart you'll have to get more sophisticated.
pgb