Accurate Timing
Jason Crystal
Posts: 3
Hello,
I wish to measure the length of time between events (specifically, the length of pulses ranging from 0.5 to 8 seconds). However, these measurements must be very accurate (preferably to the millisecond). The Pulsin command doesn't work for me because of the maximum pulse width allowed.
One option that I've explored is attaching a 555 chip and counting the number of pulses. However, is there a way for the Stamp to count these pulses while still performing other functions?
Any ideas or suggestions would be welcome!
Thank you!
-Jason
I wish to measure the length of time between events (specifically, the length of pulses ranging from 0.5 to 8 seconds). However, these measurements must be very accurate (preferably to the millisecond). The Pulsin command doesn't work for me because of the maximum pulse width allowed.
One option that I've explored is attaching a 555 chip and counting the number of pulses. However, is there a way for the Stamp to count these pulses while still performing other functions?
Any ideas or suggestions would be welcome!
Thank you!
-Jason
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 8/1/2005 3:43:47 PM GMT
Doesn't PULSIN sense the TRANSITION from Low to High (or vice versa) when determining whether to evaluate the time? From what I gather from the documentation, if PULSIN does not receive a transition within the specified period of time (based on what Stamp model you have), it will return zero. So, given your function above, I think it would always return zero (or infinitely loop) because in an 7sec pulse there would only be one transition.
Or am I reading into this incorrectly?
Thanks,
-Jason
The only time the code will never exit is if there is never a transition on the line you are monitoring.
You can think of OuterCount as just extending the value of PULSIN into a larger number, with OuterCount a byte you are working with a 24-bit number (16 bits returned by PULSIN and 8 bits for OuterCounter). With·OuterCount a word variable you are working with a 32 bit number (16 bits from PULSIN, 16 bits from OuterCount).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 7/26/2005 5:31:03 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Thanks guys,
-Jason
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
verify this pulse length. I tried the code posted by Paul baker but keep getting zero's . Here is the code I am using,
any help would be really appreciated.
' {$STAMP BS2}
' {$PBASIC 2.5}
OuterCount VAR Word
time······ VAR Word
OuterCount = -1
DO
·PULSIN 0, 1, time
·OuterCount = OuterCount + 1
LOOP UNTIL time = 0
DEBUG " outercount = ", DEC outercount,CR
DEBUG " time······ = ", DEC time····· ,CR
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
you code exactly. When I run it, I get an error message with ·"while" highlited
saying "expected a label, variable, or instruction".·· ·If I change the "while time =0"
to "loop until time > 0"· The program runs, but returns zeros in my debug statements.
This seems like such a great programming tool for measuring long pulses. I hope
·you will be able to solve this for me.
Larry
' {$STAMP BS2}
' {$PBASIC 2.5}
OuterCount VAR Word
time······ VAR Word
DEBUG " outercount = ", DEC outercount,CR
DEBUG " time······ = ", DEC time····· ,CR
OuterCount = -1
DO
·PULSIN 0, 1, time
·OuterCount = OuterCount + 1
'LOOP UNTIL time > 0
WHILE time=0
DEBUG " outercount = ", DEC outercount,CR
DEBUG " time······ = ", DEC time····· ,CR
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Post Edited (Chris Savage (Parallax)) : 8/1/2005 2:57:41 PM GMT
the transition from· zero to five volts. I connected my volt meter in parallel with Stamp pin zero, and because the pulse from the 555 is so slow (400MS) I can see the change,
on my meter, so I know the transistion from zero to five is reaching the stamp.
In order to eliminate the stamp as the source of my problem, I duplicated the little circuit in the stamp manual for PULSIN. It ran perfectly. So again I am stumped.
Larry
·· When I run your code I get the following results...With a 10hz signal into P0 I get:
outercount = 0
time = 0
outcount = 0
time = 22966
·· When I change the frquency to 100hz, I get:
outercount = 0
time = 0
outcount = 0
time = 2300
·· When I change the frequency to 1000hz, I get:
outercount = 0
time = 0
outcount = 0
time = 230
Not sure what exactly you're trying to do.· A negative one for start value will result in 65535 in that variable initially.· It will be zero on the first pass through the loop, and since there is a signal, I don't see it changing on my end.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I just found out you can't quote your own post, ended up editing the original.
Here it is reprinted:
I must appologize, my original code was not according to PBASIC requirements, the following code should work:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Here is what I am attempting to do
I have a 555 timer chip I have set it up to generate a very slow pulse of .76 seconds on and .69 seconds off. I have verified that the 555 is outputing a pulse (+5V) as it is slow enough to observe on my volt meter.
I know that the value of the components I've used will cause these times to be slightly off. I am trying to measure
the actual pulse· time using the pulsin command.· Still not sure where I have gone wrong.....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
components. It's one of those things that should work but doesn't. I suspect it may be how I am connecting the output of
the 555 to the stamp. It's pretty straight forward. The output goes thru a 1k resistor then to the stamp.
Thanks for all the tips, It got me going in the right direction....
···
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com