Hi all.
Im working on a tachometer project, that uses an input from a trigger wheel on an engine, to measure rpm.
The pulses from the trigger wheel are fed into an LM1815 IC, which basically is a zero crossing detector and outputs a 50-70uS positive pulse at each zero cross.
The trigger wheel has 36 teeth, therefore 36 pulses per engine revolution.
My picbasic code for 16F628A uses the CCP1, with a 1:1 prescale and counting 16 rising edges, pic is running at 4mhz.
Basically im measuring the time for 16 teeth on the wheel (which is aprox 0.4 revolutions of the engine) and working out the RPM based on this time.
This works fine up until around 4000 rpm, then it gets unstable - as in the results i get from the pic output fluctuate quite randomly.
I've basically worked out that at 4000 rpm there is approx 2400 pulses per second on the ccp pin and at 6000 rpm there is approx 3600 pulses per sec (0.27 msec between them?).
This means at 4000 rpm, the ccp event fires 150 times / sec and at 6000rpm around 225 times / sec (every 4.4msec)
Would the unstability be caused by a limitation of the CCP part of the pic or would it be due to the code taking too long to execute, causing discrepancies in the timer?
below is a snippet of my code, minus the rpm calculations and minus the various outputs that are triggered at various rpm. See the last few lines where the %%%%% are.... i think the execution time of these lines may contribute to the cause?
Code:TRISA = %00100000 ' Port A all output but MCLR TRISB = %00001010 ' Port B all output but 1,3 (Si and CCP) T1CON = %00000001 ' TMR1 1:1 prescale , and turn it on CCP1CON = %00000111 ' Enable the CCP1 capture, 16th rising edge startloop: IF (capture = 0) Then loop ' Wait here until captured period.lowbyte = CCPR1L ' Store the captured value in period.highbyte = CCPR1H ' period variable IF overflow = 1 then ' Skip the output if the timer overflowed capture = 0 ' Clear capture flag overflow = 0 ' Clear overflow flag goto reset EndIF ***** RPM calcs get done here (i've left them out) ******* SerOut So, N9600, [#rpm,13,10] EndIF capture = 0 'Reset capture flag to wait for next period period = 0 rpm = 0 Reset: IF (capture = 0) Then reset ' Wait here until next period captured TMR1H = 0 ' Clear Timer1 high register %%%%% TMR1L = 0 ' Clear Timer1 low register %%%%% capture = 0 ' Clear capture flag %%%%% overflow = 0 ' Clear overflow flag %%%%% GoTo startloop ' Do it forever


 
						
					 
			 
			 
			 
					
					 CCP question
 CCP question
		 
				
				
				
				
			

Bookmarks