globalDefines.h

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

Generated on Mon Nov 10 21:18:50 2008 for freeems by  doxygen 1.5.2