Timer 1 for frequency measurement
Hi MuarI,
Use timer1 to count the pulses and PBP can still count the time interval.
Here's a code snippet of a 16F676 for a low frequency meter (1s gate time)
cmcon = 7 'for pic10F206
ansel = 0 'for 16F676
'for LCD on port c
DEFINE LCD_DREG PORTC
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 5
DEFINE LCD_LINES 2
ct0 var word 'total number of counts
t1hi var ct0.byte1 'high byte of timer1
t1lo var ct0.byte0 'low byte of timer1
ovf var bit 'overflow flag bit
sermode var byte 'serial port mode
ctime var word 'counting time
sermode = 6 '1200 Baud inverted
ctime = 1000 'CPS 1000mS gate time
Pause 500 'allow LCD to startup
lcdout $fe,1 , "PIC Counter V1.1"
lcdout $fe, $c0, " C G8RPI 2005 "
Pause 1500
lcdout $fe,1
Goto main 'bypass subroutines
getcount:
porta.2 =1 'turn "gate" led on
t1con = 7 'set timer 1 on, external clock, non sync = bit0 =1, bit1 =1, bit2 =1
tmr1h = 0 'clear timer 1 high byte
tmr1l = 0 'clear timer 1 low byte
pir1 = 0 'clear overflow flag
pause ctime 'wait
t1con = 0 'stop timer 1 , bit0 =0
porta.2 =0 'turn led off
t1lo = tmr1l
t1hi = tmr1h
ovf = pir1
if ovf = 1 then
Serout porta.0,sermode,["OVER-RANGE" ,13 ,10]
lcdout $fe, $c0,"OVER-RANGE"
else
Serout porta.0,sermode,[#ct0 ," "]
lcdout $fe, $c0,#ct0, " "
endif
Return
Main:
gosub getcount
goto main
it outputs the frequency on an LCD and a serial port.
HTH,
Robert G8RPI.