Topic: Anyone to waste time on DIY engine control unit?

Looking for someone to join me in wasting time by making an engine control unit from scratch. I have wasted enough time to have a working prototype, so please excuse my sales pitch in a non-Lemons language, I am pasting from another site:

In this article I will explain how I hacked into my car harness in order to read current RPM. This approach is not universal and there are no guarantees - this article only applies to my car and you should not attempt doing anything like that to yours.

A bit of technical background first: the car I have hacked was sold in US as Ford Aspire, it was made in South Korea and it's Mazda design with some Mitsubishi components. Not your average F150 exactly smile This car uses Hall effect crankshaft position sensors (no idea how that works). So I could have used the same approach for something like Mazda Protege or even a Miata from the 90's - the younger cars would have sensors based on Variable reluctance and that would be a different story.

When I open the hood, I see a distributor like the one on the picture:
http://rusefi.com/articles/tachometer/1995_aspire_distributor_1.jpg

If I would have decided to break this distributor and look inside, I would see something like
http://rusefi.com/articles/tachometer/1995_aspire_distributor_2.jpg

That tin wheel spins with the crankshaft and that's what make the CKP signal. If I would keep taking it apart, I would see the actual sensors and the other wheel - the smaller wheel is in charge of CID signal.
http://rusefi.com/articles/tachometer/1995_aspire_distributor_3.jpg

Does not really matter what CKP and CID signals are. We only care that even while the car has a 12 volts battery, most of the sensors and the stock ECU run on 5 volts. Somewhere in my harness where are two 5 volts wave signals which look like this:
http://rusefi.com/articles/tachometer/signal.jpg

That's it. We can wire this signal right into the any 5v tolerant microcontroller. Just to be a bit safer, we will put a 1n4001 diode between the harness and the microcontroller.

So, let's get something done. Let's take a STM32F4DISCOVERY dev board - that's a $15 board based on some stm32f4 microcontroller running at 168MHz.
http://rusefi.com/articles/tachometer/STM32F4DISCOVERY.jpg

That's actually a lot of cheap computation power.

As is, microcontrollers are not exactly super friendly - ChibiOS/RT would help us, we will let it take care of the the lower level. We will use serial-over-usb to output data - so, mini-usb cable would be used to flash & power the board and the micro-usb cable would be used for serial. If you made it to here you probably know what serial is.

It's not much code, it's quite self-explanatory:

volatile int rpm = 0;
int lastInputEventTime = -10 * CH_FREQUENCY;

void icuWidthCallback(ICUDriver *driver) {
    int now = chTimeNow();
    int diff = now - lastInputEventTime;
    rpm = 60000 * TICKS_IN_MS * 2 / 4 / diff;
    lastInputEventTime = now;
}

ICUConfig wave_icucfg = { ICU_INPUT_ACTIVE_LOW, 100000, icuWidthCallback, NULL };

int main(void) {
    halInit();
    chSysInit();

    // this thread would blink one of the LEDs, that would look cool
    chThdCreateStatic(blinkingThreadStack, sizeof(blinkingThreadStack), NORMALPRIO, blinkingThread, NULL);

    // serial-over-usb initialization
    usb_serial_start();

    // configure input signal pin
    palSetPadMode(CRANK_INPUT_PORT, CRANK_INPUT_PIN, PAL_MODE_ALTERNATE(GPIO_AF_TIM2));

    // start input capture - we will handle input events and calculate RPM based on the timestamps
    icuStart(&CRANK_DRIVER, &wave_icucfg);
    icuEnable(&CRANK_DRIVER);

    while (TRUE) {
        // RPM value is updated by the input event handler
        chprintf(&SDU1, "rpm: %d\r\n", rpm);
        chThdSleep(100);
    }

    return 0;
}

It really isn't that hard, right?

I've got the software side of things covered and forced myself to figure out enough electronics, And the whole effort is absolutely pointless anyway, so why not join me?

PS: I think this is more 'Tech' then 'Human Resources'?

Re: Anyone to waste time on DIY engine control unit?

