rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
gm_ls_4.cpp
Go to the documentation of this file.
1/*
2 * gm_ls_4.cpp
3 *
4 */
5
6#include "gm_ls_4.h"
7#include "defaults.h"
8#include <rusefi/arrays.h>
9#include "proteus_meta.h"
10#include "settings.h"
11
12#ifdef HW_HELLEN
13#include "hellen_meta.h"
14#endif // HW_HELLEN
15
16void setGmLs4() {
17 strcpy(engineConfiguration->engineMake, ENGINE_MAKE_GM);
18 strcpy(engineConfiguration->engineCode, "gen4");
19 engineConfiguration->globalTriggerAngleOffset = 86;
20 engineConfiguration->vvtMode[0] = VVT_BOSCH_QUICK_START;
21
22 engineConfiguration->etbIdleThrottleRange = 30;
23
24 engineConfiguration->cranking.rpm = 400;
25 engineConfiguration->rpmHardLimit = 6000;
26
27 engineConfiguration->etb.pFactor = 7.320831;
28 engineConfiguration->etb.iFactor = 116.5986;
29 engineConfiguration->etb.dFactor = 0.0765;
30 engineConfiguration->etb.minValue = -90;
31 engineConfiguration->etb.maxValue = 90;
32
33
34#if HW_PROTEUS
35 engineConfiguration->etbFunctions[1] = DC_None;
36
37 setPPSInputs(PROTEUS_IN_ANALOG_VOLT_2, PROTEUS_IN_ANALOG_VOLT_11);
38 setTPS1Inputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_3);
39
40// todo: tps
41#endif //HW_PROTEUS
42
43#if defined(HW_HELLEN_8CHAN)
44 engineConfiguration->injectionPins[4] = Gpio::MM176_INJ5;
45 engineConfiguration->injectionPins[5] = Gpio::MM176_INJ6;
46 engineConfiguration->injectionPins[6] = Gpio::MM176_INJ7;
47 engineConfiguration->injectionPins[7] = Gpio::MM176_INJ8;
48 engineConfiguration->ignitionPins[4] = Gpio::MM176_IGN5;
49 engineConfiguration->ignitionPins[5] = Gpio::MM176_IGN6;
50 engineConfiguration->ignitionPins[6] = Gpio::MM176_IGN7;
51 engineConfiguration->ignitionPins[7] = Gpio::MM176_IGN8;
52
53 engineConfiguration->vvtPins[0] = Gpio::MM176_OUT_PWM1; // 8D - VVT 1
54 engineConfiguration->map.sensor.hwChannel = MM176_IN_CRANK_ANALOG;
55 engineConfiguration->triggerInputPins[0] = Gpio::MM176_IN_D4; // 9A
59#endif
60
61#ifdef HW_HELLEN_UAEFI
62 engineConfiguration->injectionPins[6] = Gpio::MM100_OUT_PWM1;
63 engineConfiguration->injectionPins[7] = Gpio::MM100_INJ8;
64
65 engineConfiguration->ignitionMode = IM_WASTED_SPARK;
66 // cylinders 1 and 6
67 engineConfiguration->ignitionPins[0] = Gpio::MM100_IGN1;
68 // cylinders 2 and 3
69 engineConfiguration->ignitionPins[1] = Gpio::MM100_IGN2;
70 engineConfiguration->ignitionPins[2] = Gpio::Unassigned;
71 engineConfiguration->ignitionPins[3] = Gpio::Unassigned;
72 engineConfiguration->ignitionPins[4] = Gpio::Unassigned;
73 engineConfiguration->ignitionPins[5] = Gpio::Unassigned;
74 // cylinders 7 and 4
75 engineConfiguration->ignitionPins[6] = Gpio::MM100_IGN4;
76 // cylinders 8 and 5
77 engineConfiguration->ignitionPins[7] = Gpio::MM100_IGN3;
78
79
80 engineConfiguration->triggerInputPins[0] = Gpio::MM100_IN_D1; // HALL1
81 engineConfiguration->invertPrimaryTriggerSignal = true;
82
83 engineConfiguration->camInputs[0] = Gpio::MM100_IN_D2; // HALL2
85
86#endif
87
88 engineConfiguration->fuelReferencePressure = 400; // 400 kPa, 58 psi
89 engineConfiguration->injectorCompensationMode = ICM_FixedRailPressure;
90 engineConfiguration->injector.flow = 400;
91
92 engineConfiguration->tpsAccelLookback = 0.3;
93 engineConfiguration->tpsAccelEnrichmentThreshold = 5;
94 engineConfiguration->tpsDecelEnleanmentThreshold = 7;
95 engineConfiguration->tpsAccelFractionPeriod = 3;
96 engineConfiguration->tpsAccelFractionDivisor = 1.5;
97 engineConfiguration->wwaeTau = 0;
98 engineConfiguration->wwaeBeta = 0;
99
100 engineConfiguration->cylindersCount = 8;
102 engineConfiguration->firingOrder = FO_1_8_7_2_6_5_4_3;
103 engineConfiguration->displacement = 6.2;
104 engineConfiguration->map.sensor.type = MT_GM_1_BAR;
105
106 engineConfiguration->tChargeAirIncrLimit = 5;
107 engineConfiguration->tChargeAirDecrLimit = 15;
108
109// see https://github.com/rusefi/rusefi_documentation/tree/master/OEM-Docs/GM/Tahoe-2011
110 setLuaScript( R"(
111
112function getBitRange(data, bitIndex, bitWidth)
113 byteIndex = bitIndex >> 3
114 shift = bitIndex - byteIndex * 8
115 value = data[1 + byteIndex]
116 if (shift + bitWidth > 8) then
117 value = value + data[2 + byteIndex] * 256
118 end
119 mask = (1 << bitWidth) - 1
120 return (value >> shift) & mask
121end
122
123hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
124
125function toHexString(num)
126 if num == 0 then
127 return '0'
128 end
129
130 local result = ""
131 while num > 0 do
132 local n = num % 16
133 result = hexstr[n + 1] ..result
134 num = math.floor(num / 16)
135 end
136 return result
137end
138
139function arrayToString(arr)
140 local str = ""
141 local index = 1
142 while arr[index] ~= nil do
143 str = str.." "..toHexString(arr[index])
144 index = index + 1
145 end
146 return str
147end
148
149STARTER_OUTPUT_INDEX = 0
150startPwm(STARTER_OUTPUT_INDEX, 100, 0)
151
152-- 201
153ECMEngineStatus = 0xC9
154IGN_STATUS = 0x1f1
155-- 0x514
156VIN_Part1 = 1300
157-- 04E1
158VIN_Part2 = 1249
159
160setTickRate(100)
161
162function canIgnStatus(bus, id, dlc, data)
163 crankingBits = getBitRange(data, 2, 2)
164 isCranking = (crankingBits == 2)
165-- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
166 print('crankingBits ' .. crankingBits)
167end
168
169function printAny(bus, id, dlc, data)
170 print('packet ' .. id)
171end
172
173canRxAdd(IGN_STATUS, canIgnStatus)
174-- canRxAddMask(0, 0xFFFFFFF, printAny)
175
176-- todo: take VIN from configuration? encode VIN?
177canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
178canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
179dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
180
181-- todo: smarter loop code :)
182canVin1[1] = vin(1)
183canVin1[2] = vin(2)
184canVin1[3] = vin(3)
185canVin1[4] = vin(4)
186canVin1[5] = vin(5)
187canVin1[6] = vin(6)
188canVin1[7] = vin(7)
189canVin1[8] = vin(8)
190
191canVin2[1] = vin(9)
192canVin2[2] = vin(10)
193canVin2[3] = vin(11)
194canVin2[4] = vin(12)
195canVin2[5] = vin(13)
196canVin2[6] = vin(14)
197canVin2[7] = vin(15)
198canVin2[8] = vin(16)
199
200function onTick()
201 txCan(1, VIN_Part1, 0, canVin1)
202 txCan(1, VIN_Part2, 0, canVin2)
203
204 -- good enough for fuel module!
205 txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
206
207 if isCranking then
208 setPwmDuty(STARTER_OUTPUT_INDEX, 1)
209 else
210 setPwmDuty(STARTER_OUTPUT_INDEX, 0)
211 end
212end
213
214 )");
215
216 setPPSCalibration(0.51, 2.11, 1.01, 4.23);
217 setTPS1Calibration(880, 129, 118, 870);
218}
@ Unassigned
void setTPS1Calibration(uint16_t tpsMin, uint16_t tpsMax)
void setPPSInputs(adc_channel_e pps1, adc_channel_e pps2)
void setTPS1Inputs(adc_channel_e tps1, adc_channel_e tps2)
void setPPSCalibration(float primaryUp, float primaryDown, float secondaryUp, float secondaryDown)
void setLeftRightBanksNeedBetterName()
static constexpr engine_configuration_s * engineConfiguration
void setGmLs4()
Definition gm_ls_4.cpp:16
void setLuaScript(const char *luaScript)
Definition settings.cpp:761
This file is about configuring engine via the human-readable protocol.