globalConstants.c

Go to the documentation of this file.
00001 /*      globalConstants.c
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 
00025 #define NO_CONST_ARRAYS
00026 #include "inc/freeEMS.h"
00027 
00028 /* Types summary
00029  *
00030  * BEWARE : Be explicit!!
00031  *
00032  * char                 8 bit (defaults to unsigned, but always specify signed/unsigned anyway)
00033  * short                16 bit (defaults to signed, but always specify signed/unsigned anyway)
00034  * int                  16 bit DO NOT USE! (current compile flags make this 16 bits, but a change of flags could will change your program if you use this because they will all be 32 bit all of a sudden)
00035  * long                 32 bit (defaults to signed, but always specify signed/unsigned anyway)
00036  * long long    64 bit (inefficient, avoid these, if using : defaults to signed, but always specify signed/unsigned anyway)
00037  * float                32 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math)
00038  * double               64 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math)
00039  */
00040 
00041 const unsigned short memdumplength = 0x100;
00042 const unsigned short maxBasicDatalogLength = sizeof(CoreVar) + sizeof(DerivedVar) + sizeof(ADCArray);
00043 
00044 
00045 /* Constants */
00046 /* &&&&&&&&&& WARNING &&&&&&&&&& These need to be changed if the timer period is changed at all!! &&&&&&&&&& WARNING &&&&&&&&&& */
00047 /* TODO It may be better to make these actual times and calculate the number of timer units such that a change in time base of the timer doesn't affect the code. */
00048 
00049 /* Serial interface unique identifier */
00050 const unsigned char interfaceVersionAndType[20] = {0,0,2,'I','F','r','e','e','E','M','S',' ','V','a','n','i','l','l','a',0};
00051 /* This should only change when the serial interface changes (even a little) */
00052 /* This field consists of 3 chars for a 3 part version number and a free form string. For any unique string the version
00053  * number is also unique. In this way tools can easily support a range of versions for a specific unique string ID */
00054 
00055 /* Displayable firmware version identifier */
00056 const unsigned char firmwareVersion[47] = {"FreeEMS Vanilla 0.0.18 JackTheRipper pre-alpha"};
00057 /* This should change everytime the code is changed at all (even a little) before each release. */
00058 
00059 /* divisors and untunable physical constants combined into a single master fuel constant
00060  *
00061  * const unsigned short molarMassOfAir = 2897; // in grams per 100 moles, so divide by 100 to get gm/mol
00062  * const unsigned short msToTicks = 1250; // constant to bring ms into 0.8us chunks
00063  * const unsigned short universalGasConstant = 34056; // 8.314472 * 4096, so divide by 4096 to get real number
00064  *
00065  * #define injectorFlowDivisor 1024
00066  * #define injectorFlowUnitDivisor 1000 - to get it into litres/second
00067  * #define injectorFlowTotalDivisor 1024000
00068  * #define stoichiometricAFRDivisor 1024
00069  * #define universalGasConstantDivisor 4096
00070  * #define molarMassOfAirDivisor 100
00071  * #define perCylinderVolumeDivisor 32768
00072  *
00073  * master = (msToTicks * molarMassOfAir * universalGasConstantDivisor * stoichiometricAFRDivisor * injectorFlowTotalDivisor) / (universalGasConstant * molarMassOfAirDivisor * perCylinderVolumeDivisor);
00074  * master = (1250          * 2897                       * 4096                                            * 1024                                     * 1024000                             ) / (34056                            * 100                                   * 32768                                   );
00075  * http://www.google.com/search?hl=en&safe=off&q=((1250+*+2897+*+4096+*+1024+*+1024000)+%2F+(34056+*++100+*+32768)&btnG=Search */
00076 const unsigned long masterFuelConstant = 139371764; /* ((1250 * 2897 * 4096 * 1024 * 1024000) / (34056 *  100 * 32768) */
00077 
00078 /* Yet to be determined */
00079 const unsigned long MAFFuelConstant = 0;
00080 
00081 /* Injection limits */
00082 /* The number of timer units it takes for the switch on scheduling code to run */
00083 const unsigned short injectorSwitchOnCodeTime = 100; /* Measured 4 timer cycles, going on the safe side by a lot, and limiting minimum pulse to 0.02ms which is well below any dead time I've heard of */
00084 
00085 /* The number of timer units it takes for the switch off scheduling code to run */
00086 const unsigned short injectorSwitchOffCodeTime = 100; /* This is actually shorter than the switch on time above as measured between 0.0.8 and 0.0.9 */
00087 
00088 /* The maximum a requested pulsewidth can be before it is truncated to this amount */
00089 const unsigned short injectorMaximumPulseWidth = 0xF424; /* 62500 clock cycles, = exactly 50ms, which is an arbitrary limit but I like round numbers :-) */
00090 
00091 /* The minimum a requested pulsewidth can be before it is not switched on at all */
00092 const unsigned short injectorMinimumPulseWidth = 100;
00093 
00094 
00095 /* Ignition limits */
00096 /* Ignition maximum dwell in timer units */
00097 const unsigned short ignitionMaximumDwell = 50000; /* meaningless us value for now, currently unused */
00098 
00099 /* Ignition minimum dwell in timer units */
00100 const unsigned short ignitionMinimumDwell = 500; /* meaningless us value for now, currently unused */
00101 
00102 /* Ignition maximum delay post schedule tooth in timer units */
00103 const unsigned short ignitionMaximumDelayToDwellStartAfterTooth = 50000; /* (max retard) meaningless us value for now, currently unused */
00104 
00105 /* Ignition maximum delay post schedule tooth in timer units */
00106 const unsigned short ignitionMinimumDelayToDwellStartAfterTooth = 500; /* (max advance) meaningless us value for now, currently unused */
00107 
00108 
00109 /* Engine position/RPM decoder limits */
00110 /*  */
00111 const unsigned short leadingEdgePrimaryRPMInputCodeTime = 100; /* random large safe value */
00112 
00113 /*  */
00114 const unsigned short trailingEdgePrimaryRPMInputCodeTime = 100; /* random large safe value */
00115 
00116 /*  */
00117 const unsigned short leadingEdgeSecondaryRPMInputCodeTime = 100; /* random large safe value */
00118 
00119 /*  */
00120 const unsigned short trailingEdgeSecondaryRPMInputCodeTime = 100; /* random large safe value */
00121 
00122 // TODO put these where they belong, just dumped from other file for now...
00123 /* Main injector channel bit masks and registers for use in both injection_isrs.c and engine_position_isrs.c */
00124 /* Masks for setting mainOn flags and checking state of pin and therefore which change of state just occured */
00125 /* Masks for clearing mainOn flags */
00126 /* Masks for setting mainOn flags and checking state of pin and therefore which change of state just occured */
00127 /* Masks to be used with |= to switch a channel to "turn on compare" mode */
00128 /* Masks to be used dissable with &= to switch a channel to "turn off compare" mode */
00129 /* Masks to be used with |= to switch a channel to "turn on on compare" mode from "turn off on compare" mode */
00130 /* Masks to be used with &= to switch a channel to "turn off on compare" mode from "turn on on compare" mode */
00131 /* Ignition channel bit masks for use in both PIT timer ISRs and engine_position_isrs.c */
00132 /* Masks for setting ignition status bits and turning on the channels themselves */
00133 /* Masks for clearing ignition status bits and turning off the channels themselves */
00134 
00135 
00136 /* Dwell masks                                            { CYL1 B0, CYL2 B1, CYL3  B2, CYL4  B3, CYL5  B4, CYL6  B5, CYL7  B6, CYL8  B7, CYL9 A0,CYL10 A1,CYL11 A2,CYL12 A3}; */
00137 const unsigned short dwellStartMasks[IGNITION_CHANNELS] = { BIT8_16, BIT9_16, BIT10_16, BIT11_16, BIT12_16, BIT13_16, BIT14_16, BIT15_16, BIT0_16, BIT1_16, BIT2_16, BIT3_16};          /* Set of masks such that a cylinder can be dwelled with a single line of code */
00138 const unsigned short ignitionMasks[IGNITION_CHANNELS]   = {NBIT8_16,NBIT9_16,NBIT10_16,NBIT11_16,NBIT12_16,NBIT13_16,NBIT14_16,NBIT15_16,NBIT0_16,NBIT1_16,NBIT2_16,NBIT3_16};          /* Set of masks such that a cylinder can be fired with a single line of code */
00139 
00140 /* Injection masks */
00141 const unsigned char injectorMainOnMasks[INJECTION_CHANNELS] = {BIT2,  BIT3,  BIT4,  BIT5,  BIT6,  BIT7};
00142 const unsigned char injectorMainOffMasks[INJECTION_CHANNELS] = {NBIT2, NBIT3, NBIT4, NBIT5, NBIT6, NBIT7};
00143 const unsigned char injectorMainEnableMasks[INJECTION_CHANNELS] = {0x30, 0xC0, 0x03, 0x0C, 0x30, 0xC0};
00144 const unsigned char injectorMainDisableMasks[INJECTION_CHANNELS] = {0xCF, 0x3F, 0xFC, 0xF3, 0xCF, 0x3F};
00145 const unsigned char injectorMainGoHighMasks[INJECTION_CHANNELS] = {BIT4, BIT6, BIT0, BIT2, BIT4, BIT6};
00146 const unsigned char injectorMainGoLowMasks[INJECTION_CHANNELS] = {NBIT4, NBIT6, NBIT0, NBIT2, NBIT4, NBIT6};

Generated on Mon Dec 22 21:29:18 2008 for freeems by  doxygen 1.5.2