As Joe already mentioned earlier, RA4 T0CKI is a Schmitt Trigger input. If your sensor doesn't output a minimum voltage of 0.8 * VDD for logic 1 and 0.2 * VDD or less for logic 0, then the Schmitt Trigger input isn't seeing the correct logic levels, and TMR0 isn't counting your pulses.
Here's a quick little test program to show how it works when RA4/T0CKI is connected to an I/O-pin to increment the counter.
It works great, but only as long as the input signal meets the threshold levels the Schmitt Trigger input buffer on RA4/T0CKI expects.Code:@ DEVICE pic16F88, INTRC_OSC, CCPMX_ON, MCLR_OFF DEFINE HSER_BAUD 2400 Loops VAR BYTE Revs var BYTE OSCCON=$60 ' use internal 4MHZ osc ANSEL = 0 ' disable A/D so RA4 is digital CMCON = 7 ' disable comparators TRISA.4=1 ' RA4/T0CKI = input (Timer0 clock input) PORTB.5=1 ' USART TX pin idles high PORTB.0=1 ' clock output pin to RA4 starts high TRISB.0=0 ' clock out pin to RA4/T0CKI = output TRISB.5=0 ' USART TX = output ANSEL = 0 ' disable A/D so RA4 is digital CMCON = 7 ' disable comparators OPTION_REG = %10110001 ' clk on RA4/T0CKI, falling edge, 1:4 prescale Mainloop: TMR0 = 0 ' clear count before each pass ' output 8 clocks on RB0 to RA4/T0CKI FOR Loops = 0 TO 7 PORTB.0=1 ' RB0 connects to RA4/T0CKI PAUSE 5 PORTB.0=0 ' counter increments on falling edge PAUSE 5 NEXT Loops Revs = TMR0 ' get TMR0 count IF OPTION_REG.0 THEN HSEROUT ["Counts at 1:4 prescale: ",dec Revs,13,10] ELSE HSEROUT ["Counts at 1:2 prescale: ",dec Revs,13,10] ENDIF OPTION_REG.0 = OPTION_REG.0 ^ 1 ' toggle 1:4 or 1:2 prescale GOTO Mainloop end




Bookmarks