R/C, Voltage, EGT, and Tachometry Inputs

The PIC16F876 has two analogue inputs which are ideal for sensing onboard battery voltage and an EGT output from the AD595 TC chip. The battery voltage is divided by two series, precision resistors, and the output fed directly into one of the two ADC channel pins. The AD595 is externally biased to keep the output below 5V, and a precision voltage reference, LM336, provides a stable 5V output for ADC comparison.

The RC and Tachometer are measured differently... the RC receiver controls a servo by varying pulse width, and this pulse width is easily measured with a single PicBasic Pro command, PULSIN. The tacho input is a different matter entirely... one cannot measure pulse width, as the width of the pulse will vary with the mechanics of the transducer. Instead, one must measure the number of pulses which arrives at the pin over a given period of time. If the uProcessor counts the number of pulses over a 60 millisecond period, the resulting number indicates the RPM in thousands. For example, 30 pulses in 60 milliseconds = 30,000 RPM. Resolution can be improved by taking a longer sample, but there is a tradeoff in that the uProcessor "hangs" while counting, and cannot monitor other functions. Three 60 mS samples generates a resolution of ~ 300 RPM, which should be more than adequate for a model turbojet, and consumes 0.180 seconds. Of course, a dedicated processor could get a much higher resolution and serially report the results, but this would greatly increase the complexity.

EGT is smoothed and can be software filtered for noise by taking a large number of samples and rejecting aberrant samples which do not fall into the normal range. Currently, this code takes 48 samples and averages the result. Using 8-bit sampling, resolution is +/- 4 degrees C, but the effect of the large sample number is to actually increase the resolution.

Getting the data is easy... the hard part is formatting it for display on the LCD!!

'*							      *
'*			INPUTS.BAS		              *
'*							      *

'This code conglomerates all of the inputs to the PIC chip, including
'EGT, battery voltage, RC throttle inputs, and tachometry.

DEFINE	ADC_CLOCK	3 			'Uses internal RC clock
DEFINE	ADC_SAMPLEUS	10			'Microsecond sample time

EGTChannel	con	1			'Channel 1
VoltChannel	con	     0			'Channel 0

'ADC Variables
Voltage		var		Word		'0 to 1000, where 1000 = 10V
LCDVHigh		var		Byte		'Left of decimal place
LCDVLow		var		Byte		'Right of decimal place

NumSamples	con 		48		'Number of EGT samples to take, Max 254
EGT		var		Word		'Global EGT Reading
EGTSample		var		Byte		'Sample In from AD595
i		var		Byte		'Iterative tool

'Tachometry:  RPMSM is the number of 60 mS samples to take.  Each sample
'represents the actual tach output / 1000.  Resolution increases with
'an increase in RPMNumSamps at the expense of shared processor time.  An RPMNumSamps
'of 3 yields a resolution of +/- 400 RPM

'R/C Input:
ThrotPin		var	PORTB.2		'Pin 21, RC Throttle Signal
Throttle		var	Word		'Sample in from RC
TachPin		var	PORTB.1		'Pin 22, Pulled High, Active Low
RPMSamp		var	Word		
RPM		var	Byte		'High Byte for display and Globally used RPM reference	
RPML		var	Byte		'Low Byte for display		
RPMNumSamps	con	2		'Number of 60 ms Sample times to take

'ADC Subroutines
ADCInit:		   			'Call once to initialize pins and ADCON1 register
	EGT = 0: Voltage = 0		
	TRISA.0 = 1			'Set chnl 0, 1, Vref to Inputs
	TRISA.1 = 1
	TRISA.3 = 1
	ADCON1 = %00000101		'Left Justified Results 


	'For global reference to system voltage, use the Voltage variable, which is based on a
	'scale of 1 to 1000, with 775 = 7.75 volts.  Remember that the resistors on the board
	'divide the actual battery voltage in half so the ADC can "digest" it without damage.
	'ADCIN voltages are limited to 5.  Both EGT and Voltage are compared with the onboard
	'precision voltage reference which delivers a perfect 5V.

	ADCIN VoltChannel, Voltage		'Take just 1 voltage sample. 7.6V = 194
	Voltage = Voltage * 4			'194 * 4 = 776
	LCDVHigh = Voltage / 100		'776 / 100 rounds to 7
	LCDVLow = (Voltage // 100) / 10	'776 // 100 = 76, 76 / 10 = 7
						'Final Display = 7.7

	'** EGT **
	EGT = 0					'Reinitialize EGT
	for i = 0 to NumSamples - 1
		ADCIN EGTChannel, EGTSample    	'0 to 255 EGT sample
		EGT = EGT + ((EGTSample * 255) / 60)   'The equation gives the actual Celcius reading
	next i				       	'Add it all into EGT.

	EGT = EGT / NumSamples			'Divide EGT by the Number of samples

	'Tach and R/C subroutines
	'The greater the number of samples taken, the better the resultion, at the expense
	'of processor time.  More than 4 to 6 really slows the whole thing down.  With three
	'samples or less, it might be best to simply display 1000's rather than XXX.X

	'** RPM **
	'60 ms Sample time yields direct RPM readout in 1000's
	'Comments start with real RPM of 143,578 and RPMNumSamps=3

	Count tachPin, 60 * RPMNumSamps, RPMSamp	'RPMSamp = 430
	RPMSamp = RPMSamp * 10				'RPMSamp = 4300
	RPM = RPMSamp / (RPMNumSamps * 10)		'RPM = 143
	if not RPMNoDecimal then			'Calculate the tenths if RPMNoDecimal = 0
		RPML = RPMSamp // (RPMNumSamps * 10)	'RPML = 10
		RPML = RPML /  RPMNumSamps		'RPML = 3
							'LCD output is thus 143.3

	'** R/C **
	'Measure the pulse width of the incoming RC signal
	Pulsin Throtpin, 0, Throttle


ECU | Gas Turbine | Home | Links | The Shop