pulse counting
muttvac
Posts: 14
in Propeller 1
Hi All, I would like to count low to high transitions on pin 2(I/O 1). Total number of pulse will be displayed on terminal.
Code below. Thanks
Pub Start | pulsecounter
pst.Start(115_200) 'this sets up terminal
CTRA := %01101000000000000000000000000010 ' - pos edge
FRQA := $01 'this is the count of events
PHSA := $01
dira[1] := 0 'make pin 2(P1) an input to receive pulses
repeat
pst.str(string(" CTRA Value = "))
pst.bin(CTRA,32)
pst.str(string(" PHSA Value = "))
pst.bin(PHSA,32)
pst.str(string(" Pulse Count = ")) 'show Pulse Count value
pst.bin(FRQA,32)
pst.newline
Comments
The great thing about the Propeller is that it can test itself. You can create an oscillator with the other counter and connect it to the same pin -- I just did this and it works as expected.
Here's something you can drop into a program to see that the mechanisms work. You'll need to define an output to display the counts (hertz in this case).
I discussed by confusion about differences in pulse counting techniques in this thread. The thread includes code I used to monitor pulses using three different strategies. You might find the code useful for your purposes (though the code JonnyMac posted should do the job just fine).