I'm trying to use the "counter/timer" of the picaxe 28x2
to count pulses on pin C.0 while my program is busy doing other things.
I was getting more counts than expected, and assumed that there might
be "contact bounce" as the input is derived from an analogue source.
I therefore decided to test the mechanism using an output pin on the same chip to drive the counter input.
Circuit:
a completely bare AXE200 surface mount 28x2 module with -
pins 27,28 connected to a 9v PP3 power source. with 1000uF capacitor.
pin 5 (C.0) connected to pin6 (C.1)
That's it!
Program:
let dirsc = %00000010
SETTIMER COUNT 65535
do
pause 500
inc b2
toggle c.1 ' provide pulse to counter input
b0=pinsc ' report value for debug
b1=timer ' report value for debug
debug
loop
Results: using the above program, b1 (timer) is reported to increase by two every time round the loop.
B2 is alternately one or two more than b1. B0 reads alternately 3, and 0
I conclude that the timer circuit is counting 2 for every positive transition.
Further tests:
I changed the preload value from 65535 to 65534, and the program behaved as expected.
B1 increases by 1 every other loop. B1 is approximately half the value of b2.
With a preload of 65533, B1 counted every 3 times round the loop.
I want it to count up by one every time round the loop.
How do I make it do this?
John Fisher
to count pulses on pin C.0 while my program is busy doing other things.
I was getting more counts than expected, and assumed that there might
be "contact bounce" as the input is derived from an analogue source.
I therefore decided to test the mechanism using an output pin on the same chip to drive the counter input.
Circuit:
a completely bare AXE200 surface mount 28x2 module with -
pins 27,28 connected to a 9v PP3 power source. with 1000uF capacitor.
pin 5 (C.0) connected to pin6 (C.1)
That's it!
Program:
let dirsc = %00000010
SETTIMER COUNT 65535
do
pause 500
inc b2
toggle c.1 ' provide pulse to counter input
b0=pinsc ' report value for debug
b1=timer ' report value for debug
debug
loop
Results: using the above program, b1 (timer) is reported to increase by two every time round the loop.
B2 is alternately one or two more than b1. B0 reads alternately 3, and 0
I conclude that the timer circuit is counting 2 for every positive transition.
Further tests:
I changed the preload value from 65535 to 65534, and the program behaved as expected.
B1 increases by 1 every other loop. B1 is approximately half the value of b2.
With a preload of 65533, B1 counted every 3 times round the loop.
I want it to count up by one every time round the loop.
How do I make it do this?
John Fisher