An attempt to build an Engine Control Unit based on stm32.
It's really not that hard.

In the previous article 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.

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.

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:

We will need a bit of code to generate fake CKP signal
int main(void) {

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

    // serial-over-usb initialization

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

    while (TRUE)

    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:

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)

With just three components you cannot possibly say that this wasn't easy, right?

Want to join the fun?

Project source:


Copyright (c) 2012-2013 Andrey