MegaSquirt-I™ Electronic Fuel Injection Computer - Coolant and MAT Sensors

The sensor setup for the MegaSquirt-I™ uses a standard General Motors thermistor sensor (part #12146312) for both the coolant and mass air temperature sensors. These are just standard thermistor sensors which have been used by GM since the early 1980's, and can be acquired for less than $8.00. If you are building a MegaSquirt system, it is highly recommended that you use these sensors, because they work and you do not have to generate new files for MegaSquirt.

The thermistor sensor(s) are part of a voltage divider circuit - the top leg is tied to +5 volts, thru a 2490 ohm resistor, then to the thermistor, then to ground (see the schematics) - the junction of the 2490 resistor and the thermistor is monitored by an analog-to-digital converter channel in the MC68HC908GP32 processor (both the coolant and MAT channels are of the same configuration, and feed into their own ADC channels).

The voltage output of the voltage divider is V = 5.0*(R/(R+2490)), with R being the thermistor resistance, and V the voltage. The ADC converts the voltage into "counts" from 0 for zero volts to 255 for 5 volts, or count = V * (255/5.0). Combine the two and you get the resistance value for a corresponding ADC count, and if you know the transfer function for the thermistor correlating resistance to temperature, you are golden.

The file used by MegaSquirt-I™ for the coolant temperature is named, and for the air density correction it is named If you use another sensor type other then the specified GM sensor above, you will have to generate these files for your corresponding sensor (or use EasyTherm to do this for you).

MegaSquirt-II™ uses internal thermistor tables that can be accessed directly in TunerStudio instead (under 'Tools') without have to rewrite or recompile files.

The file is the transfer function of the coolant sensor - it converts ADC counts to temperature in degrees F with an offset of 40 degrees added to it (i.e. for a real temperature of -40 degrees F the file will return a reading of 0, and for a temperature of 215 degrees the file will return 255) - this was done in order to keep the temperature variable inside of the MegaSquirt™-I code as an unsigned 8-bit quantity (0 to 255). The airdenfactor file is the correction (in percent) to the fuel equation due to changes in manifold air inlet temperature. 100 percent (i.e. no correction) is defined at 70 degrees F, and any temperature below this value will yield an increase in percentage (dense air requires more fuel), and temperatures below this will yield a decrease in percentage.

For those of you who want to try their hand at using thermistors other than the GM variety, the following "C" program will help (cut and paste from here into a text editor). This program was used to generate both the air density and coolant temperature files. To modify this program, you will need to know the transfer function for the thermistor, i.e. several temperature points, and its corresponding resistance value(s). Get a pot of water and a digital multimeter and take several temperature/resistance pair readings. You need at least two, but the more the better.

Simply enter the number of pairs for NTEMPS, and change the arrays in the beginning of the code (make sure resistance values are sorted ascending values). Leave the rest of the code alone. Then, compile with any C compiler (MSVC++, gcc, etc) and execute - this will generate the two files in proper format for the P&E assembler. Then, copy them into the directory you have your embedded MegaSquirt code, and reassemble the code using these files, then download into the EFI controller.

/**             Gentherm.c - used for generating thermistor transfer           **/
/**                                 function files for MegaSquirt.                                     **/
/**                                                                                                                              **/
/**               Generates and                    **/
/**                                                                                                                              **/
/**                                  Bruce Bowling, July 2001                                            **/


/* User-defined area here */
/* Thermistor transfer function:
    NTEMPS = Number of temperature-resistance pairs
	temp = temperature array of values (degrees F)
	res = corresponding resistance values (ascending order) */
#define NTEMPS 15
double temp[NTEMPS]={210,194,176,158,140,122,104, 86,  68,  50,  32,  14,   -4,   -22, -40};
double  res[NTEMPS]={177,241,332,467,667,973,1459,2238,3520,5670,9420,16180,28681,52700,100700};
/* End user-defined area */

void main()
	double count, rescalc, tempcalc, ad, adp;
	FILE *fp, *afp;
	int i;

	fp = fopen("./","w");

	afp = fopen("./","w");

	/* Loop over all of the A/D range (0 to 255 for 8 bits) */
	for(count=0.; count <256.; count += 1.0)
		if(count < 0.1 || count > 254.) 
			fprintf(fp, "\tDB\t210T\n"); /* This is the end-pont limp-home values */
			fprintf(afp,"\tDB\t100T\n"); /* This is the end-pont limp-home values */
			/* determine resistance for corresponding count */
			rescalc = 2490./((255/count) - 1);
			/* Find where resistance value lies in res[] array */
			while(i < (NTEMPS - 1) && rescalc > res[i]) i++;
			/* Linear interpolate */
			/* Limit range and write (add 40 degree offset in write */
			if(tempcalc > 215.) tempcalc=215.;
			if(tempcalc < -40.) tempcalc=-40.;
			fprintf(fp,"\tDB\t%dT\n",(int)(tempcalc + 40));

			/* Determine air density correction factor and write */
			ad = 37.943/((tempcalc + 459.7)*1728.0);
			adp = 100.0*(ad/4.157E-5);


© 2003, 2008 Bowling and Grippo. All rights reserved. MegaSquirt® and MicroSquirt® are registered trademarks.