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

Committer:
foxdie
Date:
Wed Apr 24 19:58:41 2019 +0000
Revision:
2:1d1c166c841c
Parent:
0:4f9ca3373904
Updated documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
foxdie 0:4f9ca3373904 1 #include "mbed.h"
foxdie 0:4f9ca3373904 2 #include "math.h"
foxdie 0:4f9ca3373904 3 #include "EFI-Engine-Simulator.h"
foxdie 0:4f9ca3373904 4
foxdie 0:4f9ca3373904 5 unsigned short crank_angle = 0;
foxdie 0:4f9ca3373904 6 float targetRPM = EFI_CRANKING_RPM;
foxdie 0:4f9ca3373904 7 float offsetRPM = 0.0f;
foxdie 0:4f9ca3373904 8 Ticker RPMtick;
foxdie 0:4f9ca3373904 9
foxdie 0:4f9ca3373904 10 void updateSignals() {
foxdie 0:4f9ca3373904 11 LPC_GPIO2->FIOPIN = EFI_CRANK_CAM_LOOKUP[crank_angle] << 4;
foxdie 0:4f9ca3373904 12 crank_angle++;
foxdie 0:4f9ca3373904 13 if (crank_angle >= EFI_TOTAL_ROTATION) { crank_angle = 0; }
foxdie 0:4f9ca3373904 14 }
foxdie 0:4f9ca3373904 15
foxdie 0:4f9ca3373904 16 int main() {
foxdie 0:4f9ca3373904 17 // Set up pins p21 (P2_5) and p22 (P2_4) at a low level
foxdie 0:4f9ca3373904 18 LPC_PINCON->PINSEL4 &= 0xFFFFF0FF; // Set pins to GPIO (function = 0b00)
foxdie 0:4f9ca3373904 19 LPC_PINCON->PINMODE_OD2 |= 3 << 4; // Set pins to open drain mode
foxdie 0:4f9ca3373904 20 LPC_GPIO2->FIODIR |= 3 << 4; // Set pins as outputs (dir = 1)
foxdie 0:4f9ca3373904 21 LPC_GPIO2->FIOMASK = ~(3 << 4); // Only change these pins (mask bits = 0)
foxdie 0:4f9ca3373904 22
foxdie 2:1d1c166c841c 23 // Main loop - simple cycling of RPMs to test crank / cam signals
foxdie 0:4f9ca3373904 24 while(1) {
foxdie 0:4f9ca3373904 25 targetRPM = (EFI_REDLINE_RPM / 2.0f) + (sin(offsetRPM) * ((EFI_REDLINE_RPM / 2.0f)));
foxdie 0:4f9ca3373904 26 RPMtick.attach(&updateSignals, 1.0f / (targetRPM * 6));
foxdie 0:4f9ca3373904 27 offsetRPM += 0.05f;
foxdie 0:4f9ca3373904 28 wait_ms(100);
foxdie 0:4f9ca3373904 29 }
foxdie 0:4f9ca3373904 30 }