Even in PBP you'll be able to do it with a decent result. Just use the internal timer. The following example is more than enough to start.
Code:
' Pulse High and Low Timer
' ========================
'
' File name : PulseHighLowTimer.bas
' Company : Mister E
' Programmer : Steve Monfette
' Date : 13/01/2006
' Device : PIC16F88
'
'
' This program measure and send to PC, the value of incomming pulses.
' The program will send measure of High pulse and Low Pulse length in uSec.
'
' Hardware configuration
' ======================
DEFINE OSC 20
DEFINE LOADER_USED 1
TRISB = %00000100 ' RB2 as input => Serial RX
TRISA = 255 ' PORTA As input
CMCON = 7 ' Disable analog comparator
ANSEL = 0 ' Disable all A/d
T1CON = 0 ' TIMER1:
' Clock Internal
' Pre-scaller 1:1
'
' Hardware connection
' ===================
SignalInput var PORTA.2
'
' Serial Communication definition
' ===============================
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 129 ' 9600 Bauds
DEFINE HSER_CLROERR 1
'
' Alias Definition definition
' ===========================
T1ON var T1CON.0
'
' Variables definition
' ===================
PulseHigh var word
PulseLow var word
'
' Software/Hardware initialisation
' ================================
CLEAR
GOSUB ClearTimer
'
' ////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
' Program Start Here
'
' ////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
Start:
'
' Waiting for falling edge
' ========================
'
WHILE SIGNALINPUT=0 : WEND
WHILE SIGNALINPUT=1 : WEND
'
' Measure low pulse
' =================
'
T1ON=1 ' start Timer
WHILE SIGNALINPUT=0 : WEND ' wait for next rising edge
T1ON=0 ' stop timer
PULSElow.HIGHBYTE=TMR1H ' store results
PULSElow.LOWBYTE=TMR1L '
pulselow=pulselow / 5 ' 1 tick = 0.2 Usec @ 20MHZ
' Divide by 5 to have 1 uSec
' Resolution
gosub Cleartimer ' reset Timer1 register (TMR1L, TMR1H)
'
' Waiting for rising edge
' =======================
'
while Signalinput=1 : Wend
while signalinput=0 : wend
'
' Measure high pulse
' ==================
'
T1ON=1 ' Start timer
WHILE SIGNALINPUT=1 : WEND ' wait for next falling edge
T1ON=0 ' Stop Timer
PULSEhigh.HIGHBYTE=TMR1H ' Store result
PULSEhigh.LOWBYTE=TMR1L '
pulsehigh=pulsehigh / 5 ' match results to 1 uSec resolution
gosub Cleartimer ' reset Timer1 register (TMR1L, TMR1H)
'
' Send results to PC via RS-232
' =============================
'
hserout ["PulseLow =",dec pulselow, " uSec",13,10,_
"PulseHigh=",dec pulsehigh," uSec",13,10,_
rep "*"\50,13,10]
pause 1000
goto start
ClearTimer:
TMR1L=0
TMR1H=0
RETURN
I agree, you can have a bit more accuracy in pure assembler... but test with the above first.
It's only one way to do it... that's the results of a 10 minutes coding... on friday 13
Bookmarks