Hi all,

I've got some code im testing, basically to decode a trigger wheel, and output 3 pulses per rotation of the wheel which has 35 teeth.

Code:

CMCON = 7						' set portA to digital
TRISA = %00100000				' Port A all output but MCLR
TRISB = %00001000				' Port B all output but 3 (CCP)
InPIN	VAR	PORTB.3				' Define input pin
OutPIN 	VAR	PORTB.5				' Define output pin
LastState   VAR	BIT				' Last Pin State
PulseCount	VAR BYTE			' Number of input pulses
	

PulseCount = 0
Low OutPin

MainLoop:
if InPIN <> LastState then  ' If Input State Changed 

	LastState = InPIN    
	
	PulseCount = PulseCount + 1
					
		Select Case PulseCount
		
			Case 1
			High OutPin
			Case 4
			Low Outpin
			
			Case 12
			High OutPin
			Case 15
			Low Outpin
			
			Case 24
			High Outpin
			Case 27
			Low Outpin
			
			Case 35
			PulseCount = 0
			Low OutPin
			
			Case is > 35
			PulseCount = 0
			Low OutPin
			
			Case Else
			
		End Select

endif
GOTO MainLoop

at maxium wheel rotation speed, the pic input frequency is approx 5khz,
now, at 4mhz, should the pic be able to keep up, or does anyone have any alternative code ideas to help improve the performance?