In the previous post we've seen how easy it is to get RPM value from my car (that's mostly because my 1996 car is old enough). Now let's see if we can control anything. In order to learn more about engine control let's take the ECU out of the car and play with it on the bench. I did not want to leave my car without the ECU so I've got the exact same one on eBay for $30. Self-serve junk yards are another great source of cheap stock control units.

http://rusefi.com/articles/stimulator/aspire_ecu.jpg

Let's make the ECU think that it is actually still in the car, that the engine is running and it's actually its job to supply fuel and spark. If we can do that we can potentially learn a lot about the stock ECU logic.

Anyone has an old broken desktop, and most of these old desktops have a functioning power supply. Lucky for us, these power supplies are 12 volts, exactly what we need to for this ECU on our bench.

http://rusefi.com/articles/stimulator/ATX-Power-Supply.jpg

So, we will fake the CKP signal with the microcontroller and feed it to the ECI. In the world of analog electronics they do funny things: instead of plain & easy zero volts for logical OFF and some voltage for logical ON, they sometimes do disconnected for logical OFF and ground for logical ON. Our nice & digital microcontroller does plain & easy low/high, so we need to translate these signals. Turned out a transistor is exactly the device which does such conversion, but it has to the NPN type. I've used 2N5551 because they are $0.99 for 15 shipped from Singapore.
Here is the schematic:

http://rusefi.com/articles/stimulator/sensor_simulator.gif

We will need a bit of code to generate fake CKP signal

int main(void) {
    halInit();
    chSysInit();

    // this thread would blink one of the LEDs, that would look cool
    chThdCreateStatic(blinkingThreadStack, sizeof(blinkingThreadStack), NORMALPRIO, blinkingThread, NULL);

    // serial-over-usb initialization
    usb_serial_start();

    pwmStart(PWM_SLOW, &pwmcfg_slow);
    palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(2));
    pwmEnableChannel(PWM_SLOW, 1, 600);

    while (TRUE)
        chThdSleep(100);

    return 0;
}

Same funny thing with ECU outputs: each injector output wire is disconnected while injector is off and ground in order to turn the injector on. In order to convert such signal into something the microcontroller would understand, we would need a diode and a resistor:

http://rusefi.com/articles/stimulator/ecu_output.gif

It is hard to believe but the ECU has actually responded! Here you are, injector output signal (it is inverted because of the schematic we use to convert it into logic levels)

http://rusefi.com/articles/stimulator/signals.jpg

Re: Anyone to waste time on DIY engine control unit?

Why are you wasting your time driving the car? You should be in the pits F1 style sitting in front of a row of monitors looking at telemetry and making adjustments.

Bacon, oh bacon
Bacon, bacon, oh bacon
Love in five letters

Re: Anyone to waste time on DIY engine control unit?

Isn't this headed to MegaSquirt/MegaJolt?  Just curious...

Jamie Palmer  tr6driver@yahoo.com
Austin Powerless Racing  '75 Austin Marina, 44th/IOE Summit Point '13, 35th/1st Class C CMP Fall '13, 23rd/3rd Class C CMP Spring '14, 83rd/14th Class C CMP Fall '14 (blown engine/swapped mid-race to finish), 3rd Class C CMP Spring '15, 2nd Class C CMP Fall '15
http://www.facebook.com/pages/Austin-Po … 3187341573

Re: Anyone to waste time on DIY engine control unit?

tr6driver wrote:

Isn't this headed to MegaSquirt/MegaJolt?  Just curious...

MegaSquirt is proprietary hardware and it carries the baggage of age - they have started a while ago when CPUs were way slower meaning software implementation had to be way more hardcore. My idea is that since processors are now faster (and cheaper), one can solve the same problem of fuel control in a simpler, more flexible and extendable manner.

Re: Anyone to waste time on DIY engine control unit?

10-4!  Well, then more power (processing power!) to you!  I, unfortunately, have no expertise to add, and my car ran on points/condensor at Summit (!), but I'll watch with interest :-)

