COUNT pin, period, wordvariable
Pin - is a variable/constant which specifies the input pin to use.
Period - is a variable/constant (1-65535ms at 4MHz).
Wordvariable - receives the result (0-65535).
Count pulses on an input pin.
Count checks the state of the input pin and counts the number of low to high transitions within the time 'period'. A word variable should be used for 'variable'. At 4MHz the input pin is checked every 20us, so the highest frequency of pulses that can be counted is 25kHz, presuming a 50% duty cycle (ie equal on-off time). Take care with mechanical switches, which may cause multiple 'hits' for each switch push as the metal contacts 'bounce' upon closure.
Effect of increased clock speed
For all PICAXE chips the minimum width of a clocking signal (total time of high and low added together) and that signal's maximum frequency will be as follows:
The unit of time for the sampling period is also affected by the operating speed.
||Sample Period Time Unit
||1ms (1000 us)
The 'count' command can count up to 65535 pulses and a 16-bit word variable is required to store numbers that high.
An 8-bit byte variable can only hold a maximum value of 255 so, if more than 255 pulses are counted, the number stored in the byte variable will not accurately reflect the actual count of pulses.
For this reason it is recommend that a word variable is used to store the count of pulses.
If it is known there will never be more than 255 pulses during the period of the count, or it does not matter if the variable does not hold an accurate count when there are more than 255 pulses, then a byte variable may be used.