1 /* FreeEMS - the open source engine management system
3 Copyright 2008, 2009 Fred Cooke
5 This file is part of the FreeEMS project.
7 FreeEMS software is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 FreeEMS software is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/
20 We ask that if you make any changes to this file you email them upstream to
21 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
23 Thank you for choosing FreeEMS to run your engine! */
26 /** @file globalConstants.c
27 * @ingroup dataInitialisers
29 * @brief Global constant values
31 * All global constants values are, and should be, defined here.
37 #define GLOBAL_CONSTANTS_C
38 #define NO_CONST_ARRAYS
39 #include "inc/freeEMS.h"
44 * BEWARE : Be explicit!!
46 * char 8 bit (defaults to unsigned, but always specify signed/unsigned anyway)
47 * short 16 bit (defaults to signed, but always specify signed/unsigned anyway)
48 * 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)
49 * long 32 bit (defaults to signed, but always specify signed/unsigned anyway)
50 * long long 64 bit (inefficient, avoid these, if using : defaults to signed, but always specify signed/unsigned anyway)
51 * float 32 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math)
52 * double 64 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math)
56 const unsigned short memdumplength
= 0x100;
57 const unsigned short maxBasicDatalogLength
= sizeof(CoreVar
) + sizeof(DerivedVar
) + sizeof(ADCArray
);
61 /* &&&&&&&&&& WARNING &&&&&&&&&& These need to be changed if the timer period is changed at all!! &&&&&&&&&& WARNING &&&&&&&&&& */
62 /* 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. */
64 /** Serial interface unique identifier
66 * This should only change when the serial interface changes (even a little)
68 * This field consists of 3 chars for a 3 part version number and a free form string. For any unique string the version
69 * number is also unique. In this way tools can easily support a range of versions for a specific unique string ID
71 const unsigned char interfaceVersionAndType
[20] = {0,0,2,'I','F','r','e','e','E','M','S',' ','V','a','n','i','l','l','a',0};
73 /** Displayable firmware version identifier
75 * This should change every time the code is changed at all (even a little) before each release.
77 const unsigned char firmwareVersion
[45] = {"FreeEMS Vanilla 0.0.20 pre-release pre-alpha"};
79 /** Divisors and untunable physical constants combined into a single master fuel constant
81 * const unsigned short molarMassOfAir = 2897; // in grams per 100 moles, so divide by 100 to get gm/mol
82 * const unsigned short msToTicks = 1250; // constant to bring ms into 0.8us chunks
83 * const unsigned short universalGasConstant = 34056; // 8.314472 * 4096, so divide by 4096 to get real number
85 * hash define injectorFlowDivisor 1024
86 * hash define injectorFlowUnitDivisor 1000 - to get it into litres/second
87 * hash define injectorFlowTotalDivisor 1024000
88 * hash define stoichiometricAFRDivisor 1024
89 * hash define universalGasConstantDivisor 4096
90 * hash define molarMassOfAirDivisor 100
91 * hash define perCylinderVolumeDivisor 32768
93 * master = (msToTicks * molarMassOfAir * universalGasConstantDivisor * stoichiometricAFRDivisor * injectorFlowTotalDivisor) / (universalGasConstant * molarMassOfAirDivisor * perCylinderVolumeDivisor);
94 * master = (1250 * 2897 * 4096 * 1024 * 1024000 ) / (34056 * 100 * 32768 );
95 * http://www.google.com/search?hl=en&safe=off&q=((1250+*+2897+*+4096+*+1024+*+1024000)+%2F+(34056+*++100+*+32768)&btnG=Search
97 * ((1250 * 2897 * 4096 * 1024 * 1024000) / (34056 * 100 * 32768) = 139371764
99 const unsigned long masterFuelConstant
= 139371764;
101 /** MAF fuel constant
103 * @todo TODO Determine what the value of MAF fuel constant should be
105 const unsigned long MAFFuelConstant
= 0;
107 /* Injection limits */
108 /* The number of timer units it takes for the switch on scheduling code to run */
109 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 */
111 /* The number of timer units it takes for the switch off scheduling code to run */
112 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 */
114 /* The maximum a requested pulsewidth can be before it is truncated to this amount */
115 const unsigned short injectorMaximumPulseWidth
= 0xF424; /* 62500 clock cycles, = exactly 50ms, which is an arbitrary limit but I like round numbers :-) */
117 /* The minimum a requested pulsewidth can be before it is not switched on at all */
118 const unsigned short injectorMinimumPulseWidth
= 100;
121 /* Ignition limits */
122 /* Ignition maximum dwell in timer units */
123 const unsigned short ignitionMaximumDwell
= 50000; /* meaningless us value for now, currently unused */
125 /* Ignition minimum dwell in timer units */
126 const unsigned short ignitionMinimumDwell
= 500; /* meaningless us value for now, currently unused */
128 /* Ignition maximum delay post schedule tooth in timer units */
129 const unsigned short ignitionMaximumDelayToDwellStartAfterTooth
= 50000; /* (max retard) meaningless us value for now, currently unused */
131 /* Ignition maximum delay post schedule tooth in timer units */
132 const unsigned short ignitionMinimumDelayToDwellStartAfterTooth
= 500; /* (max advance) meaningless us value for now, currently unused */
135 /* Engine position/RPM decoder limits */
137 const unsigned short leadingEdgePrimaryRPMInputCodeTime
= 100; /* random large safe value */
140 const unsigned short trailingEdgePrimaryRPMInputCodeTime
= 100; /* random large safe value */
143 const unsigned short leadingEdgeSecondaryRPMInputCodeTime
= 100; /* random large safe value */
146 const unsigned short trailingEdgeSecondaryRPMInputCodeTime
= 100; /* random large safe value */
148 // TODO put these where they belong, just dumped from other file for now...
149 /* Main injector channel bit masks and registers for use in both injection_isrs.c and engine_position_isrs.c */
150 /* Masks for setting mainOn flags and checking state of pin and therefore which change of state just occured */
151 /* Masks for clearing mainOn flags */
152 /* Masks for setting mainOn flags and checking state of pin and therefore which change of state just occured */
153 /* Masks to be used with |= to switch a channel to "turn on compare" mode */
154 /* Masks to be used dissable with &= to switch a channel to "turn off compare" mode */
155 /* Masks to be used with |= to switch a channel to "turn on on compare" mode from "turn off on compare" mode */
156 /* Masks to be used with &= to switch a channel to "turn off on compare" mode from "turn on on compare" mode */
157 /* Ignition channel bit masks for use in both PIT timer ISRs and engine_position_isrs.c */
158 /* Masks for setting ignition status bits and turning on the channels themselves */
159 /* Masks for clearing ignition status bits and turning off the channels themselves */
162 /* 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}; */
163 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 */
164 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 */
166 /* Injection masks */
167 const unsigned char injectorMainOnMasks
[INJECTION_CHANNELS
] = {BIT2
, BIT3
, BIT4
, BIT5
, BIT6
, BIT7
};
168 const unsigned char injectorMainOffMasks
[INJECTION_CHANNELS
] = {NBIT2
, NBIT3
, NBIT4
, NBIT5
, NBIT6
, NBIT7
};
169 const unsigned char injectorMainEnableMasks
[INJECTION_CHANNELS
] = {0x30, 0xC0, 0x03, 0x0C, 0x30, 0xC0};
170 const unsigned char injectorMainDisableMasks
[INJECTION_CHANNELS
] = {0xCF, 0x3F, 0xFC, 0xF3, 0xCF, 0x3F};
171 const unsigned char injectorMainGoHighMasks
[INJECTION_CHANNELS
] = {BIT4
, BIT6
, BIT0
, BIT2
, BIT4
, BIT6
};
172 const unsigned char injectorMainGoLowMasks
[INJECTION_CHANNELS
] = {NBIT4
, NBIT6
, NBIT0
, NBIT2
, NBIT4
, NBIT6
};