Jamie Palmer  tr6driver@yahoo.com
Austin Powerless Racing  '75 Austin Marina, 44th/IOE Summit Point '13, 35th/1st Class C CMP Fall '13, 23rd/3rd Class C CMP Spring '14, 83rd/14th Class C CMP Fall '14 (blown engine/swapped mid-race to finish), 3rd Class C CMP Spring '15, 2nd Class C CMP Fall '15
http://www.facebook.com/pages/Austin-Po … 3187341573

Re: Anyone to waste time on DIY engine control unit?

I'm just starting to create a new dash that is controlled by an arduino nano.  Abstractly it's pretty simple, but the devil is in the details for an ME trying to understand electrical noise in a automotive circuit.  I'm not much of a partner in your endevour, but I'm interested in seeing your progress.

Our Lady of Perpetual Downforce
http://www.perpetualdownforce.com/

Re: Anyone to waste time on DIY engine control unit?

st_rage wrote:

I'm just starting to create a new dash that is controlled by an arduino nano.  Abstractly it's pretty simple, but the devil is in the details for an ME trying to understand electrical noise in a automotive circuit.  I'm not much of a partner in your endevour, but I'm interested in seeing your progress.

I've gained some painful experience in reading analog signals, I can write a short article on this if you would be interested.

What features do you plan for your dashboard? What do you use for display?

Re: Anyone to waste time on DIY engine control unit?

I've been daydreaming of an old giant desktop PC (XT AT 286 386) that would run my fuel injection system. To start the car, first you have to insert your huge 5-1/4" floppy, remembering to turn the load arm down, next pull up the program in DOS and type "RUN". Hopefully you won't get the "Blue screen of death" in the middle of a race forcing you to pull over on the side of the track and reboot

'ported, relieved, with bored-out arm rests, and oversize seat covers.

Re: Anyone to waste time on DIY engine control unit?

stupid_but_tough wrote:

I've been daydreaming of an old giant desktop PC (XT AT 286 386)...

386 was 12 MHz to 40 MHz, 486 was 16  MHz to 100 MHz. The $15 dev board is 168MHz smile

Re: Anyone to waste time on DIY engine control unit?

I've been wanting to do this and add FI to my lawnmower.

No, seriously.

12 (edited by derekste 2013-08-29 11:41 AM)

Re: Anyone to waste time on DIY engine control unit?

russian wrote:
tr6driver wrote:

Isn't this headed to MegaSquirt/MegaJolt?  Just curious...

MegaSquirt is proprietary hardware and it carries the baggage of age - they have started a while ago when CPUs were way slower meaning software implementation had to be way more hardcore. My idea is that since processors are now faster (and cheaper), one can solve the same problem of fuel control in a simpler, more flexible and extendable manner.

(I recall your previous thread from about a year ago concerning developing your own ECU)

Processor speed has little, if anything, to do with an ECU's ability to adequately control the car- in fact I challenge you to find me a car ECU that runs faster than 200MHz

Megasquirt I is 8MHz, Megasquirt II is 24MHz, and the newest MS3 is 50MHz(+ an 100MHz XGATE RISC coprocessor). Hell, you can get a realtime clock for MS3, if you so desire!

Is there some specific feature Megasquirt lacks that you need to replicate? http://ms3efi.com/product.html . 0.1% and 0.1* resolutions on 16x16 tables with full interpolation is pretty damn good.

Megasquirt is only proprietary in that you have to buy "their" board. But even this is not 100% true- there have been "counterfeit" boards made that I am aware of. Want to copy or modify megasquirt? Look no further than http://www.megamanual.com/ms2/megasquirt_ShemV3.00.pdf Want to modify the software? Go for it.

Again, I hate to be a naysayer, but I also hate to see people reinvent wheels. Megasquirt has THOUSANDS of hours behind it, over the better part of a decade. That is why Megasquirt can run on just about freakin everything-- including a certain WWII radial-plane-engine-powered MR2 we all know and love.

I guess knowing your end goal would really help justifying such an endeavor. That being said, I'm local to you, have a Comp Sci degree, and tons of experience with high speed data acquisition, A/D conversion, and realtime/embedded systems- would be happy to help on whatever, bounce ideas off of, etc.

