This is like super-crude... but it'll kinda work as a starting point...
Code:
InputA var PortB.0
InputB var PortB.1
LED var PortB.4
Temp var Byte
ToggleA var Temp.0
ToggleB var Temp.1
CounterA var WORD
InputACount var WORD
InputBCount var WORD
TRISB=%00001111
Start:
'
' Get Ready
' ---------
ToggleA=0
ToggleB=0
InputACount=0
InputBCount=0
High LED ' We're Ready...
'
' Start Count
' -----------
For CounterA=0 to 3999
If (InputA=0 and ToggleA=0) then ToggleA=1
If (InputA=1 and ToggleA=1) then
InputACount=InputACount+1
ToggleA=0
endif
If (InputB=0 and ToggleB=0) then ToggleB=1
If (InputB=1 and ToggleB=1) then
InputBCount=InputBCount+1
ToggleB=0
endif
PauseUS 250
Next CounterA
'
' Stop Count
' ----------
Low LED
LCDOut $FE,1,"A=",#InputACount,"Hz"
LCDOut $FE,$C0,"B=",#InputBCount,"Hz"
Goto Start ' Loop forever
Yes, of course there are limitations... you'll have to trim PauseUS so that the For/Next Loop is exactly 1 second long... so put a scope on the LED pin... another limitation is that your Pulse must be wider than about 270uS so you may need some external circuitry... another is that probably 3.5kHz is a practical maximum count... but go play...
Bookmarks