Count
argmafia
Posts: 30
on the BS2 is there a way to keep track of·or count the pulses on a certain input pin without using the pulsein command?· The reason I can't use the pulsein command is because I need·to count the pulse·for an undetermined amount of time.· ·I was trying to use a for loop but was unable to.
Comments
The COUNT command will accumulate the number pulses over a FINITE period of time, but to countinously check over a more infinite or undetermined period time, you will indeed need to use a FOR ... NEXT loop. The following is just a simple example:
PulsePin PIN 1 ' Arbitrarily assign pin port 1
Pulses VAR·WORD 'Count to a max. of·65535 pulses
TimeToStop VAR BIT 'Stop flag (set elsewhere)
NO CON 0
YES CON 1
ProgramStart:
Input PulsePin 'Set pin port to INPUT mode
Pulses = 0
TimeToStop = NO
PulseLoop:
'GOSUB OtherTasks 'Jump out and do other tasks quickly, if necessary
IF TimeToStop = YES GOTO ExitProgram: 'Time to display and quit?
If PulsePin <> 1 GOTO PulseLoop 'Is pulse present, if not try again
Pulses = Pulses + 1 'Accumulate pulses
GOTO PulseLoop 'Return and check again
ExitProgram:
DEBUG "Pulse Count Total = ", Pulses
END
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
Post Edited (Bruce Bates) : 3/8/2006 11:17:13 PM GMT
It sounds like you need a seperate counter circuit that you can read in the value when you want it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Check it again, the posting ran away from me <sigh>.
Bruce
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
--But is the voltage regulator itself capable of handling that high of voltage? Most 5V Regulators begin getting inefficient and heating up after 12V...?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com