Coding my own aftermarket ECU

User avatar
antus
Site Admin
Posts: 8996
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

Post by antus »

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
User avatar
AngelMarc
Posts: 223
Joined: Sat Apr 08, 2023 9:23 pm
cars: A CB450 running to 8,000RPM with a P59.

Re: Coding my own aftermarket ECU

Post 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.
Don't stress specific units.
User avatar
AngelMarc
Posts: 223
Joined: Sat Apr 08, 2023 9:23 pm
cars: A CB450 running to 8,000RPM with a P59.

Re: Coding my own aftermarket ECU

Post 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.
Don't stress specific units.
User avatar
antus
Site Admin
Posts: 8996
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

Post 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.
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
User avatar
AngelMarc
Posts: 223
Joined: Sat Apr 08, 2023 9:23 pm
cars: A CB450 running to 8,000RPM with a P59.

Re: Coding my own aftermarket ECU

Post by AngelMarc »

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
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.
Don't stress specific units.
User avatar
pman92
Posts: 577
Joined: Thu May 03, 2012 10:50 pm
Location: Castlemaine, Vic
Contact:

Re: Coding my own aftermarket ECU

Post 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)
            ); 
User avatar
AngelMarc
Posts: 223
Joined: Sat Apr 08, 2023 9:23 pm
cars: A CB450 running to 8,000RPM with a P59.

Re: Coding my own aftermarket ECU

Post 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.
Don't stress specific units.
User avatar
pman92
Posts: 577
Joined: Thu May 03, 2012 10:50 pm
Location: Castlemaine, Vic
Contact:

Re: Coding my own aftermarket ECU

Post 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
User avatar
AngelMarc
Posts: 223
Joined: Sat Apr 08, 2023 9:23 pm
cars: A CB450 running to 8,000RPM with a P59.

Re: Coding my own aftermarket ECU

Post 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.
Don't stress specific units.
User avatar
AngelMarc
Posts: 223
Joined: Sat Apr 08, 2023 9:23 pm
cars: A CB450 running to 8,000RPM with a P59.

Re: Coding my own aftermarket ECU

Post 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];
  }

Don't stress specific units.
Post Reply