Page 8 of 18
Re: Coding my own aftermarket ECU
Posted: Wed Jun 11, 2025 9:46 am
by antus
also consider how to time dwell so the charge time is right before you fire the spark.
Re: Coding my own aftermarket ECU
Posted: Wed Jun 11, 2025 10:02 am
by AngelMarc
antus wrote: ↑Wed Jun 11, 2025 9:11 am
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.
Re: Coding my own aftermarket ECU
Posted: Wed Jun 11, 2025 10:04 am
by AngelMarc
pman92 wrote: ↑Wed Jun 11, 2025 9:46 am
understand whats happening, rather than writing it all for you
Literally what I've been doing as much as possible.
Re: Coding my own aftermarket ECU
Posted: Wed Jun 11, 2025 10:05 am
by antus
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.
Re: Coding my own aftermarket ECU
Posted: Wed Jun 11, 2025 10:13 am
by AngelMarc
Thanks. Guess I was overthinking, wanted to use RPMtime directly instead of converting in arduino code. This should be fine.
Even inverts the index so lower number is slower.
Re: Coding my own aftermarket ECU
Posted: Wed Jun 11, 2025 10:15 am
by pman92
AngelMarc wrote: ↑Wed Jun 11, 2025 10:04 am
Literally what I've been doing as much as possible.
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
Posted: Wed Jun 11, 2025 10:16 am
by AngelMarc
antus wrote: ↑Wed Jun 11, 2025 10:05 am
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.
Sounds like redefining ordinary words to be less intuitive. I don't like it.
Re: Coding my own aftermarket ECU
Posted: Wed Jun 11, 2025 10:18 am
by pman92
AngelMarc wrote: ↑Wed Jun 11, 2025 10:16 am
Sounds like redefining ordinary words to be less intuitive. I don't like it.
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
Posted: Wed Jun 11, 2025 10:30 am
by AngelMarc
pman92 wrote: ↑Wed Jun 11, 2025 10:18 am
AngelMarc wrote: ↑Wed Jun 11, 2025 10:16 am
Sounds like redefining ordinary words to be less intuitive. I don't like it.
A 3D table visualises as a wavy 3D map with high and low areas.
A 2D table visualises as a line on a graph
I'm going to keep thinking in math terms where the result isn't a spatial dimension.
Re: Coding my own aftermarket ECU
Posted: Wed Jun 11, 2025 10:59 am
by AngelMarc
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.
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];
}