A small lightweight program to simulate cam and crank engine signals for ECU / PCM testing

Dependencies:   mbed

The purpose of this program is to simulate the CPS (Crank Position Sensor) and the CAS (Crank Angle Sensor) of a "traditional" 4-stroke engine for testing Electronic Fuel Injection engine computers (aka the EFI ECU or PCM).

Initially this project will be used to simulate one of the following engines, but it's hoped that this will expand over time - if you want to help, email me.

  • Mitsubishi 6G72 DOHC - Used in the GTO / 3000GT and Dodge Stealth equivalent
  • Mitsubishi 6A13 DOHC - Used in the 8th Gen Galant VR-4 / Legnum

Both of these cars use a hall-effect 3-vane CPS and 4-vane CAS, details can be found here; http://www.stealth316.com/2-ignitionsystem.htm

The above car manufacturers, models and content are copyrights / trademarks of their respective owners.

This program is provided as-is, without any warranty or support. You use it at your own risk. I take no responsibility for any damages that may occur.

This program is provided free for educational and personal use but please credit the same people I have credited.

It may also be used directly or indirectly for commercial purposes ONLY IF a a 5% donation of any profits is made to a charity that can be categorised below;

  • One that helps animals, particularly endangered species
  • One that helps humanity with terminal illness ie. ALS / MND, cancers etc
  • One that helps young people learn computing, cars and / or engineering

Let's give a little back to the community, even if it's just a few bucks :)

Credits:

  • http://www.stealth316.com/ - Ignition timing information for the 6G72 / 6A13
  • Kewks - For recommending setting pin states directly for extra performance
  • The open-source programming community at large for all the inspiration

Jason Gaunt, 22nd April 2019

main.cpp

Committer:
foxdie
Date:
2019-04-24
Revision:
2:1d1c166c841c
Parent:
0:4f9ca3373904

File content as of revision 2:1d1c166c841c:

#include "mbed.h"
#include "math.h"
#include "EFI-Engine-Simulator.h"

unsigned short crank_angle = 0;
float targetRPM = EFI_CRANKING_RPM;
float offsetRPM = 0.0f;
Ticker RPMtick;

void updateSignals() {
    LPC_GPIO2->FIOPIN = EFI_CRANK_CAM_LOOKUP[crank_angle] << 4;
    crank_angle++;
    if (crank_angle >= EFI_TOTAL_ROTATION) { crank_angle = 0; }
}

int main() {
    // Set up pins p21 (P2_5) and p22 (P2_4) at a low level
    LPC_PINCON->PINSEL4 &= 0xFFFFF0FF; // Set pins to GPIO (function = 0b00)
    LPC_PINCON->PINMODE_OD2 |= 3 << 4; // Set pins to open drain mode
    LPC_GPIO2->FIODIR |= 3 << 4;       // Set pins as outputs (dir = 1)
    LPC_GPIO2->FIOMASK = ~(3 << 4);    // Only change these pins (mask bits = 0)

    // Main loop - simple cycling of RPMs to test crank / cam signals
    while(1) {
        targetRPM = (EFI_REDLINE_RPM / 2.0f) + (sin(offsetRPM) * ((EFI_REDLINE_RPM / 2.0f)));
        RPMtick.attach(&updateSignals, 1.0f / (targetRPM * 6));
        offsetRPM += 0.05f;
        wait_ms(100);
    }
}