"THE WONDERMENT CONSORTIUM"
Everything dies baby that's a fact,
But maybe everything that dies someday comes back?

Re: Anyone to waste time on DIY engine control unit?

derekste wrote:

...Again, I hate to be a naysayer, but I also hate to see people reinvent wheels....I guess knowing your end goal would really help justifying such an endeavor....

Really?  In the 24 Hours of Lemons forums, you have to ask why someone has started an unnecessary, potentially dangerous project with no clear benefit?

Because racecar, that's why.

russian, if I had the slightest clue (ok, actually I have a slight clue) and the time, I'd be all over this.

stupid_but_tough wrote:

I've been daydreaming of an old giant desktop PC (XT AT 286 386) that would run my fuel injection system. To start the car, first you have to insert your huge 5-1/4" floppy, remembering to turn the load arm down, next pull up the program in DOS and type "RUN". Hopefully you won't get the "Blue screen of death" in the middle of a race forcing you to pull over on the side of the track and reboot

Well, in almitydave's Ye Olde Computer Graveyard, there lies a Celeron 488MHz with functioning (last time I checked, which was probably 1999) 5.25" drive.  I also have a Pentium3 500Mhz taking up space, but that's way overkill for your application.  Plus I daydream about having enough free time to put DOS on it to play the original Need for Speed again.

And I have to be nerd-pedantic and point out that there was no BSOD in DOS.  I can't remember a typical in-application crash message, however; it's been too long.

15x+ Loser, thinks he's a Real Racer(tm)
Rotaries are great, everyone should try them.

Re: Anyone to waste time on DIY engine control unit?

TrackGeeks_Chris wrote:

I've been wanting to do this and add FI to my lawnmower.

No, seriously.

Seriously? Please PM me if you are seriously serious.

Re: Anyone to waste time on DIY engine control unit?

derekste wrote:

Processor speed has little, if anything, to do with an ECU's ability to adequately control the car- in fact I challenge you to find me a car ECU that runs faster than 200MHz
...
I guess knowing your end goal would really help justifying such an endeavor. That being said, I'm local to you, have a Comp Sci degree, and tons of experience with high speed data acquisition, A/D conversion, and realtime/embedded systems- would be happy to help on whatever, bounce ideas off of, etc.

You are absolutely right, processor speed has very little with the ABILITY to control a car. On the other hand, the x10-x100 excessive power means I can write code on a much higher level. I believe MS1 implementation is assembler and while later MSs are written C, they are written in a very platform-dependent manner, with hardware specifics all over the place. If I have hardware taken care by ChibiOS (and it does this job), I can code on a much higher level of abstraction - making a much more readable and portable code.

As for goals... If I transplant the brain inside existing stock ECU, I've for my firmware running on $15 of Lemons budget, is not that cool?

As for features missing in MS... GPS activated throttle blip? smile

Re: Anyone to waste time on DIY engine control unit?

russian wrote:

As for features missing in MS... GPS activated throttle blip? smile

Taunting the losers: http://www.youtube.com/watch?v=8aArSn4IhHI&t=23s

15x+ Loser, thinks he's a Real Racer(tm)
Rotaries are great, everyone should try them.

Re: Anyone to waste time on DIY engine control unit?

russian wrote:

It really isn't that hard, right?

Actually, it is.  I spent a couple months studying the transistor... and completely forgot everything afterwards, except for a couple takeaways:
- The transistor works on current, not voltage
- The transistor works as a linear current amplifier within a small range of current... then it goes nonlinear

Furthermore, one must consider the impedances of his source and sink: namely your microcontroller and ECU.  Once you know your impedances, you'll know how much current you'll be pulling from your source / will need to send to your sink.

TL;DR: your design is missing a couple resistors.  You might fry your transistor, or your microcontroller, or you may end up with some unexpected glitches at your ECU... but that's what makes it Lemony!

Here's a good place to start, although it doesn't talk about power dissipation: http://www.rason.org/Projects/transwit/transwit.htm

Re: Anyone to waste time on DIY engine control unit?

