- Name:
-
count
- Syntax:
-
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).
- Description:
-
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:
| Clock Signal |
Signal Frequency |
Width Frequency |
| 4MHz |
40us |
25kHz |
| 8MHz |
20us |
50kHz |
| 16MHz |
10us |
100kHz |
| 32MHz |
5us |
200kHz |
| 64MHz |
2.5us |
400kHz |
The unit of time for the sampling period is also affected by the operating speed.
| Clock Frequency |
Sample Period Time Unit |
| 4MHz |
1ms (1000 us) |
| 8MHz |
500 us |
| 16MHz |
250 us |
| 32MHz |
125 us |
| 64MHz |
62.5 us |