Coding my own aftermarket ECU

Post Reply
User avatar
AngelMarc
Posts: 198
Joined: Sat Apr 08, 2023 9:23 pm
cars: A CB450 running to 8,000RPM with a P59.

Coding my own aftermarket ECU

Post by AngelMarc »

EDIT: Most recent progress
Have RPM based VE scaling and MAP sensor VE scaling working together passed 39,000RPM.
Most recent video before RPM based VE scaling was solved.
[youtube]https://www.youtube.com/watch?v=_ZkIpFpMpZ0[/youtube]

Original post-
Just going to dump progress and ideas of logic flow.
Updates will be sparse and slow. Largely from hunting for right syntax references.
I think spark timing/dwell will be handled by multiple arrays. One for start of dwell, one for end.
Same for fuel.
Will use 24x wheel. No cam, waste spark/batch fire.
Similar decode logic to what GM used.
AngelMarc wrote: Wed Apr 30, 2025 2:44 pm Ok, signed (+/-) start at zero, count down when low, up when high, move MSB of counter (for the +/-) each time signal goes low, into a shift register.
I knew it had to be a list of 1s and 0s, but I love this simple thing that can likely be done with common arduinos.
A little validation on a theory is nice every now and then. Great read.
With an array for the pattern to point at correct cylinder

Hopefully I don't run out of RAM.
If I can offset array values by a set amount for each cylinder, that'd be how timing is changed for V6, V8, V2 etc. As long as 15 degree increments work for the engine.
Sensor calibration will be done by the same array tables, deal with it.
Sensor count will be minimal.
No idle management routines.
Cylinder count limit currently unknown.
How to get it all going without overlap restrictions and racing-code conditions... I don't know yet.
Last edited by AngelMarc on Wed Jun 11, 2025 6:01 pm, edited 6 times in total.
Don't stress specific units.
User avatar
AngelMarc
Posts: 198
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 »

Nearly an hour just trying to get some formatting/syntax right so I can even see what space could be taken up by tune/cal.
It also didn't like me specifying "long" instead of "unsigned long"... "narrowing conversion from long long int, to long" ... um, no.
Attachments
Capture.PNG
Last edited by AngelMarc on Fri May 02, 2025 8:13 am, edited 1 time in total.
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 »

You're missing a set of { } to cover the whole lot, and your array is backwards.
You've specified an array of 12 arrays with length 20. But then shown 20 arrays with length 12.

As for working out how much space, you dont actually need to define all the data. " = { }" is enough to allocate memory.
But even easier, 12 x 20 items of type unsigned long (4 bytes each) = 12 x 20 x 4 = 960 bytes of memory.
User avatar
AngelMarc
Posts: 198
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 »

Thank you. Need a quick reference manual as helpful as you. I'm not an encyclopedia that can remember all this arbitrary syntax.
Attachments
Capture.PNG
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 »

Try chatGPT. It's excellent for stuff like that.
Just tell it you want short answers and you dont want it to try and take over.
If you let it start writing code for you, you'll generally get it working in the end, but you'll learn nothing in the process.
Just keep it for when you get stuck on stuff like that. The show it your code, show it the error you're getting, and it will point out the problem for you
User avatar
AngelMarc
Posts: 198
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 »

I forgot. My approach requires this insanity.
And compiler doesn't just tell me what that consumes.
Attachments
Capture.PNG
Capture.PNG (29.69 KiB) Viewed 1524 times
Don't stress specific units.
User avatar
AngelMarc
Posts: 198
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 »

EDIT: think I did my math wrong.
65,536 bytes, so before it was 131,072 bytes.
1 good thing about that circuit python nonsense, the units meant for it have excess resources.
Messed up the edit and deleted original. Don't know how I originally got 20kB.
Attachments
Capture.PNG
Capture.PNG (19.21 KiB) Viewed 1521 times
Last edited by AngelMarc on Wed May 28, 2025 2:03 am, edited 4 times in total.
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 »

The [20][256] table is over 20kb by itself

20 x 256 x 4
User avatar
AngelMarc
Posts: 198
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 »

Oh, yes, I forgot to x4 that.
Don't stress specific units.
User avatar
AngelMarc
Posts: 198
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 »

To keep code more generic, I think I'll just compare 2 counters. Each counter will increment with the high and low of crank signal, then those numbers get compared with an if < or if > for the 24X decode.
Don't stress specific units.
Post Reply