Coding my own aftermarket ECU [beta available]
- antus
- Site Admin
- Posts: 8999
- Joined: Sat Feb 28, 2009 8:34 pm
- cars: TX Gemini 2L Twincam
TX Gemini SR20 18psi
Datsun 1200 Ute
Subaru Blitzen '06 EZ30 4th gen, 3.0R Spec B - Contact:
Re: Coding my own aftermarket ECU
also consider how to time dwell so the charge time is right before you fire the spark.
Have you read the FAQ? For lots of information and links to significant threads see here: http://pcmhacking.net/forums/viewtopic.php?f=7&t=1396
Re: Coding my own aftermarket ECU
And I don't know about a 3D table, but I might be able... daisy chain arrays. A 1D array pointed at by divided RPMtime in the middle full of various divisor values to scale RPMtime differently for pointing at VE table.
Don't stress specific units.
Re: Coding my own aftermarket ECU
Literally what I've been doing as much as possible.
Don't stress specific units.
- antus
- Site Admin
- Posts: 8999
- Joined: Sat Feb 28, 2009 8:34 pm
- cars: TX Gemini 2L Twincam
TX Gemini SR20 18psi
Datsun 1200 Ute
Subaru Blitzen '06 EZ30 4th gen, 3.0R Spec B - Contact:
Re: Coding my own aftermarket ECU
3d means X and Y for location, Z for value, so you have 3D tables. 2D means 1 row or column only and a value.
Have you read the FAQ? For lots of information and links to significant threads see here: http://pcmhacking.net/forums/viewtopic.php?f=7&t=1396
Re: Coding my own aftermarket ECU
Thanks. Guess I was overthinking, wanted to use RPMtime directly instead of converting in arduino code. This should be fine.pman92 wrote: ↑Wed Jun 11, 2025 9:46 am That is a perfect question for AI:
RPMtime = (2,500,000 / ( index - 1 )) * 600
Index = 1 + (2,500,000 * (RPMtime * 600))
https://chatgpt.com/share/6848bfe0-99f0 ... 51d98a254c
Even inverts the index so lower number is slower.
Don't stress specific units.
Re: Coding my own aftermarket ECU
Yes I can see but just thought I should mention it.
Sometimes I find myself going down a rabbit hole getting no where with something. Then some time later I actually think a bit more about what I was trying to do, and realise I was asking it the wrong questions. Not saying that's what your doing right now though
I've got wrapper functions that use those lookup functions as well. Eg
Code: Select all
uint16_t EGT2_millivolts(uint16_t egt2_temperature){
return (lookup_2d_linear(egt2_temperature,
calibration.table.outputConversion.EGT2,
TABLE_EGT2_OUTPUT_CONVERSION_SIZE,
TABLE_EGT2_OUTPUT_CONVERSION_MIN,
TABLE_EGT2_OUTPUT_CONVERSION_MAX)
);
Re: Coding my own aftermarket ECU
Sounds like redefining ordinary words to be less intuitive. I don't like it.
Don't stress specific units.
Re: Coding my own aftermarket ECU
A 3D table visualises as a wavy 3D map with high and low areas.
A 2D table visualises as a line on a graph
Re: Coding my own aftermarket ECU
I'm going to keep thinking in math terms where the result isn't a spatial dimension.
Don't stress specific units.
Re: Coding my own aftermarket ECU
That was a simple change. Do still need to test though.
But since part of the testing is changing values and comparing before and after, going to move on.
But since part of the testing is changing values and comparing before and after, going to move on.
Code: Select all
void loop() {
if (newSample) {
newSample = false;
// --- ADC rolling average (12-bit to 7-bit scale) ---
total -= readings[bufIndex];
int newVal = analogRead(A0);
readings[bufIndex] = newVal;
total += newVal;
bufIndex = (bufIndex + 1) % 24;
int avg12bit = total / 24;
adcIndex = (avg12bit >> 5) - 1; // () for simple order of opperation, minus 1 for avoiding index wrapping
// --- Calculate RPM timing (µs per event) ---
unsigned long RPMTime = pulseHighTime + pulseLowTime;
RPMTime = constrain(RPMTime, 125, 125000); // 20k RPM to 20 RPM
RPMIndex = (uint8_t)(2500000/(RPMTime*600));
// --- Update delay values from tables ---
currentOnDelay11 = Dstart[RPMIndex][adcIndex];
currentOffDelay11 = Dend[RPMIndex][adcIndex];
currentOnDelay4 = Istart[RPMIndex][adcIndex];
currentOffDelay4 = Iend[RPMIndex][adcIndex];
}
Don't stress specific units.