00001 /* Copyright 2008 Fred Cooke 00002 00003 This file is part of the FreeEMS project. 00004 00005 FreeEMS software is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 FreeEMS software is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/ 00017 00018 We ask that if you make any changes to this file you email them upstream to 00019 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com! 00020 00021 Thank you for choosing FreeEMS to run your engine! */ 00022 00023 00039 /* Header file multiple inclusion protection courtesy eclipse Header Template */ 00040 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */ 00041 #ifndef FILE_GLOBALDEFINES_H_SEEN 00042 #define FILE_GLOBALDEFINES_H_SEEN 00043 00044 00045 /* TODO perhaps configure various ports and pins etc to have names such that the 00046 * code can stay untouched when being ported and just the header changed to suit? 00047 * definitely a good idea, but we'll see what karsten says before putting time 00048 * into it. something like : #define RPM_IN_MAIN IC0 etc etc 00049 */ 00050 00051 00052 /* Definitions for functions used across the project */ 00053 /* http://www.seattlerobotics.org/encoder/200109/encoder.htm section Assembly */ 00054 #define INLINE_ASSEMBLY(code) __asm__ __volatile__ (code) 00055 #define ALWAYS_INLINE __attribute__((always_inline)) 00056 00057 /* Common macro definitions across the project */ 00058 /* Boolean */ 00059 #define FALSE 0 00060 #define TRUE !FALSE /* http://c2.com/cgi/wiki?CeePreprocessorStatements */ 00061 00062 /* 8 bit values */ 00063 #define ZEROS 0x00 00064 #define ONES 0xFF 00065 00066 /* 16 bit values */ 00067 #define ZEROS16 0x0000 00068 #define ONES16 0xFFFF 00069 00070 /* Halves and Maxes */ 00071 #define LONGHALF 0x80000000 /* 2147483648 */ 00072 #define LONGMAX 0xFFFFFFFF /* 4294967295*/ 00073 #define SHORTHALF 0x8000 /* 32768 */ 00074 #define SHORTMAX 0xFFFF /* 65535 */ 00075 00076 /* Individual bits WARNING, do not not these for notted versions, use the notted ones below instead : http://supp.iar.com/Support/?note=12582&from=search+result */ 00077 #define BIT0 0x01 /* 1st bit = 1 */ 00078 #define BIT1 0x02 /* 2nd bit = 2 */ 00079 #define BIT2 0x04 /* 3rd bit = 4 */ 00080 #define BIT3 0x08 /* 4th bit = 8 */ 00081 #define BIT4 0x10 /* 5th bit = 16 */ 00082 #define BIT5 0x20 /* 6th bit = 32 */ 00083 #define BIT6 0x40 /* 7th bit = 64 */ 00084 #define BIT7 0x80 /* 8th bit = 128 */ 00085 00086 #define BIT0_16 0x0001 /* 1st bit = 1 */ 00087 #define BIT1_16 0x0002 /* 2nd bit = 2 */ 00088 #define BIT2_16 0x0004 /* 3rd bit = 4 */ 00089 #define BIT3_16 0x0008 /* 4th bit = 8 */ 00090 #define BIT4_16 0x0010 /* 5th bit = 16 */ 00091 #define BIT5_16 0x0020 /* 6th bit = 32 */ 00092 #define BIT6_16 0x0040 /* 7th bit = 64 */ 00093 #define BIT7_16 0x0080 /* 8th bit = 128 */ 00094 00095 #define BIT8_16 0x0100 /* 9th bit = 256 */ 00096 #define BIT9_16 0x0200 /* 10th bit = 512 */ 00097 #define BIT10_16 0x0400 /* 11th bit = 1024 */ 00098 #define BIT11_16 0x0800 /* 12th bit = 2048 */ 00099 #define BIT12_16 0x1000 /* 13th bit = 4096 */ 00100 #define BIT13_16 0x2000 /* 14th bit = 8192 */ 00101 #define BIT14_16 0x4000 /* 15th bit = 16384 */ 00102 #define BIT15_16 0x8000 /* 16th bit = 32768 */ 00103 00104 /* Individual bits NOTTED : http://supp.iar.com/Support/?note=12582&from=search+result */ 00105 #define NBIT0 0xFE /* 1st bit = 1 */ 00106 #define NBIT1 0xFD /* 2nd bit = 2 */ 00107 #define NBIT2 0xFB /* 3rd bit = 4 */ 00108 #define NBIT3 0xF7 /* 4th bit = 8 */ 00109 #define NBIT4 0xEF /* 5th bit = 16 */ 00110 #define NBIT5 0xDF /* 6th bit = 32 */ 00111 #define NBIT6 0xBF /* 7th bit = 64 */ 00112 #define NBIT7 0x7F /* 8th bit = 128 */ 00113 00114 #define NBIT0_16 0xFFFE /* 1st bit = 1 */ 00115 #define NBIT1_16 0xFFFD /* 2nd bit = 2 */ 00116 #define NBIT2_16 0xFFFB /* 3rd bit = 4 */ 00117 #define NBIT3_16 0xFFF7 /* 4th bit = 8 */ 00118 #define NBIT4_16 0xFFEF /* 5th bit = 16 */ 00119 #define NBIT5_16 0xFFDF /* 6th bit = 32 */ 00120 #define NBIT6_16 0xFFBF /* 7th bit = 64 */ 00121 #define NBIT7_16 0xFF7F /* 8th bit = 128 */ 00122 00123 #define NBIT8_16 0xFEFF /* 9th bit = 256 */ 00124 #define NBIT9_16 0xFDFF /* 10th bit = 512 */ 00125 #define NBIT10_16 0xFBFF /* 11th bit = 1024 */ 00126 #define NBIT11_16 0xF7FF /* 12th bit = 2048 */ 00127 #define NBIT12_16 0xEFFF /* 13th bit = 4096 */ 00128 #define NBIT13_16 0xDFFF /* 14th bit = 8192 */ 00129 #define NBIT14_16 0xBFFF /* 15th bit = 16384 */ 00130 #define NBIT15_16 0x7FFF /* 16th bit = 32768 */ 00131 00132 00133 /* Serial Comms Stuff */ 00134 #define ESCAPE_BYTE 0xBB 00135 #define START_BYTE 0xAA 00136 #define STOP_BYTE 0xCC 00137 #define ESCAPED_ESCAPE_BYTE 0x44 00138 #define ESCAPED_START_BYTE 0x55 00139 #define ESCAPED_STOP_BYTE 0x33 00140 #define flashSectorSize 1024 00141 #define flashSectorSizeInWords 512 /* 512 words to a 1k flash sector */ 00142 00143 00144 #define RPM_FACTOR 2 00145 #define MAP_FACTOR 100 00146 #define TPS_FACTOR 640 00147 #define BRV_FACTOR 1000 00148 #define TEMP_FACTOR 100 00149 #define EGO_FACTOR 32768 00150 00151 00152 #define idleManifoldPressure 3000 /* 30 kPa */ 00153 #define seaLevelKPa 10000 /* 100 kPa */ 00154 #define maxExpectedBoost 30000 /* 300 kPa */ 00155 00156 #define freezingPoint 27315 /* 0 Celcius */ 00157 #define roomTemperature 29315 /* 20 Celcius */ 00158 #define runningTemperature 35815 /* 85 Celcius */ 00159 00160 #define halfThrottle 32768 /* 50% throttle */ 00161 #define runningVoltage 14400 /* 14.4 Volts */ 00162 #define idlePulseWidth 2000 /* ~1.5ms */ 00163 #define idleAirFlow 1500 /* guessed */ 00164 00165 #define typicalCylinderSize 16384 /* 500cc per cylinder */ 00166 #define typicalInjectorSize 9387 /* 550cc per minute */ 00167 00168 #define densityOfOctane 22496 /* 703 grams per litre */ 00169 #define stoichiometricLambda 32768 /* Lambda = 1.0 */ 00170 00171 /* Generated with http://www.diyefi.org/calculators.htm#stoich */ 00172 #define stoichiometricAFRMethane 17245 /* 17.245 AFR */ 00173 #define stoichiometricAFRPropane 15685 /* 15.685 AFR */ 00174 #define stoichiometricAFRLPG 15599 /* 15.599 AFR */ 00175 #define stoichiometricAFRButane 15469 /* 15.469 AFR */ 00176 #define stoichiometricAFROctane 15137 /* 15.137 AFR */ 00177 #define stoichiometricAFRGasoline 14700 /* 14.700 AFR */ 00178 #define stoichiometricAFRXylene 13681 /* 13.681 AFR */ 00179 #define stoichiometricAFRToluene 13512 /* 13.512 AFR */ 00180 #define stoichiometricAFRBenzene 13282 /* 13.282 AFR */ 00181 #define stoichiometricAFRE85 9862 /* 9.862 AFR */ 00182 #define stoichiometricAFREthanol 9008 /* 9.008 AFR */ 00183 #define stoichiometricAFRMethanol 6475 /* 6.475 AFR */ 00184 00185 #define batteryVoltageMin 0 /* Voltage read at lowest ADC reading */ 00186 #define batteryVoltageRange 24500 /* Voltage difference between lowest and highest ADC reading */ 00187 00188 #define LC1LambdaMin 16384 /* Lambda read at lowest ADC reading */ 00189 #define LC1LambdaMax 49152 /* Lambda read at highest ADC reading */ 00190 #define LC1LambdaRange 32768 /* Lambda difference between lowest and highest ADC reading */ 00191 00192 #define AFR1020LambdaMin 16384 /* Lambda read at lowest ADC reading */ 00193 #define AFR1020LambdaMax 49152 /* Lambda read at highest ADC reading */ 00194 #define AFR1020LambdaRange 32768 /* Lambda difference between lowest and highest ADC reading */ 00195 00196 00197 /* MAP Sensor Data Explanation 00198 * 00199 * Motorola/Freescale pressure sensor data obtained from the 00200 * data sheets by extrapolation of the "typical" line to the 00201 * borders of the transfer function chart. This gives us the 00202 * correct values in the middle despite not being able to 00203 * reach the ends of the scale. 00204 * 00205 * By min and max I mean the OV and 5V pressures that aren't 00206 * attainable, but that give the correct function in between. 00207 */ 00208 00209 00210 /* www.freescale.com/files/sensors/doc/data_sheet/MPX4100A.pdf */ 00211 #define MPX4100AMin 1400 /* Pressure read at lowest ADC reading */ 00212 #define MPX4100AMax 10750 /* Pressure read at highest ADC reading */ 00213 #define MPX4100ARange 9350 /* Pressure difference between lowest and highest ADC readings */ 00214 00215 /* www.freescale.com/files/sensors/doc/data_sheet/MPX4250A.pdf */ 00216 #define MPX4250AMin 800 /* Pressure read at lowest ADC reading */ 00217 #define MPX4250AMax 26000 /* Pressure read at highest ADC reading */ 00218 #define MPX4250ARange 25200 /* Pressure difference between lowest and highest ADC readings */ 00219 00220 #define MPXH6300AMin 1200 /* Pressure read at lowest ADC reading */ 00221 #define MPXH6300AMax 32000 /* Pressure read at highest ADC reading */ 00222 #define MPXH6300ARange 30800 /* Pressure difference between lowest and highest ADC readings */ 00223 00224 #define MPXH6400AMin 1200 /* Pressure read at lowest ADC reading */ 00225 #define MPXH6400AMax 42000 /* Pressure read at highest ADC reading */ 00226 #define MPXH6400ARange 40800 /* Pressure difference between lowest and highest ADC readings */ 00227 00228 #define TPSDefaultMin 255 /* ADC reading at lowest throttle position */ 00229 #define TPSDefaultMax 767 /* ADC reading at highest throttle position */ 00230 00231 #define offIdleMAP 3000 /* 30kPa just above where MAP would be with closed throttle at idle */ 00232 #define nearlyWOTMAP 9500 /* 95kPa just below where MAP would be at WOT */ 00233 00234 #define ticksPerCycleAtOneRPMx2 300000000 /* twice how many 0.8us ticks there are in between engine cycles at 1 RPM */ 00235 #define ticksPerCycleAtOneRPM 150000000 /* how many 0.8us ticks there are in between engine cycles at 1 RPM */ 00236 #define tachoTickFactor4at50 6 /* Provides for a 4 cylinder down to 50 RPM */ 00237 /*efine tachoEdgesPerCycle4at50 8 / 8 events per cycle for a typical 4 cylinder tacho, 4 on, 4 off */ 00238 #define tachoTotalFactor4at50 48 /* http://www.google.com/search?hl=en&safe=off&q=((150000000+%2F+6)+%2F++8+)+%2F+50&btnG=Search */ 00239 //#define ticksForFiftyRPM 3000000 /* ticksPerCycleAtOneRPM / 50 */ 00240 00241 //#define lookedUpVEDivisor 512 00242 //#define VEpercentageDivisor 100 00243 #define oneHundredPercentVE 51200 00244 00245 //#define densityOfFuelDivisor 32 00246 //#define densityOfFuelUnitDivisor 1000 00247 #define densityOfFuelTotalDivisor 32000 00248 00249 #define divisorFor115200bps 22 /* (40MHz / (16*115.2kHz)) = 21.7013889 */ 00250 /* http://www.google.com/search?hl=en&safe=off&q=22%2F%28%2840000000%2F16%29%2F115200%29&btnG=Search 1.376% error in speed */ 00251 /* http://www.google.com/search?hl=en&safe=off&q=40MHz%2F%2816*22%29&btnG=Search 113.636 kHz */ 00252 00253 /* Not 1024, the number of gaps between them */ 00254 #define ADC_DIVISIONS 1023 00255 00256 #define IGNITION_CHANNELS 12 /* How many ignition channels the code should support */ 00257 #define INJECTION_CHANNELS 6 /* How many injection channels the code should support */ 00258 00259 /* Ignition defines */ 00260 #define DWELL_ENABLE BIT0 00261 #define DWELL_DISABLE NBIT0 00262 #define IGNITION_ENABLE BIT1 00263 #define IGNITION_DISABLE NBIT1 00264 00265 /* Valid RPAGE values : 00266 * 0xFF - linear 00267 * 0xFE - linear 00268 * 0xFD - default 00269 * 0xFC 00270 * 0xFB 00271 * 0xFA 00272 * 0xF9 00273 * 0xF8 00274 */ 00275 /* The reset value of RPAGE is 0xFD */ 00276 /* The other 8k of linear RAM space is accessible */ 00277 /* through the RPAGE window with 0xFE and 0xFF */ 00278 /* 0xFE refers to the 0x2000 to 0x3000 region */ 00279 /* 0xFF refers to the 0x3000 to 0x4000 region */ 00280 #define RPAGE_TUNE_ONE 0xF8 00281 #define RPAGE_TUNE_TWO 0xF9 00282 #define RPAGE_FUEL_ONE 0xFA 00283 #define RPAGE_FUEL_TWO 0xFB 00284 #define RPAGE_TIME_ONE 0xFC 00285 #define RPAGE_TIME_TWO 0xFD 00286 00287 00288 /* The TX and RX buffers are slightly larger than 2k because the RX buffer */ 00289 /* needs to also receive a header, checksum and attributes for the data */ 00290 /* involved and the TX buffer needs to handle all of those two fold. */ 00291 #define TX_BUFFER_SIZE 0x0820 00292 #define RX_BUFFER_SIZE 0x0810 00293 #define TransferTableSize 2048 00294 00295 00296 #else 00297 /* let us know if we are being untidy with headers */ 00298 #warning "Header file GLOBALDEFINES_H seen before, sort it out!" 00299 /* end of the wrapper ifdef from the very top */ 00300 #endif