papal_smear wrote:

You might fry your transistor, or your microcontroller, or you may end up with some unexpected glitches at your ECU... but that's what makes it Lemony!

I will make an honest attempt to educate myself further, but that's probably why I am looking for someone to join me smile

In my defense I have to say that my design _works_ - it's probably some luck combined with all the tolerances across all the doomed components involved.

Re: Anyone to waste time on DIY engine control unit?

russian wrote:
st_rage wrote:

I'm just starting to create a new dash that is controlled by an arduino nano.  Abstractly it's pretty simple, but the devil is in the details for an ME trying to understand electrical noise in a automotive circuit.  I'm not much of a partner in your endevour, but I'm interested in seeing your progress.

I've gained some painful experience in reading analog signals, I can write a short article on this if you would be interested.

What features do you plan for your dashboard? What do you use for display?

The gauges I want are:
Oil Pressure
Oil Temp
Water Temp
Fuel
Time
Voltage
Shift Lights

Currently I'm planning on displaying them on discrete serial 7-segment displays.  The reason I like the idea of a microcontroller running them instead of autometer gauges is that I can make the display flash when they exceed my preset values.  Essentially everything gets a programmable  idiot light.

Our Lady of Perpetual Downforce
http://www.perpetualdownforce.com/

20 (edited by ppressle 2013-09-01 10:15 AM)

Re: Anyone to waste time on DIY engine control unit?

I have an Arduino controlling a bunch of stuff.  It is an incredible waste of time, but it is fun.  Very Lemony.

My first display is LCD.  But that is too hard to read in bright daylight, so I'm looking to change it out.

http://m9.i.pbase.com/g4/51/415951/3/141777769.sGmoT0Fw.jpg

My second display is plasma, and is very readable, but too big and heavy.  I'm still working on that.

Re: Anyone to waste time on DIY engine control unit?

And to get the thread back on track, I think it is BRILLIANT to make your own ECU!  When I need more horsepower and turbo the car, I'll come calling for more info. smile

Re: Anyone to waste time on DIY engine control unit?

ppressle wrote:

And to get the thread back on track, I think it is BRILLIANT to make your own ECU!  When I need more horsepower and turbo the car, I'll come calling for more info. smile

We both know you need more horsepower smile Let's start with RPM, I would love to have BMW crank position decoder.

Re: Anyone to waste time on DIY engine control unit?

Always need more HP, but I don't have any budget at the moment. 

Isn't the crank position sensor just a hall effect device?  Do some hardware cleanup of that signal with an op amp perhaps and generate an interrupt on that, then you know the rpm and the position of the crank.

I have not done any of the math to know if you can manage everything that you would need in software though.  I suspect that you would use the computer to get an rpm and set up pointers into the current  timing data for the current fuel and timing data.  I thought you would need to handle the actual timing and fueling with a dedicated circuit though.

If the computer is fast enough to do that all, that simplifies things greatly.  (and makes the engine totally dependent on getting that right)

Re: Anyone to waste time on DIY engine control unit?

ppressle wrote:

Isn't the crank position sensor just a hall effect device?  Do some hardware cleanup of that signal with an op amp perhaps and generate an interrupt on that, then you know the rpm and the position of the crank.

How do I put this mildly... Did you actually read the first post in this thread? smile

ppressle wrote:

I have not done any of the math to know if you can manage everything that you would need in software though.  I suspect that you would use the computer to get an rpm and set up pointers into the current  timing data for the current fuel and timing data.  I thought you would need to handle the actual timing and fueling with a dedicated circuit though.
If the computer is fast enough to do that all, that simplifies things greatly.  (and makes the engine totally dependent on getting that right)

You mean x86 computer? No way - because no real time OS, your win/unix will go do some swapping and you have missed your spark time.

8000rpm is 133Hz, some shafts go twice the crank speed so 266Hz, in order to have 1 degree precision on the shaft you need 100 KHz performance.

Re: Anyone to waste time on DIY engine control unit?

Hey, you said BMW crank sensor.  smile  They don't have the optical thing like you have.