Download as pdf or txt
Download as pdf or txt
You are on page 1of 94

Engine Control Unit for a 4 cylinder

motorcycle engine
Ríkarður Jón Ragnarsson

Final Report in Electrical Engineering B.Sc.


2017

Name: Ríkarður Jón Ragnarsson


Kennitala: 091292–3789
Supervisor: Indriði Sævar Ríkharðsson

School of Science and Engineering


Tækni- og verkfræðideild
Tækni- og verkfræðideild
Heiti verkefnis:
Vélarstýring fyrir 4 sílindra vél úr mótorhjóli

Námsbraut: Tegund verkefnis:


Rafmagnstæknifræði B.Sc. Lokaverkefni í tæknifræði B.Sc.

Önn: Námskeið: Ágrip:


Haust 2017 RT LOK Vélartölva er búnaður sem allar nútíma
1012 bifreiðar innihalda. Ef um er að ræða
sérsmíði bíls, getur val á vélatölvu verið
flókið ferli. Sérstaklega ef bíllinn er smíðaður
Höfundur: í þeim tilgangi að keppa eigi á honum í
Ríkarður Jón Ragnarsson alþjóðlegri keppni þar sem taka þarf mark á
ýmsum reglum sem takmarka valmöguleika. Í
slíkum keppnisbílum eru yfirleitt notaðar
tölvur sem eru hannaðar sem alhliða tölvur í
sem flestar gerðir keppnistækja. Þær gerðir
Umsjónarkennari: tölva eru yfirleitt ansi dýrar.
Baldur Þorgilsson
Verkefni snýst um að hanna og smíða
vélartölvu fyrir 4 sílindra vél úr mótorhjóli
Leiðbeinandi: sem notuð verður í keppnisbíl Formula
Indriði Sævar Ríkharðsson Student lið Háskóla Reykjavíkur. Markmiðið
verkefnisins er að smíða einfalda vélatölvu til
að minnka bæði kostnað og flækjustig. Ferlið
Fyrirtæki/stofnun: felst í því að forrita, hanna rafrásir og búa til
prentplötu. Hönnun rása og forrits er síðan
prófuð.

Dagsetning: Lykilorð íslensk: Lykilorð ensk:


4. desember Vélarstýring Engine Control Unit
2017 Hagnýt Kerfi Embedded Systems
Hönnun Rafrása Circuit Design

Dreifing:
opin lokuð

Háskólinn í Reykjavík  Menntavegi 1, 101 Reykjavík  sími: 599 6200


www.ru.is
ii
Abstract

An Engine control unit (ECU) is a component found in all modern vehicles. In the case of a
competition vehicle, the variety of ECUs decrease massively. especially if the vehicle is con-
structed for the purpose of competing in an international competition, because of various rules
and regulations regarding the vehicle that limit the choice of an ECU. In such competition ve-
hicles, the ECUs are generally built for universal purposes but maintaining the performance
quality of a competition ECUs. These types of ECUs are usually expensive.

The project of this thesis is designing and building an ECU for a 4 cylinder motorcycle en-
gine. The ECU will be used by the Formula Student team of Reykjavík University and the goal
is to create a simple ECU to decrease both the cost and the complexity. The process includes
programming, circuit designing, and PCB making. The hardware and firmware designs are then
tested.
iv
Acknowledgements

This thesis is the author’s final project in B.Sc. degree in Applied Electrical Engineering at the
Reykjavik University. The project idea was instigated by the author and Jón Bjarni Bjarnason,
a fellow student. Both, involved in the Formula Student team of Reykjavík University. The
school’s supervisor is Indriði Sævar Ríkharðsson, lector in science and engineering department
at the Reykjavik University.

I would like to thank all those who gave support while carrying out the project. Special thanks
go to my parents, Gróa H. Rósinkransa Jónsdóttir and Ragnar Kristinn Ingason, for showing
support throughout my school career. I would also like to thank my friend, Jón Bjarni Bjarna-
son, for helping me make this project possible and proofreading the thesis.
vi
vii

Contents

Abstract iii

Acknowledgements v

Contents vii

List of Figures ix

List of Tables xi

List of Abbreviations xiii

1 Introduction 1
1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Engine Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3 Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2 Analysis 9
2.1 Analog circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.1 Active circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.2 Passive ciruits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3 Methods 15
3.1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.1.1 The engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.1.2 Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.1.3 Power source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.1.4 Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.1.4.1 Crankshaft . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.1.4.2 Camshaft . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.1.4.3 Manifold absolute pressure . . . . . . . . . . . . . . . . . . 28
3.1.4.4 Exhaust oxygen . . . . . . . . . . . . . . . . . . . . . . . . 30
3.1.4.5 Throttle Position . . . . . . . . . . . . . . . . . . . . . . . . 32
3.1.4.6 Temperature sensors . . . . . . . . . . . . . . . . . . . . . . 33
3.1.4.7 Battery voltage . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.1.5 Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.1.6 Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.1.6.1 Ignition outputs . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.1.6.2 Injector outputs . . . . . . . . . . . . . . . . . . . . . . . . . 40
viii

3.1.6.3 Auxiliary outputs . . . . . . . . . . . . . . . . . . . . . . . . 41


3.1.7 PCB Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.1.8 Hardware Problems and Testing . . . . . . . . . . . . . . . . . . . . . 43
3.2 Firmware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.2.1 Development environment . . . . . . . . . . . . . . . . . . . . . . . . 45
3.2.2 Interrupt routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.2.3 Sampling and Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . 47
3.2.3.1 Median filtering . . . . . . . . . . . . . . . . . . . . . . . . 47
3.2.3.2 Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3.2.3.3 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.2.4 Crank signal decoder . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.2.5 Ignition calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.2.6 Fuel calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
3.2.7 Tuning interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
3.2.8 Calibrations and Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.2.8.1 Analog Test . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.2.9 Firmware Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.2.9.1 NVIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

4 Results & Discussion 65


4.1 PCB Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
4.2 Cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
4.3 Current Consumption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.4 Timing & Pulsewidth Accuracy . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.4.1 Ignition Output Testing . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.4.2 Injector Output Testing . . . . . . . . . . . . . . . . . . . . . . . . . . 71
4.5 ECU testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

5 Conclusion 73
5.1 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
5.1.1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
5.1.2 Firmware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
ix

List of Figures

1.1 An example of an AFR table [2] . . . . . . . . . . . . . . . . . . . . . . . . . . . 3


1.2 An example of an ignition advance table [2] . . . . . . . . . . . . . . . . . . . . . 3
1.3 Nomenclature for reciprocating engines [2] . . . . . . . . . . . . . . . . . . . . . 4
1.4 Actual cycle for four-stroke spark ignition engine [2] . . . . . . . . . . . . . . . . 6

2.1 The internals of the 741 operational amplifier [5] . . . . . . . . . . . . . . . . . . 9


2.2 The noninverting operation amplifier configuration [5] . . . . . . . . . . . . . . . 10
2.3 The voltage follower operation amplifier configuration [5] . . . . . . . . . . . . . . 11
2.4 The voltage divider [5] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.5 The breakdown voltage graph of a zener diode [7] . . . . . . . . . . . . . . . . . . 12
2.6 A passive first order low-pass filter [5] . . . . . . . . . . . . . . . . . . . . . . . . 13
2.7 A passive second order low-pass filter [5] . . . . . . . . . . . . . . . . . . . . . . 13
2.8 The first order low-pass filter [5] . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3.1 Position of the crankshaft wheel when at TDC [9] . . . . . . . . . . . . . . . . . . 16


3.2 Position of camshaft lobes when at TDC [9] . . . . . . . . . . . . . . . . . . . . . 17
3.3 The firing order of the R6 engine [9] . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.4 The Arduino Due Core [10] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.5 The Arduino Mega Core [11] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.6 The mounting slot for the EEPROM on the Arduino Due Core . . . . . . . . . . . 20
3.7 LM1084 power dissipation [14] . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.8 LM2940 power dissipation [15] . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.9 The crankshaft wheel and the VR sensor . . . . . . . . . . . . . . . . . . . . . . . 23
3.10 The measured signals from crankshaft and camshaft sensors . . . . . . . . . . . . 23
3.11 The MAX9926 footprint and pinout [16] . . . . . . . . . . . . . . . . . . . . . . . 24
3.12 The MAX9926 operating modes [16] . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.13 The recommended connection diagram for operating mode A2 [16] . . . . . . . . . 25
3.14 Designed circuit diagram for the crankshaft signal . . . . . . . . . . . . . . . . . . 25
3.15 Input signal versus the output signal of the MAX9926 interface . . . . . . . . . . . 26
3.16 The camshaft signal indicator of the Yamaha R6 engine . . . . . . . . . . . . . . . 26
3.17 Designed circuit diagram for the camshaft signal . . . . . . . . . . . . . . . . . . . 27
3.18 The MPX4115AP [23] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.19 The MPXAZ6115 [22] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.20 Output signal of the MAP sensors in regards to pressure in kPa [23] [22] . . . . . . 29
3.21 Designed circuit diagram for the MAP sensor . . . . . . . . . . . . . . . . . . . . 30
3.22 Electrical difference between a Narrowband and Wideband sensors. [25] . . . . . . 31
3.23 Designed circuit diagram for the exhaust oxygen signal . . . . . . . . . . . . . . . 32
3.24 Designed circuit diagram for the throttle position sensor . . . . . . . . . . . . . . . 32
3.25 Resistance of the NTC resistor in regards to temperature in celsius [27] . . . . . . . 33
x

3.26 Designed circuit diagram for the temperature sensors . . . . . . . . . . . . . . . . 33


3.27 Designed circuit diagram for the battery voltage . . . . . . . . . . . . . . . . . . . 34
3.28 Basic schematic of a transistor controlled ignition system [29] . . . . . . . . . . . 36
3.29 Difference between CDI and TCI [30] . . . . . . . . . . . . . . . . . . . . . . . . 37
3.30 F6T558 ignition coil from Mitsubishi . . . . . . . . . . . . . . . . . . . . . . . . 37
3.31 Measurments of injector and ignition outputs in regards to the crankshaft and camshaft
signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.32 Designed circuit diagram for the ignition output signals . . . . . . . . . . . . . . . 40
3.33 Recommended circuit diagram for the LM1949 [32] . . . . . . . . . . . . . . . . . 40
3.34 Designed circuit diagram for the injector outputs . . . . . . . . . . . . . . . . . . . 41
3.35 Designed circuit diagram for the RPM signal generator . . . . . . . . . . . . . . . 42
3.36 Top view of the PCB design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.37 Bottom view of the PCB design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.38 Latency measurments of ignition/injector outputs with 1kΩ resistor and a 20µs rise
time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.39 Latency measurments of ignition/injector outputs with 10kΩ resistor and a 208µs
rise time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.40 Latency measurments of ignition/injector outputs with 100kΩ resistor and a 2.3ms
rise time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.41 Median filter example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
3.42 An example for interpolation of a 2x2 VE table. [33] . . . . . . . . . . . . . . . . 49
3.43 Logging window of the tuning interface . . . . . . . . . . . . . . . . . . . . . . . 54
3.44 VE table window of the tuning interface . . . . . . . . . . . . . . . . . . . . . . . 54
3.45 Ignition advance table window of the tuning interface . . . . . . . . . . . . . . . . 55
3.46 AFR table window of the tuning interface . . . . . . . . . . . . . . . . . . . . . . 55
3.47 Analog test with the variable resistors at lowest value . . . . . . . . . . . . . . . . 57
3.48 Analog test with the variable resistors at approximate medium value . . . . . . . . 57
3.49 Analog test with the variable resistors at highest value . . . . . . . . . . . . . . . . 57
3.50 Code for tracing the NVIC problem . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.51 Serial monitor of tracing the NVIC problem . . . . . . . . . . . . . . . . . . . . . 59
3.52 Operation in the "NVIC EnableIRQ()" function regarding NVIC problem . . . . . 59
3.53 Code printing out ISER[0] register regarding NVIC problem . . . . . . . . . . . . 60
3.54 Serial monitor of ISER[0] register regarding NVIC problem . . . . . . . . . . . . . 60
3.55 The incorrect version of the "for loop" . . . . . . . . . . . . . . . . . . . . . . . . 62
3.56 The correct version of the "for loop" . . . . . . . . . . . . . . . . . . . . . . . . . 62
3.57 Test code to test the ISER[0] register . . . . . . . . . . . . . . . . . . . . . . . . . 62
3.58 Results of the test code in figure 3.57 . . . . . . . . . . . . . . . . . . . . . . . . . 63

4.1 Top side of PCB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66


4.2 Bottom side of PCB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
4.3 Measurments of the ECU current consumption . . . . . . . . . . . . . . . . . . . . 68
4.4 Signal parameters for reference of the accuracy testing . . . . . . . . . . . . . . . 69
4.5 Measurment of ignition pulse durration . . . . . . . . . . . . . . . . . . . . . . . . 69
4.6 Measurment of the time between teeth regarding ignition measurments . . . . . . . 70
4.7 Measurment of the time between ignition event and TDC regarding ignition mea-
surments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
4.8 Measurment of the injector pulsewidth . . . . . . . . . . . . . . . . . . . . . . . . 71
xi

List of Tables

3.1 Due Core and Mega Core comparison [4] [12] . . . . . . . . . . . . . . . . . . . . 19


3.2 MAX992x and LM1815 comparison [16] [17] . . . . . . . . . . . . . . . . . . . . 24
3.3 Mass stoichiometric value of different fuels [24] . . . . . . . . . . . . . . . . . . . 30
3.4 Cut-off frequency for each analog circuit . . . . . . . . . . . . . . . . . . . . . . . 34
3.5 NVIC priority order [4] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
3.6 Results of the analog testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
3.7 Table of SETENA bits in the ISER[] register. [4] . . . . . . . . . . . . . . . . . . 61
3.8 Table of decimal and binary value of ISER[] register . . . . . . . . . . . . . . . . . 61

4.1 The cost of the ECU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67


xii
xiii

List of Abbreviations

MCU Microcontroller Unit


PCB Printed Circuit Board
SMD Surface Mount Device

ECU Engine Control Unit


RPM Revolutions Per Minute
MAP Manifold Absolute Pressure
cc Cubic Centimeters
VR Variable Reluctance
TDC Top Dead Center
BDC Bottom Dead Center

IDE Integrated Development Environment


PIO Peripheral Input/Output
2
IC Inter-Integrated Circuit
UART Universal Asynchronous Receiver-Transmitter
NVIC Nested Vector Interrupt Controller
ADC Analog to Digital Converter
EEPROM Electrically Erasable Programmable Read-Only Memory
SETENA Interrupt Set-Enable Bits.
ISER Interrupt Set-enable Registers

FSAE Formula Society of Automotive Engineers


UK United Kingdom
xiv
1

Chapter 1

Introduction

The thesis contains a brief introduction to the thesis subject, explaining the background and
setting the general tone of the thesis before defining the scope and the outline of the thesis.
From there the subject will be academically researched, the methods will be explained and
finally, the results will be presented and discussed.

1.1 Background
The modern world is ever increasing in its technological advances. In the case of automotive
industry, no exceptions are made. The modern vehicle is packed with all sorts of electrical
devices, each having its own purpose. The most vital electrical component of a modern pro-
duction vehicle is the ECU (Engine Control Unit). The ECU is an evolution of the mechanical
ignition and injection systems. Devices such as the distributor, driven by the rotational force
of the engine to control the ignition timing and the carburetor, controlling the fuel volume to
the cylinders using the vacuum created by actuating the throttle valve which allows for more
air to flow through the carburetor. The modern ECU is a control unit that controls the ignition
and injection of fuel in regard to external and internal digital and analog sensors. The ECU
can either be an open-loop system or a closed-loop system depending on whether it contains
sensors like an exhaust oxygen sensors which provide a feedback signal, making the ECU a
closed-loop system. The closed-loop ECU is provided with a feedback signal from the sensor
and adjusts its outputs accordingly. An open-loop ECU receives input signals and gives an out-
put signal in accordance with the input signals. The variety of ECUs produced in commercial
vehicles is massive since most manufacturers design their own ECUs. In commercial vehicles
the operational conditions are fairly harsh, being exposed to[1]:

• Temperatures ranging from -40 to 125°C under normal operating conditions

• Abrupt temperature variations

• Exposure to fluids such as oil, fuel, water, moisture, etc.

• Mechanical stresses such as engine vibration

In the case of performance ECUs, the variety reduces considerably. These performance ECUs
are designed for near universal compatibility, containing circuitry for all sorts of auxiliary de-
vices whether it being additional inputs or outputs. Performance suggests the operating con-
ditions are much more extreme depending on the usage and the overall design of the vehicle.
These conditions are met with a more durable design of casing and a better placement of the
2 CHAPTER 1. INTRODUCTION

ECU.

The primary benefit of performance ECUs is the capability of changing the fuel volume and
ignition timing at distinct RPM (Revolutions Per Minute) and MAP (Manifold Absolute Pres-
sure) values in a simple manner. These factors are changed using specific tuning interfaces
which allow the user to connect a computer to the ECU through the interface and changing the
constants in the ECUs memory to meet the engine specification and the general purpose of the
vehicle. Whether it is used in drag racing where momentary power is important or in the case
of a vehicle driven in an endurance race where the durability of the engine must not be compro-
mised over the capable power output of the engine.

The control unit consists of a microcontroller, power transistors and other digital and analog
circuitry. The ECU is used to measure values from various sensors including:

• Air temperature

• Coolant temperature

• Throttle position

• Air to fuel ratio

• Intake air pressure

• Camshaft position

• Crankshaft position

The data from the sensors is both used to estimate injector and ignition pulse widths, and igni-
tion and injection timing, which are configurable for both RPM (Revolutions Per Minute) and
MAP (Manifold Absolute Pressure) often referred to as "Load". Tuning tables and vectors are
used to configure the fuel and ignition, the RPM vector is commonly on the X-axis and the load
vector on the Y-axis. The most basic tables are VE (Volumetric Efficiency) table, AFR (Air to
Fuel Ratio) and ignition advancing table. See example of AFR table in figure 1.1 and spark
advance table in figure 1.2 both displaying the table content and the RPM and MAP vectors. [2]
1.1. BACKGROUND 3

Figure 1.1: An example of an AFR table [2]

Figure 1.2: An example of an ignition advance table [2]

Engines are commonly configured to use less fuel (Lean mixture) on lower loads to improve
fuel economy and on higher loads, the fuel is increased (Rich mixture) for higher power output
and to reduce the risk of engine damage. The higher the load, the more air is sucked into the
engines cylinders, which requires more fuel to be delivered to the cylinder so the AFR remains
in balance. The fuel is calculated by using the ideal gas model for air (Equation 1.1). [3]

P ·V =n·R·T (1.1)

The ignition timing is configurable by either advancing from the TDC (Top Dead Center, ex-
plained in chapter 1.1.1) or retarding it. By advancing the ignition timing, the spark fires further
from the TDC mark, making the spark ignite sooner. But when the timing is retarded, the spark
fires closer to the TDC mark, making the spark ignite later. There are two ways of implement-
ing the timing of the spark, either by wasted spark system or sequential system. Wasted spark
system sparks every round of the crankshaft but the sequential system only sparks at the power
stroke. The sequential system requires a camshaft position sensor on the engine, to indicate
when the power stroke occurs for each cylinder, further explained in chapter 1.1.1.

The Formula Student team of Reykjavík University plans on constructing its third vehicle to
4 CHAPTER 1. INTRODUCTION

compete in the Formula SAE competition in 2018, the competition will take place in the United
Kingdom on the famous Silverstone Circuit. To cut down costs and gain an immense knowl-
edge, the decision was made to design and construct an ECU for the provisioned engine. The
engine in question comes out of a Yamaha YZF-R6 motorcycle. The rules and regulations for
the FSAE UK competition restrict certain assets of the original motorcycle engine, making the
original motorcycle ECU nonfunctional for the vehicle and the need for a performance ECU.

1.1.1 Engine Basics


The internal combustion engine is the driving force of the Formula SAE cars when it comes to
fuel-driven vehicles. For the internal combustion engines, there are specific regulations which
have to be followed. Main restrictions are: engine must be a 4-stroke engine, maximum dis-
placement restriction is 710 cc (0.710L), an intake air restrictor with air flow gap that varies
depending on the fuel chosen. Key for a successful design, that fulfills these parameters, is
understanding the basics of an engine.

The Otto cycle is the ideal cycle for a spark-ignition reciprocating engine. A reciprocating
engine is the most common powerhouse of an automobile. The engines main components are
intake- and exhaust valves, cylinder, and a piston. The piston moves up and down in the cylin-
der and the distance from the lowest to the highest point of the piston movement is called the
stroke. The highest position of the stroke is called TDC (Top Dead Center) and the lowest
position is called BDC (Bottom Dead Center). When the piston is at BDC the largest volume
in the cylinder occurs, displacement volume and conversely TDC is when the smallest volume
in the cylinder takes place, clearance volume. The diameter of the cylinder is called the bore
of the engine. The AFR mixture is drawn into the cylinder through the intake valve and after
combustion, the exhaust gases from the burnt AFR mixture are pushed out through the exhaust
valve.

Figure 1.3: Nomenclature for reciprocating engines [2]


1.1. BACKGROUND 5

The compression ratio (R) of the engine is the ratio between the displacement- and clearance
volume and is calculated using the cylinder volume at TDC and BDC, see equation 1.2.

VBDC
R= (1.2)
VT DC
6 CHAPTER 1. INTRODUCTION

The four-stroke internal combustion engine executes four strokes or two mechanical cycles
meaning that the crankshaft completes two revolutions per Otto cycle. The four strokes of the
Otto cycle are compression-, power-, exhaust- and intake stroke. Let’s assume that initially, the
piston is at BDC, with intake- and exhaust valves closed and with the cylinder full of fresh AFR
mixture.

1. Compression stroke: The piston compresses the AFR mixture as it moves from BDC
upwards to TDC.

2. Power stroke: Shortly before the piston reaches the highest position the spark plug fires
and the mixture ignites. The result of increased pressure and temperature of the system
forces the piston down to BDC and since the piston is connected to the crankshaft it
rotates and produces usable work output.

3. Exhaust stroke: At the end of the power stroke the cylinder is full of combustion products.
The exhaust valve opens and the piston purges the exhaust gases through the exhaust valve
as it moves up towards TDC again.

4. Intake stroke: The intake valve opens and as the piston moves towards BDC again the
cylinder is filled with fresh AFR mixture.

Figure 1.4: Actual cycle for four-stroke spark ignition engine [2]

The key ingredients for successful combustion are fuel and oxidizer, multiple variations of
fuel and oxidizer mixture exist in the automotive industry, but in this case the fuel is an E85
mixture and the oxidizer is the oxygen in the air. The spark plug provides the source of heat
required to initiate the combustion. Combustion quality and speed have a direct impact on
engine performance, so it is important to get the fuel/oxidizer mixture right. An ideal case
scenario is a complete combustion, to achieve that with the E85 fuel, the AFR (Air to Fuel Ratio)
has to be stoichiometric or about 9.8:1, note that this is a mass ratio. However stoichiometric
mixture does not necessarily produce the most power output from the engine. Mixture varies
depending on the engine load and speed and has to be adjusted individually for each engine and
fuel type.
1.2. SCOPE 7

The thermal efficiency of an Otto engine increases with higher compression ratio and therefore
higher compression ratio is feasible. The downside of running high compression ratio engines
is that the temperature of the air/fuel mixture is capable of rising above the auto-ignition tem-
perature of the fuel during the compression stroke and causes a premature and rapid burn of
the mixture. Auto-ignition is when fuel ignites without the help of a spark ignition, the com-
pressed air becomes so hot that it ignites the fuel. This premature ignition of the fuel produces
an audible noise which is called engine knock and in spark-ignition engines knocking hurts per-
formance and can cause engine damage. Gasoline blends with high anti-knock characteristics,
such as E85 have made running engines with higher compression possible. E85 is a mixture of
85% Ethanol mixed with 15% gasoline. The project will be performed with the presumption
that the engine will run on the E85 mixture. [2]

1.2 Scope
The original and main purpose of the project is to cut down costs on the electrical system of
the FSAE car. However, there is an underlying purpose of designing and constructing an ECU
rather than buying a new one, that is the immense knowledge received in the process. The
project will be available for other students to further develop the ECU.

Despite the cost being the main priority, the project requires some design goals for the ECU
to work properly. Therefore the subject of the thesis will also focus on the following goals:

• Write a program that contains all necessary algorithms to make an engine run.

• Accuracy of 0.1ms on injector and ignition pulse width.

• Accuracy of 0.1° on timing calculations for injector and ignition outputs.

• Design a PCB capable of receiving and produce the relevant signals with minimum cur-
rent consumption of 1A in a steady state operation.

• Maintain a budget of 100 dollars per unit produced.

1.3 Outline
The thesis outline is as follows:
Chapter 2: The analysis of the various methodology.
Chapter 3: The methods of the project is explained.
Chapter 4: The test results of the methodical approaches, are presented and discussed.
Chapter 5: The end results of the project is presented and future work is discussed.
8
9

Chapter 2

Analysis

2.1 Analog circuits


2.1.1 Active circuits
The operational amplifier (op-amp) is an active component and consist of a multiple bipolar
junction transistors divided into stages to effectively provide a single output signal depend-
ing on the two input signals, see figure 2.1 for reference of the internals of a popular op-amp
design. The transistors are able to provide the output signal with several stages of circuit pro-
tection depending on the external circuitry around the op-amp. This protection is crucial for the
microcontroller since the recommended maximum input voltage of the Arduino Due is 3.6V
[4]. The op-amp requires a separate voltage source and a separate ground connection to work,
making the final PCB design more intricate.

Figure 2.1: The internals of the 741 operational amplifier [5]


10 CHAPTER 2. ANALYSIS

Analysis of two op-amp circuit configurations are suitable for the objective at hand, the volt-
age follower configuration (figure 2.3) and the noninverting amplifier configuration (figure 2.2).
Both are farily simple designs with few external components, making the cost of the PCB pro-
duction lower.

The noninverting configuration, figure 2.2 requires 2 resistors acting as current limiters and
as voltage divider depending on the values of the resistors. Since the objective is to convert
the 0 - 5V signal to a 0 - 3.3V signal, the resistors must be of different sizes as suggested by
equation 2.1 for closed loop transfer function gain.

VO R2
=1+ (2.1)
VI R1

The equation clearly shows that the closed loop gain product of the noninverting configuration
will always exceed 1 unless the value of R2 is zero. If R2 = 0 then the configuration would
resemble the voltage follower configuration which is analysed separately. Calculating the re-
quired gain product to convert the max 5V analog input signal, from the sensor, to the max 3.3V
output signal, going to the microcontroller, equation 2.1 is used. With VI = 5V and VO = 3.3V
the gain product equals 0.66. This means that with a 5V input signal, the output signal can not
be a 5V or lower. One way to impement this is to put the input signal VI through a voltage di-
vider, making the voltage divider drop the 5V signal to a 3.3V signal and designing the op-amp
circuit so that the gain product is close to 1. This means that the op-amp will strictly be used
for circuit protection and the amplification factor will ever so slightly decrease the resolution
of the signal since the amplification will always exceed 1. This would not sevearly impact the
measurment reading, depending on the ratio between R1 and R2 .

Figure 2.2: The noninverting operation amplifier configuration [5]

The Voltage follower configuration, figure 2.3 is a simpler design from the noninverting config-
uration. The configuration acts as a unity gain buffer, unity gain meaning that the gain product
is always 1. Simular problem arise with the follower as with the noninverting op-amp, the gain
does not fall below 1 and the required gain product is 0.66. The problem is solved similar to the
solution for the noninverting op-amp, with a voltage divider on the input signal.
2.1. ANALOG CIRCUITS 11

Figure 2.3: The voltage follower operation amplifier configuration [5]

The problem with the op-amp circuits analyzed above is that they do not provide the gain
product required and are therefore only suitable as buffers for the microcontroller.

2.1.2 Passive ciruits


The passive components examined for the project are the resistor, capacitor and the zener diode.
The resistor provides an implementation of voltage dividers, see figure 2.4. The Voltage has
to be dropped from the range of 0 - 5V down to the range of 0 - 3.3V. The voltage divider
also provides linearity through the whole bandwidth, making the calculations of the transfer
functions more. The passive components do not require any sorts of operating voltages, making
the PCB design simpler. The voltage divider formula can be seen in equation 2.2. For full
resolution, the output voltage has to be as close to 3.3V as possible, with the standard resistor
values available, when the input voltage is at 5V. For the analog circuits, the aim is not to exceed
1mA on each sensor circuit. With RL as 20kΩ and RS as 10kΩ, the max current consumption is
5V /30kΩ = 0.167mA and the output voltage from the voltage divider, calculated with equation
2.2, is 3.33V with an input voltage of 5V providing a reasonable resolution for the project.

Figure 2.4: The voltage divider [5]

RL
VO = VS · (2.2)
RL + RS
12 CHAPTER 2. ANALYSIS

A passive component commonly used for protecting sensitive components is the zener diode,
allowing current to flow through the kathode of the diode when the voltage over it exceeds a cer-
tain limit. The zener doide analyzed is the SMD TZMC3V3 from Vishay. The diode has a 3.3V
threshold and idealy it conducts at the 3.3V mark. However, the breakdown voltage expands
over a longer voltage range, see figure 2.5 where −VZ is the 3.3V, and it statrs conducting before
the 3.3V mark and then exponentially increases as it gets closer to the 3.3V voltage. According
to the datasheet, the TZMC3V3 starts conducting at the 3,1V mark and therefore decreasing the
resolution of the sensor. The TZMC3V6 starts conducting at 3.4V making it the most fitting
zener diode for the project since the maximum input voltage of the microcontroller is 3.6V,
explained in chapter 3.1.2. [6]

Figure 2.5: The breakdown voltage graph of a zener diode [7]

The capacitor is commonly used for filtering out unwanted frequencies. These filters come in
various configurations. Four filters are most common, the low-pass, high-pass, band-pass and
band-stop filters. The project requires only one configuration and that is the low-pass filter. The
filter will be used to cut out unwanted disturbance in the signal. The low-pass filter has a DC
gain of 1, meaning it increases conductivity at lower frequencies and decreases conductivity at
higher frequencies depending on various factors of the filter, making it the most fitting filter for
this project. The filters are able to have several filtering stages which increase or decrease the
efficiency of the filter. The first order, low-pass, passive filter is the simplest low-pass filter and
composes of a single resistor and a single capacitor, see figure 2.6. By adding another first order
filter to the filter, a second order filter is formed which provides sharper filtering of the desired
frequency.
2.1. ANALOG CIRCUITS 13

Figure 2.6: A passive first order low-pass filter [5]

Figure 2.7: A passive second order low-pass filter [5]

Figure 2.8: The first order low-pass filter [5]

The ω0 is the cut-off frequency of the filter and with higher order of the filter the steeper the
slope of the bode plot, see figure 2.8. The cut-off frequency of a first order filter is calculated
with equation 2.3 and the cut-off frequency of a second order filter is calculated in equation 2.4.
[8]
1
fC = (2.3)
2·π·R·C
1
fC = √ (2.4)
2 · π · R1 · C1 · R2 · C2
For all analog filters of the project, the resistance of the filter resistor is set as 9.1kΩ and capac-
itors are selected to fit the cut-off frequency with the application.
14
15

Chapter 3

Methods

The chapter informs the reader of the methods used to achive the project goals. The chapter is
split into two main sections, hardware and firmware.

The hardware section includes:

• Introduction to the engine being used for the project.

• Research and choice of microcontroller.

• Circuit design of the power source of the ECUs components.

• Research and design of input signal circuitry.

• Filter design of the input signals.

• Research and design of output signal circuitry.

• The overview of the PCB design process.

• Solutions to the problems concerning the hardware are presented.

The firmware section includes:

• The choice of the development environment.

• Methods of programming the interrupt routines.

• Filtering and sampling algorithms concerning the input signals.

• The method of decoding the crankshaft signal.

• Ignition timing calculations and programming.

• Injection pulse-width calculations and programming.

• Communication methods with the tuning interface.

• Programming calibrations and tests are prsented.

• Solutions to the problems concerning the firmware are presented.


16 CHAPTER 3. METHODS

3.1 Hardware

3.1.1 The engine

To adapt the ECU design to the engine specifications, the engine mechanical components and
general specification must be considered. These components are the crankshaft wheel, camshaft
and firing order of the cylinders along with other minor engine parameters.

The crank wheel decoder in the ECU requires a reference signal to indicate that the crank
wheel has completed one rotation. This is usually done by cutting out one or two teeth from
the crank wheel. On the Yamaha engine, the crankshaft wheel has 22 teeth and 2 missing teeth,
so the wheel is specified as a 24-2 crank wheel. To find the TDC of the engine, the crankshaft
wheel has to be inspected. Referring to figure 3.1, the TDC of the first cylinder can be found
by rotating the crank clockwise until the first piston is on the compression stroke and the TDC
mark ("a") on the crank wheel aligns with the crankcase mating surface ("b"). Cylinder number
one is the cylinder closest to the stator of the engine, the stator being the electrical generator of
the engine.

Figure 3.1: Position of the crankshaft wheel when at TDC [9]


3.1. HARDWARE 17

The compression stroke, explained in chapter 1.1.1, can be found when the camshaft lobes of
the first cylinder are turned away from each other, see figure 3.2. The TDC is crucial knowledge
for the ECU, setting the base for all injection and ignition timing calculations.

Figure 3.2: Position of camshaft lobes when at TDC [9]

The firing order is another factor to be considered. The firing order is the sequence of power
delivered in a multi cylinder engine. Without the correct firing order, the engine will not run
properly or not at all. The firing order for the R6 engine is 1-2-4-3, see figure 3.3. The firing
order is the order of which cylinder is on which stroke can be seen in figure 1.4, where "A" is the
degrees that the crankshaft is turned clockwise, "B" is the cylinder and "C" is the combustion
cycle. [9]

Figure 3.3: The firing order of the R6 engine [9]


18 CHAPTER 3. METHODS

3.1.2 Controller
The controller is the most important component of the ECU, responsible for all signal pro-
cessing, calculations and signal generation regarding the process of running the engine. A
microcontroller in an ECU is required to contain various features that are divergently important
to the operations of the engine. Features including the I/O pins, analog pins, operating voltage,
memory type and capacity, ADC, timer/counters resolution, and capacity.

The required microcontroller features for this project are:

• 3 Interrupt pins for the crank, cam and neutral switch signal

• 8 Timers/counters for injection and ignition per cylinder

• Counters with resolution capable of running the engine at 14000RPM

• 12 Digital I/O pins

• 6 Analog input pins

• EEPROM memory

• Analog to Digital Converter

Many microcontroller brands are available, but the decision was made to work with controllers
from Atmel because of the familiarity to the hardware and software along with the customer
support available for the Atmel products. The decision is between two microcontrollers, the
Arduino Due and the Arduino Mega. Both being available in a more compact versions of them-
selves, the Arduino Due Core seen in figure 3.4 and the Arduino Mega Core seen in figure 3.5.

Figure 3.4: The Arduino Due Core [10] Figure 3.5: The Arduino Mega Core [11]
3.1. HARDWARE 19

The Arduino Due uses the SAM3X8E SMART ARM-based microcontroller and the Arduino
Mega uses the Atmega2560. A comparison of the required features along with some additional
operating features can be seen in table 3.1.

Arduino Due Core Arduino Mega Core


Cost 18 dollars 19 dollars
Dimensions 54 x 58mm 36 x 51mm
Microprocessor SAM3X8E ATmega2560
Operating voltage 3.3V 3.3V or 5V
Clock speed 84MHz 16MHz
Interrupt pins 103 8
Timer/Counters 9 6
Counter resolution 32-bit 2x8-bit, 4x16-bit
Digital I/O pins 103 54
Analog pins 12 16
2
EEPROM I C Compatible 4Kbytes
ADC resolution 12-bit 10-bit

Table 3.1: Due Core and Mega Core comparison [4] [12]

Analyzing the specifications in table 3.1, The Arduino Due Core has the advantage in most as-
pects. The advantages that the Mega Core has over the Due Core are the dimensions, operating
voltage, analog pins and the internal EEPROM.

The dimensions of the microcontroller can influence the overall dimensions of the PCB. The
larger the microcontroller, the larger the possible PCB design. However, the difference is too
insignificant to influence the choice of the microcontroller. A possible solution to the extra
space is to place other circuit components on the space under the microcontroller, since the
microcontroller is mounted on the PCB.

The operating voltage of the Mega Core is an advantage over the Due Core. The Mega Core
operates at both 5V and 3,3V. Some analog sensors incorporated in the project require a 5V volt-
age source and subsequently produce a 0-5V analog signal to the microcontroller. This would
simplify the circuit design significantly because the voltage would not have to be converted to
a 0-3,3V signal as is required when using the Due Core.

The Mega Core has 16 analog pins allowing for more analog sensors. But when all required
sensors are considered, see chapter 3.1.4, only 6 out of the 16 pins (Mega Core) or the 12 pins
(Due Core) would be used for this project. This makes the number of analog pins irrelevant to
the choice of microcontroller. However, the Due Core has a 12-bit ADC over the 10-bit ADC
that the Mega Core has. The ADC converts the analog signal from the sensors to a digital signal
for the processor to read. The resolution of the ADC (Volt/Bit) of either device is calculated
below, n being the number of bits.

V oltage
Resolution = (3.1)
2n
20 CHAPTER 3. METHODS

With a 3.3 operating voltage, the resolution of the Due Core ADC would be 0.00080566V /bit
against the 0.0032226V /bit resolution of the Mega Core. The resolution is important to get the
most accurate sensor reading and subsequently have more accurate results of calculations done
from those readings.

In the automotive industry, the EEPROM is used for storing tuning tables and engine con-
figuration constants. The tuning tables and constants are stored in the EEPROM and used by
the MCU to calculate ignition/injection timing and the pulse-width needed for each crank cy-
cle. The EEPROM also allows the user to change the table and the engine configuration values
while the engine is running, preventing the inconvenience of uploading a new program to the
microcontroller every time a change is made to the tables or constants. The EEPROM commu-
nicates through the I2 C protocol. The Mega Core includes a 4Kbyte EEPROM, while the Due
Core does not. However, the Due Core PCB includes a mounting slot for an external EEPROM,
see figure 3.6. The slot is for an 8 lead TSSOP8 SMD footprint. An EEPROM in the same
footprint is the AT24CxxxC series from Atmel corporations. The AT24CxxxC series EEPROM
comes in two sizes. A 128Kbyte version (AT24C128C) and a 256Kbyte version (AT24C256C).
The At24C256C chip is available at the Atmel store for around 0,49 dollars for one EEPROM
[13]

Figure 3.6: The mounting slot for the EEPROM on the Arduino Due Core

Results: Preferably, the focus would be set on cost but because of the insignificant difference
in cost, the focus was set on the timers and the EEPROM for accuracy and storage capability.
With the Arduino Due Core having 9 32-bit counters/timers and the availability for external
mounting of an EEPROM (figure 3.6), using I2 C communication, the Due was chosen. The
counter/timers are used for the ignition timing and injection timing. Since the motor is estimated
to reach speeds of 14000RPM and containing 4 injectors, and 4 ignition coils the amount and
resolution of the timers are crucial for accurate ignition and injector timing. The downside
of the Arduino Due was the 3.3V operating voltage. Because all analog sensors give an output
voltage of 0-5V and some need a supply voltage of 5V. The solution to this problem is explained
in further details in chapter 2.1.
3.1. HARDWARE 21

3.1.3 Power source


Electrical power is essential for the components of the PCB to work. For this project, three
voltages are used for supplying sensors and other components of the ECU, 12V, 5V and 3.3V
voltage sources. The primary voltage source of the engine and all components of the Formula
Student car is the 12V battery. For the ECU to work, the 12V from the battery must be converted
to 5V and 3.3V. This is done with voltage regulators. The primary concern of the voltage
regulator is the capable power consumption, without sacrificing the cost. Two regulators were
compared, the LM1084 and the LMx940 both coming in 5V and 3.3V versions, the LM1084-
5V, LM1084-3.3V, LM3940 and the LM2940. Both regulators cost around 2 dollars for 5
pieces, depending on the seller, meaning that each regulator would cost 40 cents making the
cost low enough to be irrelevant. The short circuit current of the LM2940 is 1,9A with the
junction temperature of 25°C and input voltage of 12V, according to the datasheet. However,
the LM1084 has the current limit of 8A maintaining the junction temperature above -40°C and
under 125°C and having the input voltage of 10V. The aim of the project is to have a maximum
current consumption of 1A, with equation 3.2 the calculated maximum power consumption of
the 5V regulator is 7W at 1A and the maximum power consumption of the 3.3V regulator is
8.7W at 1A. [14] [15]
P ower = (VIN − VOU T ) · I (3.2)

The temperature at 7W and 8.7W consumption is calculated from information on the datasheet
and equation 3.3.
T hermalResistance = RθJA − RθCS − RθJC (3.3)

For the 3-pin TO-220 footprint the thermal resistances RθJA , RθCS , RθJC without any heat sink
are: [15]

• RθJA is the junction to ambient thermal resistance and is 23.3 °C/W

• RθCS is the case to heat sink thermal resistance and is 0 °C/W

• RθJC is the junction to case thermal resistance and is 3 °C/W

Calculated with equation 3.3, with the thermal resistance values above, the thermal resistance
is 20.3°C/W. Multiplying the thermal resistance with the maximum power consumption and
adding the ambient temperature of 25°C, the expected temperature of the TO-220 footprint at
1A current consumption is 167.1°C for the 5V regulator and 201.61°C for the 3.3V regulator.
The absolute maximum temperature rating of either regulator is 150°C, making it necessary to
add a heat sink. To stay inside the recommended operating conditions, the temperature has to
be below 125°C making the thermal resistance of the heat sink to be above 5.93°C/W.

In figures 3.7 and 3.8, the power dissipation of each regulator is graphed, the LM1084 provides
no information on the power dissipation with different heat sinks and only provides information
of the regulator with no heat sink. The datasheet for LM2940 provides the power dissipation at
three different scenarios, without a heat sink, with a 10°C/W heat sink, and with an infinite heat
sink. With the power dissipation and current capability being less for the LM1084 and both
regulators costing the same, the LM1084 was chosen for this project
22 CHAPTER 3. METHODS

Figure 3.7: LM1084 power dissipation [14] Figure 3.8: LM2940 power dissipation [15]

3.1.4 Inputs
In control systems, a sensor of some sort is usually used to provide a signal to the controller
which influences the output of the system. An input signal is required for the engine to run
smoothly at various speeds and engine loads. Some signals are crucial for the engine to run at
all and others only provide a fine-tuning element to the engine response and the general opera-
tions of the engine.

Since the engine fuel and ignition systems are not of the mechanical design and the engine
uses an electronic fuel delivery and ignition triggering, the most crucial feedback signals are
the following:

• Crankshaft signal

• MAP signal

Other input signals only improve the smoothness and general operations of the engine. The
signals included in the project are the following:

• Camshaft signal

• Exhaust oxygen (AFR)

• Throttle position

• Intake air temperature

• Coolant temperature

• Battery voltage
3.1. HARDWARE 23

3.1.4.1 Crankshaft
The VR (Variable Reluctance) sensor is located by the crankshaft wheel, see figure 3.9 and
generates the crankshaft signal as the teeth of the crank wheel pass the sensor.

Figure 3.9: The crankshaft wheel and the VR sensor

The sensor gives out a sinusoidal signal with fluctuating voltage amplitude and frequency, which
is dependent on the angular speed of the crankshaft wheel. The crankshaft and camshaft sig-
nal were measured with an oscilloscope, see figure 3.10 where the yellow line indicates the
crankshaft signal and the blue line indicates an inverted camshaft signal.

Figure 3.10: The measured signals from crankshaft and camshaft sensors

The analog signal must be converted to digital form before being processed by the microcon-
troller. This is done by putting the signal through a VR interface. Two VR interfaces were
compared, the LM1815 from Texas Instruments and the MAX992x from Maxim Integrated.
Both interfaces comprise of zero-crossing detection circuits and as the name suggests, the in-
terface detects when a signal crosses the 0 voltage threshold. The MAX992x comes in four
packages, MAX9924-MAX9927. MAX9924 and MAX9925 have a single zero-crossing detec-
tion circuit while the MAX9926 and MAX9927 have two zero-crossing detection circuits. The
price of the MAX992x depends on the popularity of the interface, the MAX9926 is the most
popular of the four and subsequently has the lowest price, so the MAX9926 will be compared
with the LM1815. Comparisons of both components can be seen in table 3.2. [16] [17]
24 CHAPTER 3. METHODS

MAX992x LM1815
Cost 3 dollars 5 dollars
Size Medium Large
Footprint 16QSOP D(R-PDSO-G14)
Power 5V 5V
VR circuits 2 1

Table 3.2: MAX992x and LM1815 comparison [16] [17]

Relying on the comparison in table 3.2, the MAX9926 was chosen because of the cost and the
interface provides two zero crossing detection circuits and is capable of detecting a digital sig-
nal from Hall Effect sensors allowing for future experementations with the interface.

The MAX9926 has 16 pins, see figure 3.11, and four operating modes available, depending
on the external connection of the interface, see figure 3.12.

Figure 3.11: The MAX9926 footprint and pinout [16]

Figure 3.12: The MAX9926 operating modes [16]

Referring to figure 3.12, the A2 operating mode has an internally generated reference voltage
(0V) used to bias the differential amplifier and all internal circuitry instead of an external volt-
age connected to the BIAS input. The operating mode both fits the application of the project
and also helps reduce external components and design variables leading to a more robust appli-
cation. The recommended circuit diagram of opperating mode A2 can be seen in figure 3.13
3.1. HARDWARE 25

Figure 3.13: The recommended connection diagram for operating mode A2 [16]

Circuit: The VR sensor is connected to the input pins of the interface through two 10K ohm
resistors on each input for current limiting purposes. A 1nF capacitor is connected over the two
input signal wires for noise cancelation. The output of the interface has two stages, floating or
grounded. In order to read the output signal, a pullup resistor is needed with a voltage source,
the voltage source being 3.3V because of the input voltage tolerance of the microcontroller. A
shunt resistor (R324 in figure 3.14) is connected across the VR sensor to reduce the overall
voltage produced by the VR sensor, allowing for interface to operate at higher RPMs. [18]

Figure 3.14: Designed circuit diagram for the crankshaft signal


26 CHAPTER 3. METHODS

Figure 3.15: Input signal versus the output signal of the MAX9926 interface

Figure 3.15 shows the measured input signal (Pink) compared to the measured output signal
(Blue) of the VR interface. The zero crossing of the input signal while the voltage is decreasing
indicates the center of the crank tooth. Comparing the output signal with the input signal, it
can be seen that when the output signal is on the rising edge, the input signal voltage crosses
the zero voltage threshold while decreasing. Making the rising edge of the output signal of the
MAX9926 the indicator for the center of the current tooth. This information is crucial when
programming the injector and ignition timing calculations. [19]

3.1.4.2 Camshaft
The camshaft signal is produced by a Hall Effect sensor, giving out 5V pulses every time the
sensor detects a metal substance, see figure 3.10. The camshaft wheel is a complete metal ring
mounted on the exhaust camshaft controlling the exhaust valves. The ring is indented in one
place indicating the position of the camshaft, see figure 3.16. The hall effect sensor gives a
steady 5V signal until it passes the indented surface of the camshaft ring, grounding the sensor
output. The signal must be dropped down to logic level (3.3V) in order for the microcontroller
to be able to receive the signal.

Figure 3.16: The camshaft signal indicator of the Yamaha R6 engine


3.1. HARDWARE 27

A transistor will be used to drop the voltage down and provide an over voltage protection to
the input of the microcontroller, making the solution simple and effective. The MOSFET and
the photocoupler will be compared for the objective at hand. The MOSFET is the BSS138,
N-Channel Logic Level Enhancement Mode Field Effect Transistor and the photocoupler is the
PC817 photocoupler. The photocoupler provides an electrical isolation up to 5kV, completely
separating the 5V signal from the 3.3V signal which the BSS138 MOSFET does not accom-
plish. However, the BSS138 is a fast switching transistor providing minimum latency of the
acquired signal, which the photocoupler does not accomplish. With the maximum rise time of
the BSS138 transistor being 18ns while the maximum rise time of the photocoupler is 18µs.
Taking into count the deviation of the actual latency depending on the quality of the compo-
nent, the rise time of the photocoupler is too high. Considering that the cycle time of one engine
rotation at the target RPM limit (14,000 RPM) is 4.28ms and while maintaining the accuracy of
0.1° (0.1° = 1.18µs at 14,000RPM) on ignition and injection timing, the BSS138 is the better
choice for this project. [20] [21]

Circuit: The circuit will consist of a MOSFET transistor which acts as a buffer. The signal
from the camshaft sensor controls the base of the transistor, opening the source of the transistor
and grounding the respective pin on the microcontroller. The camshaft wheel is a smooth circle
with one indent indicating the signal pulse, therefore the base of the transistor is pulled up to
a 5V voltage source. The MOSFET also acts as an inverter, meaning the input signal on the
microcontroller is the inverted output signal of the Hall Effect sensor, resembling the signal in
figure 3.10. See figure 3.17 for the designed camshaft signal circuit.

Figure 3.17: Designed circuit diagram for the camshaft signal


28 CHAPTER 3. METHODS

3.1.4.3 Manifold absolute pressure

The MAP (Manifold Absolute Pressure) sensor measures the air pressure in the intake manifold
providing the base of calculating the mass of air inside the cylinders. The air mass decides
the fuel mass delivered to the cylinder. The MAP sensor comes in various packaging, whether
it be an external sensor mounted on the intake manifold or an internal sensor, mounted inside
the ECU with a small hose going on a fitting, mounted on the intake manifold. The internal
MAP sensor usually referred to as on-board MAP sensor, is mounted on the ECU PCB. Two
on-board sensors will be compared for use in this project since the external sensors are heavier
and require extra wires in the wiring loom instead of just one small hose.

Two sensors were compared for the project, the MPX4115xx and the MPXxx6115A. The
MPX4115xx sensor is a dip mounted sensor while the MPXxx6115A is an SMD mounted
sensor. Both sensors come in various packaging, usually, with the nozzle being directed in a
different direction, the sensor packaging with the nozzle directed to the side is the preferred
sensor for this project. The reason for that is to position the sensor under the microcontroller
and therefore utilizing all the space available to make the final product more compact. If the
nozzle directs upwards, the sensor would hit the microcontroller, the only way for the sensor to
be under the microcontroller is if the nozzle is directed to the side. The MPX4115AP and the
MPXAZ6115A fit the description of the application, see figure 3.18 and 3.19. To clarify, the
MPX4115AP sensor in figure 3.18 is mounted on the board and the mounting pins are bent 90°
so that the nozzle is directed to the side. [22] [23]

Figure 3.18: The MPX4115AP [23] Figure 3.19: The MPXAZ6115 [22]

Both sensors are available at around the same price at Mouser Electronics, the MPX4115AP
costs around 15 dollars plus shipment and the MPXAZ6115 costs around 13 dollars plus ship-
ment, making it around 30 dollars for each sensor. The price reduces if multiple sensors are
purchased at once. The price also reduces if the sensor is bought from China through eBay. The
price, therefore, does not have a significant effect on the choice of the sensor. The datasheet for
both sensors provide the same transfer function of the output voltage in regards to the absolute
pressure, see figure 3.20. [22]
3.1. HARDWARE 29

Figure 3.20: Output signal of the MAP sensors in regards to pressure in kPa [23] [22]

Both sensors have the maximum error of 1.5% at 0°C to 85°C and are ideally suited for micro-
controller based systems. However, the MPXAZ6115 has the following features making it the
dominant sensor for an ECU and this project.

• Resistant to high humidity and common automotive media.

• Improved accuracy at high temperature.

• Typical applications include engine control/manifold absolute pressure (MAP).

Another significant difference is the dimensions of the sensors, the MPXAZ6115 is smaller in
all dimensions making it the reasonable choice for the project. Despite the dimensions of the
MPX4115 sensor, it is not too large to fit under the microcontroller. Although the MPXAZ6115
is the reasonable choice for an ECU design, the MPX4115 had already been bought for previous
ECU designs by the Formula Student team, so the MPX4115 was chosen for this project because
of its availability. The MPX4115 was also available at lower prices when bought from China.
Although, for future development, the MPXAZ6115 would be a more suitable choice.

Circuit: The Manifold absolute pressure sensor is of an on-board type, meaning the sensor is
mounted on the PCB. A hose from the intake manifold is connected to the sensor to measure
the pressure in the manifold. The output signal of the sensor gives a 0 - 5V signal which goes
through a voltage divider to provide a range of 0 - 3.3V signal. The signal goes through a second
order low-pass filter, described in chapter 2.1.2, in order to prevent any distortion in the signal.
Pins 4, 5, and 6 are internal device connections and are not connected. The designed circuit for
the MAP sensor can be seen in figure 3.21.
30 CHAPTER 3. METHODS

Figure 3.21: Designed circuit diagram for the MAP sensor

3.1.4.4 Exhaust oxygen

The exhaust oxygen (AFR) sensor is the only sensor, for this project, to provide a feedback sig-
nal to the ECU. It measures the oxygen in the exhaust pipe and gives a 0 - 5V signal depending
on the lambda (AFR) ratio in the exhaust.

Lambda is a scale which relates to the air to fuel ratio of any sort of fuel. An ideal burn of
any sort of fuel is a 1.0 lambda reading. Usually, the lambda reading is converted to the AFR
format for the specific fuel that is being used. When reading the AFR, the stoichiometric value
is the AFR ratio which provides an ideal burn for the fuel being burnt, the value differs de-
pending on the fuel being used. For the typical gasoline fuel, the stoichiometric value by mass
is 14.7:1 AFR, 14.7 grams of air against 1 gram of gasoline. So, the lower the stoichiometric
value, the more fuel is required for an ideal burn. [24]

Fuel Stoichiometry
Gasoline 14.7:1
Ethanol 9.0:1
E85 9.8:1
Diesel 14.5:1

Table 3.3: Mass stoichiometric value of different fuels [24]

There are two types of oxygen sensors, narrowband and wideband sensor. The narrowband
sensor is calibrated to know three states of the mixture, rich, stoichiometric and lean. A rich
mixture has too much fuel and a lean mixture has too little fuel for an ideal burn. The narrow-
band sensor works as a digital sensor, giving a high signal when the mixture is lean and a low
signal when rich. The wideband sensor, however, is a linear analog sensor giving out a voltage
signal depending on the lambda reading, see figure 3.22. [25]
3.1. HARDWARE 31

Figure 3.22: Electrical difference between a Narrowband and Wideband sensors. [25]

The sensor used for this project is the Wideband sensor from Innovate Motorsports. The sensor
will be reused from the previous Formula Student car from the 2017 competition to save cost.
Included with the sensor is a wideband controller. The controller provides the ECU with the
analog signal corresponding to the lambda value in the exhaust. It also provides a calibration
capability and a serial communication to a PC computer. The controller operates on a 12V
voltage source, with nominal 2A current consumption, and outputs a 0-5V signal with a 10-bit
resolution depending on the lambda value. [26]

The ECU, therefore, requires a circuit to convert the 0 - 5V signal to a 0 - 3.3V signal. Several
methods are possible and will be looked in to with consideration taken to cost, space consump-
tion, circuit protection, efficiency, and simplicity. Two circuit variations were researched in
chapter 2, an active circuit amplification, and a passive circuit amplification.

Circuit: The input signal is put through a voltage divider to get the appropriate signal for
the microcontroller to process. The voltage divider in question consists of a 12kΩ resistor
and a 20kΩ resistor resulting in an output voltage of 0V at 0V input voltage and at 3.125V
output voltage at 5V input voltage. Some preventions were taken in regard to not having the
output voltage at 3.3V when the input voltage is at 5V. This is done as a safety measure if the
input voltage goes somewhat over 5V the output voltage of the divider doesn’t go over 3.3V.
Specified max voltage for the LM1084 voltage regulator is 5.1V. [14] To calculate the input
voltage for a 3.3V output voltage, the voltage divider equation (Equation 2.2) is configured as
so VS = VO · RLR+RL
S
and with RS = 12kΩ and RL = 20kΩ, the input voltage is at 5.28V to get
a 3.3V output voltage. A second order low-pass passive filter is designed to cut out possible
noise that may occur to shield the microcontroller from damaging. The filter also allows the
microcontroller to receive a more stable signal from the O2 sensor. See figure 3.23 for the
designed circuit diagram for the exhaust oxygen sensor.
32 CHAPTER 3. METHODS

Figure 3.23: Designed circuit diagram for the exhaust oxygen signal

3.1.4.5 Throttle Position

The TPS (Throttle Position Sensor) in a vehicle is used to measure the position of the throttle
valve inside the throttle body. The throttle valve is actuated by pressing the throttle pedal. The
signal is configured to a 0 - 100% values in the program and is used for auxiliary actions like
the flood clear action which cuts the signal to the injectors when the throttle is above the 80%
threshold and the engine is starting. The procedure is necessary if the spark plugs are not able
to ignite a spark because of too much fuel wettening the spark plugs. The fuel is then restricted
access to the cylinder to allow the excess fuel to be sucked out of the cylinder.

Circuit: The TPS is a basic 10kΩ variable resistor. The sensor has three poles, Vin, Vout,
and ground. A stable 3.3V source is provided to the TPS and connected to Vin on the sensor,
the Vout signal then connects to a second order filter for noise filtering, see figure 3.24 for the
designed circuit diagram.

Figure 3.24: Designed circuit diagram for the throttle position sensor
3.1. HARDWARE 33

3.1.4.6 Temperature sensors


The temperature sensors are the IAT (Intake Air Temperature) sensor and the coolant temper-
ature sensors. Both sensors are included with the purchase of the engine and both sensors are
composed of the same NTC resistor and therefore have the same transfer function for the change
in resistance to the change in heat, see figure 3.25. [9]

Figure 3.25: Resistance of the NTC resistor in regards to temperature in celsius [27]

Circuit: Both temperature sensors are an NTC resistor. To be able to make use of the sensor,
one pole is pulled to ground and the other pole is connected to the microcontroller with a pull-
up resistor to 3.3V voltage source, creating a voltage divider, see figure 3.26. Equation 2.2
was used find a suitable resolution for the sensors. At the lowest recommended temperature,
-40°C, the resistance of the NTC resistor is around 100kΩ. To get the highest resolution from
the sensor, the Resistance of RS has to be the significantly lower than RL . If RS is too low, the
current consumption at high temperature is too high. With a 1kΩ resistor, the maximum current
is 3.3mA and the input voltage of the microcontroller is 3.267V.

Figure 3.26: Designed circuit diagram for the temperature sensors


34 CHAPTER 3. METHODS

3.1.4.7 Battery voltage

The battery voltage measurement is used to adjust puls-width of injectors and ignition outputs
in accordance with the supply voltage from the battery. If the battery voltage decreases, the
dwell time for the ignition and injectors increase resulting in a need for higher pulse-width. The
opposite happens when the battery voltage increases. The reason is the

Circuit: The battery voltage is measured using a simple voltage divider. The measurement
voltage range is set by controlling the values of the 2 resistors in the divider. Resistor 1 is set at
82kΩ and resistor 2 is set at 22kΩ. The output of the divider gives a 3.3V signal at 15.6V input
voltage. So, the range is set at 0 - 15.6V. If the battery voltage exceeds the 15.6V mark, making
the input voltage of the microcontroller higher than 3.3V, the zener diode allows current to flow
through it to protect the microcontroller. See figure 3.27 for the designed circuit.

Figure 3.27: Designed circuit diagram for the battery voltage

3.1.5 Filters
Filters are incorperated in every analog circuit to filter out unwanted noise. The noise coming
from the engine was not measured so the filters are designed to filter out the estimated noise.
The cut-off frequency of each analog circuit can be seen in table 3.4.

Circuit Filtering order Cut-off frequency


MAP sensor 2nd order 356 Hz
Exhaust oxygen 2nd order 76 Hz
TPS 2nd order 356 Hz
IAT & Coolant 2nd order 164 Hz
Battery voltage 1st order 7,2kHz

Table 3.4: Cut-off frequency for each analog circuit


3.1. HARDWARE 35

3.1.6 Outputs

In all control systems, an output signal is always produced. The output signals required for
any operation of the engine are the fuel and ignition output signals. The fuel system uses fuel
injectors to inject fuel into the intake manifold, which mixes with the air and is sucked into the
cylinders for compression. The ignition system uses ignition coils to produce a high voltage
spark to ignite the compressed AFR mixture which generates an explosion resulting in a down-
ward motion of the piston.

The ECU is designed for a four-cylinder engine with a port fuel injection (PFI) where one
injector is placed at each of the intake ports. Other injection configurations exist, each having
its advantages and disadvantages over the other. Some of the configurations are below with a
brief description.

• Single Port Injection (SPI): SPI system uses only one injector for all cylinders, injecting
the fuel into the throttle body right before the throttle valve of the throttle body.

• Port Fuel Injection (PFI): PFI system has one or more injectors for each cylinder. The
PFI has different types of configuration. Batched, where fuel is injected at the same time
to each intake port. Sequential, where fuel is injected into each port at the time when
airflow is established at the respective port.

• Gasoline Direct Injection (GDI): The injector for each cylinder is placed in the cylinder
head so that fuel injects directly into the combustion chamber

Ignition system configurations are of various designs. The most recent and most common
method is the coil on plug ignition system. The system consists of an ignition driver, a spark
plug and an ignition coil mounted on the spark plug. Some coil on plug ignition coils incor-
porate the ignition driver inside the coil casing, other ignition coils require an external ignition
driver. The ignition coil transforms 12V DC from the battery into a high voltage range of
4000V. The high voltage is conducted through the spark plug igniting a spark at the end. An-
other ignition system consists of an ignition coil, distributor, and a spark plug. This system uses
a distributor driven by mechanical means, usually the crankshaft, to distribute the high voltage
from the ignition coil to each spark plug at the correct time. The system requires only one
ignition but gives fewer possibilities to tune the ignition timing. [28]
36 CHAPTER 3. METHODS

A basic circuit of the modern ignition configuration can be seen in figure 3.28.

Figure 3.28: Basic schematic of a transistor controlled ignition system [29]

3.1.6.1 Ignition outputs

The ignition timing is configurable by either advancing from the TDC or retarding it. By ad-
vancing the ignition timing, the spark is fired before the TDC (BTDC) but when the timing is
retarded, the spark is fired after TDC (ATDC). There are two ways of implementing the timing
of the spark, either by wasted spark system or sequential system. Wasted spark system sparks
every round of the crankshaft but the sequential system only sparks at the power stroke, see
figure 1.4. The sequential system requires a camshaft on the engine, to indicate when the power
stroke occurs. There are several ways to make the spark plug ignite a spark in the cylinder
chamber. Capacitive discharge ignition (CDI) and Transistor controlled ignition (TCI) are the
two most common ways, CDI is often used for smaller engines such as motorcycle engines or
ATV, but TCI is commonly used in cars and is taking over the CDI system in modern vehicles.
CDI system works by charging a capacitor to around 400 V DC and shorting it to the ignition
coil at the specified ignition time. TCI system works by charging up the ignition coil until it has
fully charged, then the current is released and the spark ignites. See in figure 3.29 for reference
on how the CDI and TCI works.
3.1. HARDWARE 37

Figure 3.29: Difference between CDI and TCI [30]

The CDI ignition system is an outdated system existing in older motorcycles. Requiring more
circuitry and more complex ways of controlling the ignition timing. The TCI requires less cir-
cuitry and provides wider ignition timing calculations, making it the dominant system for this
project.

The engine bought for the Formula Student project has the spark plugs and ignition coils in-
cluded. The ignition system is a coil on plug requiring an external ignition driver. The ignition
coils have two pins, each connected to each side of the low voltage coil windings, see figure
3.30.

Figure 3.30: F6T558 ignition coil from Mitsubishi


38 CHAPTER 3. METHODS

The option of having an ignition coil containing the ignition driver in the casing requires the
purchase of four new ignition coils. The cost would be around 160 dollars for four ignition
coils. However, the ignition driver would not have to be designed for the project since it would
be included inside the coil casing. The cost of new ignition coils is too much for a slightly
simpler PCB design and is deemed not worthy of purchase.

An ignition driver is used to control the ignition coil ground. One pin on the ignition coil is
connected to the 12V battery supply through a relay or a mechanical switch. The other pin is
connected to the ignition driver. The driver requires a signal from the microcontroller to allow
the ignition coil to charge and as soon as the driver cuts off the ground signal to the coil, a spark
ignites at the end of the spark plug.

An ignition driver usually consists of a transistor connected in the low side driver configura-
tion. This means that the transistors collector/drain terminal is connected to the ignition coil,
the emitter/source of the transistor is connected to ground and the base/gate is controlled either
directly by the microcontroller or by other means. The method of using other devices to control
the base/gate of the transistor creates a buffer protection for the microcontroller from the con-
stant 12V pulses generated by the ignition driver. The method also allows for more current to
be able to flow between the collector/drain and the emitter/source of the transistor. The BSS138
MOSFET, used in chapter 3.1.4.2, is a fast switching MOSFET making it an ideal transistor
for the ignition buffer and to amplify the control signal to the power MOSFET controlling the
ignition coil. This, also, allows a purchase of multiple MOSFETS, reducing the cost of the final
product. The typical dwell time of ignition coils is 2.3ms. This time increases and decreases
depending on certain conditions, like the battery voltage and if the engine is cranking. This
means that at maximum RPM (4.2ms per cycle) the duty cycle would be around 54%. With
a primary coil resistance of 1.19–1.61Ω and a source voltage of 12V, the maximum current
flow through the drain of the transistor would ideally be (12V /1.19) · 54/100 = 5.44A at these
conditions, disregarding the rise time of the coil. In the case of a program failure where the
base/gate of the ignition transistor would permanently be on, the maximum current would be
12V /1, 19Ω = 10.1A. Giving the current tolerance through the collector/drain of the desired
transistor. Another concern are the flyback spikes that occur when a spark ignites. Figure 3.31
shows a measurement of one ignition output signal (Blue) and one injector output signal (Pink)
of the original Yamaha ECU. The ignition signal shows how severe the spikes can be. Therefore,
a protection from these spikes is required. A flyback diode is one solution. Another solution is
the IGBT (Insulated Gate Bipolar Transistor). The IGBT combines the bipolar technology with
the MOSFET technology, making it highly efficient and fast switching. [28]
3.1. HARDWARE 39

Figure 3.31: Measurments of injector and ignition outputs in regards to the crankshaft and
camshaft signal

The IRGB14C40L is an advanced IGBT with a maximum IC current of 14A and "includes a
MOS gated, N-channel logic level device which is intended for coil-on-plug automotive ignition
applications and small-engine ignition circuits. Unique features include on-chip active voltage
clamps between the Gate-Emitter and Gate-Collector which provide over voltage protection
capability in ignition circuits." [31] The chip active voltage clamp makes the flyback diode un-
necessary for the IGBT. The IGBT is, therefore, a better choice over the common MOSFET
connected to a flyback diode. The cost of the IRGB14C40L will be sacrificed for the quality of
the IGBT over the common MOSFET.

Circuit: The gate of the BSS138 transistor is connected to the output pin of the microcon-
troller with the internal pull-up resistor enabled on the microcontroller. A LED is also con-
nected to the gate of the BSS138. This is done to help the debugging process, indicating a
light when the ignition coil is charging. The LED is connected so that it does not interrupt the
ignition process if the LED fails. The source terminal of the BSS138 is connected to the gate of
the IGBT with a 1kΩ resistor is pull to a 12V voltage source. One pin of the ignition coil is ex-
ternally connected to a 12V voltage source, and the other connects to the IGBT, see figure 3.32.
40 CHAPTER 3. METHODS

Figure 3.32: Designed circuit diagram for the ignition output signals

3.1.6.2 Injector outputs

The injector is used to inject fuel into the intake manifold before it gets sucked into the cylinder
chamber for ignition. The injector is a simple solenoid, requiring 12V voltage source and a
ground signal. The ground pin on the solenoid is controlled with a transistor. The transistor
receives a signal from the microcontroller when an injection is needed. The injector being used
is the Delphi Multec 2 injector with the flow rate of 11.79kg/hour at 4,14bar of fuel pressure.
The injector is a high impedance injector with the resistance of 12Ω. With a maximum duty
cycle rule of thumb being 80%, the maximum current would be 0.8A. A driver is needed to
control the injector timing. The LM1949 is a dedicated fuel injection circuitry in automotive
systems. It is designed to control a pair of transistors in the Darlington configuration, see figure
3.33.

Figure 3.33: Recommended circuit diagram for the LM1949 [32]


3.1. HARDWARE 41

Another approach was taken on the injector driver. Instead of buying the LM1949 and the
circuitry around it, the IRF3205 power MOSFET with a flyback diode was chosen because it
had been bought for previous prototype ECUs that the Formula Student team had designed.
Seeing that the project is a prototype design, reusing already bought and tested components
seem logical at the moment. But for further development, the injector driver is a priority matter
for the PCB design.

Circuit: The circuit is identical to the one described in chapter 3.1.6.1, with two differences.
The transistor is a MOSFET, not an IRGB, and a flyback diode is added to the source of the
MOSFET, see figure 3.34

Figure 3.34: Designed circuit diagram for the injector outputs

3.1.6.3 Auxiliary outputs

The RPM value is calculated in the program of the ECU. This RPM value is important for the
driver of the vehicle to know or for any data logging equipment. The calculated RPM value will
be produced as an output signal changing with respect to the RPM of the engine. The output
signal can be used in other features of the car, whether it be logging or indicating.

Circuit: The signal pin of the microcontroller controls the base of a MOSFET transistor. The
output pin is programmed so that an internal pull-up resistor is enabled, so an external resistor is
not necessary. The source of the transistor is connected to the output pin of the ECU and pulled
up to the common 12V voltage source from the battery, producing an inverted output signal of
the microcontroller, see figure 3.35.
42 CHAPTER 3. METHODS

Figure 3.35: Designed circuit diagram for the RPM signal generator

3.1.7 PCB Design


The PCB was designed in Altium. The PCB is a 4 layer board with each layer dedicated to
different aspects of the circuitry.

• Layer 1: The top layer is dedicated to the 12V signals from the injector and ignition
drivers.

• Layer 2: The power layer is dedicated for voltage sources to all components on the PCB

• Layer 3: The GND layer is a dedicated ground layer, with 3 separate ground planes. One
for small signal grounding, one for ignition grounding and one for injector grounding.

• Layer 4: The signal layer is dedicated for all small signal circuitry, including all SMD
components.

The design schematics were sent off to a PCB company, named seeedStudio, for production and
all components were soldered on the board when the PCB arrived.

Figure 3.36: Top view of the PCB design Figure 3.37: Bottom view of the PCB design
3.1. HARDWARE 43

3.1.8 Hardware Problems and Testing

When testing the assembled PCB, the ignition and injector outputs started to heat up when the
ECU was in a steady state. The cause of the problem is that, as seen in figures 3.32 and 3.34,
the R101 and R201 pull-up resistors to the 12V of the emitter of the BSS138 transistor is a 1kΩ
resistor. The maximum current when the transistor continually allows current flow through the
emitter is 12V /1000Ω = 12mA. If the resistor value would be 10kΩ, the current would drop
down to 1.2mA or with a 100kΩ consuming 120µA. Another factor of concern is the increased
latency produced with higher resistance. Meaning the time it takes the voltage to travel through
the collector/source to reach desired levels in regards to the gate voltages of either transistor.

The rise time of the gate voltage of the ignition/injector transistors were measured using an
oscilloscope with the three resistor values mentioned above, 1kΩ, 10kΩ and 100kΩ. The re-
sults of the measurements can be seen in figures 3.38, 3.39 and 3.40, yellow line indicating the
gate voltage of the ignition/injector power transistor and the pink line represents the crankshaft
signal.

Figure 3.38: Latency measurments of ignition/injector outputs with 1kΩ resistor and a 20µs
rise time
44 CHAPTER 3. METHODS

Figure 3.39: Latency measurments of ignition/injector outputs with 10kΩ resistor and a 208µs
rise time

Figure 3.40: Latency measurments of ignition/injector outputs with 100kΩ resistor and a 2.3ms
rise time

The rise time to a steady 12V of the three measuments are:

• 1kΩ resistor gives 20µs rise time, total current for 8 circuits is 96mA.

• 10kΩ resistor gives 264µs rise time, total current for 8 circuits is 9.6mA.

• 100kΩ resistor gives 2.3ms rise time, total current for 8 circuits is 0.96mA.

The decrease in rise time results in an inaccurate ignition and injector pulsewidth and with a
goal of 0.1ms pulse-width accuracy, the latency of the 10kΩ and the 100kΩ circuits are too high
so the current consumption was sacrificed for the decrease in rise time by continue using the
1kΩ resistor.
3.2. FIRMWARE 45

3.2 Firmware
The program of the ECU will be of the basic C programming language instead of programming
in a more modernized language, requiring more intricate programming methods but providing
faster calculating time and input/output signal generation.

3.2.1 Development environment


The IDEs (Integrated development environment) possibilities are many when programming the
C language. The familiarity of the user is an important factor when choosing the IDE. Two
IDEs were considered bearing in mind that the programming language would be the C lan-
guage, the Eclipse IDE and the Atmel Studio. Both platforms provide a community forum for
customer service and problem solving. Atmel Studio gains the edge when considering the mi-
crocontroller. Since the microcontroller is produced by Atmel corporations, the Atmel Studio
provides much more support for the project in question. It also already contains more libraries
linked to the Atmel products. The familiarity with Atmel Studio, the customer service and the
link between the microcontroller and the IDE is the reason why Atmel Studio was chosen for
this project.

3.2.2 Interrupt routines


Programming interrupts are used for interrupting the currently running code so that another rou-
tine can run immediately. When the interrupt routine is done, the program goes back to the code
before the interrupt occurred. The interrupts for this project are of two kinds, PIO (Peripheral
Input/Output) interrupts and timer interrupts.

If an interrupt occurs while another interrupt routine is running, the priority of the interrupts
is the deciding factor of what happens. If the current running interrupts routine (Interrupt 1)
has higher priority than the interrupt that occurred (Interrupt 2) while the interrupt routine of
interrupt 1 is running, interrupt routine 2 is put on hold until interrupt routine 1 has finished.
If interrupt 2 has higher priority, the code jumps to interrupt routine 2, finishes the routine and
then jumps back to where it was in interrupt reoutine 1. The NVIC (Nested Vector Interrupt
Controller) prioritizes the interrupt to the desired priority. Interrupts of the project and their
priorities can be seen in table 3.5. [4]

The timer interrupt is used for calculating the ignition and injection timing of all cylinders. The
timer interrupts are internally triggered on compare match with the global timer, global timer
being the counter for the ECU on time. So when the global timer reaches the compare match
value, an interrupt occurs. Each timer interrupt has 3 compare match registers, RA, RB and RC
value. When the respective timer interrupt ocurrs the compare status register is checked to see
which compare value has match the global timer. RA compare value is used for the ignition
and RB is used for the injection for the respective cylinder, see algorithm 1. RC is not used but
could be used for a second injector in further development.
46 CHAPTER 3. METHODS

Program variable Priority Description


PIOB_PRIORITY 0 PIO interrupt for Crank-, camshaft input
TC0_PRIORITY 1 Timer interrupt for Cylinder 1, Ignition & injection
TC1_PRIORITY 2 Timer interrupt for Cylinder 2, Ignition & injection
T2_PRIORITY 3 Timer interrupt for Cylinder 3, Ignition & injection
TC3_PRIORITY 4 Timer interrupt for Cylinder 4, Ignition & injection
TC4_PRIORITY 5 Not used
TC5_PRIORITY 6 Not used
TC6_PRIORITY 7 Not used
TC7_PRIORITY 8 Not used
TC8_PRIORITY 9 General clock
ADC_PRIORITY 10 Analog to digital converter
PIOA_PRIORITY 11 Neutral switch
UART_PRIORITY 12 UART communication for tuning environment
UOTGHS_PRIORITY 13 USB communication
CAN0_PRIORITY 14 Can bus communication
USART1_PRIORITY 15 Telemetry communication
TWI1_PRIORITY 16 I2C EEPROM communication

Table 3.5: NVIC priority order [4]

Algorithm 1 PIOB_Handler
1: T imerStatus ← RespectiveT imerCompareStatus
2: if T imerStatus = CompareRA then
3: Output signal for ignition pins
4: if T imerStatus = CompareRB then
5: Output signal for injector pins
6: End routine.

The PIO interrupts are triggered on the input pin voltage of the desired interrupt pins. Three
PIO interrupts are used in this project, one for the crankshaft signal, one for the camshaft signal
and one for an external switch ideally for the neutral switch but is used as a debugging pin while
coding and not used at the end of the project. The crankshaft and camshaft signal control the
timing and sequence of all timing operations for the motor, which is why they are set at the
highest priority. When an interrupt occurs on peripheral register B, the ISR (Interrupt Status
Register) is checked to see what input pin has a pending interrupt and performs the functions
relevant to the interrupt, see algorithm 2.
3.2. FIRMWARE 47

Algorithm 2 PIOB_Handler
1: Readpio ← Statusf orP eripheralB
2: if Readpio = CrankSignalP in then
3: Store timing values
4: Set timer compare match values for ignition and injection depending on CamSignal status
5: if Readpio = CamSignalP in then
6: CamSignal = HIGH.
7: Toggle RPM output pin.
8: End routine.

3.2.3 Sampling and Filtering


For a signal to be read without false reading, a filter is used to increase the accuracy of the
reading. Multiple software filters are used in the modern ECU design. The project incorporates
multiple filters and sampling implementations including:

• Median filtering

• Mapping

• Interpolation

3.2.3.1 Median filtering

The median filter is a fundamental and a simple filter used, in this case, for producing accurate
data from all analog sensors. The median filter stores 3 readings in an array and sorts them
from lowest to the highest. The value in the middle is then used for further processing. The
filter provides filtering from false readings that can be too high or too low for the current state
and conditions of the sensor. These false readings can be caused by noise from other output
signals. The function in the program takes in a vector of any size, in this case, the vector size is
3. Using the insertion sort algorithm it sorts the values using a "for-loop" and then returns the
value in the middle, see figure 3.41.

Figure 3.41: Median filter example


48 CHAPTER 3. METHODS

3.2.3.2 Mapping

Mapping is used for converting the serial values of the linear analog sensors to the desired range
of integer values. The input pin of the microcontroller reads a 0 - 3.3V value. The ADC converts
that analog value to a digital serial value depending on the resolution of the ADC. The Arduino
Due Core has a 12-bit ADC, see chapter 3.1.2, and therefore converts the analog voltage to a
serial value of 0−212 (0 - 4096) depending on the voltage value. The mapping function converts
the 0-4096 value to a desired range. For example, the TPS sensor indicates the position of the
throttle from 0% - 100%. To get a 0% - 100% reading, the 0 - 4096 serial value is mapped to
the desired range. The sensors that require mapping in this project are the following:

• AFR sensor with the required range of 50 - 120 indicating the AFR ratio of the E85 fuel.
50 = 5.0 AFR and 120 = 12.0 AFR

• MAP sensor with the required range of 0 - 120 indicating the pressure in kPa inside the
intake manifold

• TPS sensor with the required range of 0% - 100% indicating the position of the throttle
valve in percentages

• Battery voltage sensor with the required range of 0 - 156 indicating the battery voltage. 0
being 0.0 battery voltage and 156 being 15.6 battery voltage

For the mapping function the lower the desired converted range, the higher the resolution of the
analog values. With a 12-bit ADC resolution and a maximum range of 156 (Battery voltage),
the reading of the converted values provides the desired resolution for further processing.
3.2. FIRMWARE 49

3.2.3.3 Interpolation

Bilinear interpolation is used for calculating the target air/fuel ratio, volumetric efficiency and
the ignition degree with respect to the RPM and MAP. The function takes in a 2D table and the
RPM and MAP vectors for the respective tables, see figure 1.1 for reference. The MAP vector
represents the y-axis with the lowest MAP value at the bottom and the highest at the top. The
RPM vector represents the x-axis with the lowest RPM at the left and the highest to the right.
The table, in this case, a VE table, is filled with the target VE (Volumetric Efficiency) values for
the MAP and RPM. To search the target value in the table, four indexes have to be searched and
the values of the indexes are then interpolated, see equation 3.4 for example of an interpolation
of a 2x2 VE table in figure 3.42. [33]

V E = V E11 (1 − p)(1 − q) + V E12 (p)(1 − q) + V E21 (1 − p)(q) + V E22 (p)(q) (3.4)

The index values of p and q are calculated with equation 3.5 and 3.6. [33]

RP M − RP M1
p= (3.5)
RP M2 − RP M1

M AP − M AP1
q= (3.6)
M AP2 − M AP1

For a larger table, a helper function is used to find the indexes above and below the measured
value for both x-axis (RPM) and y-axis (load).

Figure 3.42: An example for interpolation of a 2x2 VE table. [33]


50 CHAPTER 3. METHODS

3.2.4 Crank signal decoder


As described in chapter 3.1.1, the crank wheel is of a 24-2 design and in chapter 3.1.4.1 the
center of the tooth is at the rising edge of the output signal from the VR interface. With that in-
formation, the input pin of the microcontroller is configured to trigger an interrupt on the rising
edge.

The Crank decoder is used to monitor the current tooth of the crank wheel, incrementing an
integer variable every time an interrupt occurs on the crank signal input pin. The integer vari-
able is reset after 360° of engine rotation. The two missing teeth are used for indicating when
to reset the integer variable back to the zero value. The missing teeth are two and the time that
takes for the sensor to pass the two missing teeth and sense the first tooth after the missing teeth
have passed takes 3 times longer than the time between two teeth. The method of comparing
the gap between the previous tooth and the current tooth to the gap between the previous tooth
and the tooth before that is used to find the first tooth after the two missing teeth. If the cur-
rent gap time is 1.5 longer than the previous gap time, the two missing teeth have just passed
the crank wheel sensor and the crank tooth variable is reset to zero. The decoder is also used
to call upon non primary functions regarding ignition and injection timing. Implementing the
functions when the sensor is on a specific tooth. [34]

3.2.5 Ignition calculations


The ignition calculations are done using various timing variables and functions from the inter-
rupt handler and decoder function. The ignition timing is calculated with these variables and
the values in the ignition degree tuning table, described in chapter 3.2.3.3. The target ignition
degree is the desired time of ignition spark BTDC. The spark occurs when the ignition coil has
been charged and the current flow is cut by closing the transistor connected to the ignition coil.
The ignition degree is calculated by referencing the teeth of the crankshaft wheel. The degree
of which the ignition is to occur is calculated at TDC and BDC every revolution of the engine
for all cylinders by calculating how many teeth to skip until an ignition event and the interval
between the specific tooth and the next tooth if the ignition occurs between two teeth. The de-
gree between two teeth is 360/24 = 15 and if an ignition is to occur at 15° BTDC, the ignition
output pin is triggered when the last tooth BTDC is sensored. Equation 3.7 is used to calculate
how many teeth to skip until the ignition event. [34]

Degrees/Calculation − IGN CrankW heelT eeth


T eeth = · (3.7)
Degrees/Calculation Calculations/Rev

In this instance, the values for equation 3.7 are explained below:

• Degrees/Calculations = 360°/2 Calculations per revolution = 180°

• IGN = Target ignition degree interpolated from the tuning table

• CrankWheelTeeth = 24 teeth on the Crankshaft wheel

• Calculations/Rev = 2 Calculations per revolution


3.2. FIRMWARE 51

For example, with an ignition event occurring at 24° BTDC, the result is 10.4 teeth to skip. In C
coding, there are no floating numbers and only integers. Therefore the 10.4 teeth to skip would
be rounded to 10 teeth to skip.

The only value that constantly changes, in equation 3.7, is the target ignition degree (IGN)
from the tuning table, which changes depending on the MAP and RPM. When the correct igni-
tion tooth has been found, the interval between the ignition tooth and the next tooth is calculated
with equation 3.8. [34]

Degrees/Calculation − IGN
T eeth = modulus( · Last individual tooth interval) (3.8)
Degrees/Calculation

The "Last individual tooth interval" is the time it took for the crankshaft sensor to travel be-
tween the ignition tooth and the tooth before that. Here the 0.4 from the results above (10.4
teeth to skip) is used to calculate the time from the ignition tooth until ignition event oc-
curs. For example, with the same target ignition degree of 24° and at 1500RPM. The time
between 2 teeth at 1500RPM is (1/(1500rpm/60sec))/24 = 1.667ms. Multiply the time by
the modulus of 10.4 (0.4) and the result is time until the ignition occurs from the ignition tooth,
1.667ms ∗ 0.4Interval = 0.6668ms.

The ignition dwell (pulse duration) is set as 2.3ms at ideal conditions. The time is adjusted
depending on the battery voltage with the help of mapping explained in chapter 3.2.3.2. The
beginning of the ignition charge is calculated by subtracting the 2.3ms from the time until next
ignition and storing the value in the timer compare match for a future interrupt. Note that the
maximum dwell time is set at 5.0ms and the cranking dwell is 3.5ms to prevent the circuits from
overheating.

3.2.6 Fuel calculations

The fuel injector for each cylinder squirts fuel into the cylinder runners of the intake manifold
once every two revolutions. This method is called sequential injection. The fuel is injected into
the manifold runners before the intake valve of the respective cylinder has closed, restricting
fuel flow into the cylinder. The injector opening and closing time are calculated like the ignition
timing, described in chapter 3.2.5. At maximum revolutions (14000RPM), the revolution time
is 4.28ms and at higher RPMs, the engine requires more fuel which requires the injector to
be open longer. The ignition calculations are done 180° before an ignition event. The longer
pulse-width (80% duty-cycle) requires the injection calculations to be performed 360° before
an injection event. This sacrifices accuracy for longer pulsewidth. The injector closing time is
set as a constant 5° before the intake valve opens and the fuel is sucked into the cylinder. The
reason that the fuel is squirted into the intake port before the intake valve opens, is that it takes
time for the fuel to transfer from the injector to the cylinder, so the fuel is injected before the
intake valve opening and is ready to be sucked into the cylinder. If the fuel is injected too early,
the fuel loses its vapor state and starts to stick to the walls of the intake runners.
52 CHAPTER 3. METHODS

The fuel amount is calculated by rewriting the ideal gas model for air, in equation 1.1 presented
in chapter 1.1, to parametric terms for the engine.

• P = Pressure

• V = Volume

• n = Number of moles

• R = Gas constant

• T = Temperature in kelvin

The equation interperated by the ECU is split into three stages, finding the numerator for the
injector time (Equation 3.9), and the denominator for the injector time (Equation 3.10) which
result in the injector time for ideal conditions (Equation 3.11) [35] [36]

N umerator = MAP · VE TARGET · FUEL CONSTANT (3.9)

Denominator = AFR TARGET · (IAT + 273) (3.10)

N umerator
Injector Time = (3.11)
Denominator
The fuel constant in equation 3.9, is calculated from engine constants, the gas constant and the
fuel density, see equation 3.12.

CYL DISP · 60
FUEL CONSTANT = (3.12)
FUEL DENS · GAS CONST · NR INJ * FLOW RATE

The density of ethanol is 789Kg/m3 and the density of gasoline is 719.7Kg/m3 . With an E85
mixture (85% ethanol and 15% gasoline) the density of E85 is 778.6Kg/m3 . So the value of
all constants in equation 3.12 are:

• CYL DISP: Cylinder displacement = 600cc

• FUEL DENS: Fuel density = 778.6Kg/m3

• GAS CONST: Gas constant = 287J/(kg ∗ K)

• NR INJ: Number of injectors = 4

• FLOW RATE: Injector flow rate = 197cc/min (26lb/hour)

The fuel constant in this case is 0.00020434 and is multiplied by 1,000,000,000 so the program
is able to factor the constant into equation 3.9, since the program would interperate 0.00020434
as 0. Equation 3.11 give the injector time in µs/10. So with an outcome of 45000 from equation
3.11, the injector time would be 4.5ms. The multiplication is done to prevent overflow and
factoring by the program, that way the calculations are more precise.
3.2. FIRMWARE 53

3.2.7 Tuning interface


A method of changing the tuning tables, which are stored in the EEPROM, is needed for a
much more user friendly tuning capability. The essential functions of the tuning environment
are to change and store values in the tuning tables and display most essential values like the
battery voltage and RPM. A tuning interface was coded in python using the pycharm IDE. The
interface has 4 window, displaying the volumetric efficiency (VE) table (figure 3.44), target
ignition degree (DEG) table (figure 3.45), air to fuel ratio (AFR) table (figure 3.46) and a few
parameters which are essential information for the user to know if something goes wrong (figure
3.43). With figure 3.43 as reference, the parameters displayed are listed below allong with the
explinations of the values displayed:

• RPM: Shows current rpm of the engine (1251 = 1251RPM)

• MAP: Shows current map value in the intake manifold (98 = 98kpa)

• AFR: Shows current air to fuel ratio from the wideband sensor (99 = 9.9AFR for E85)

• BAT: Shows the current battery voltage - 120 = 12.0V

• TPS: Shows the current position of the throttle valve (0 = 0%)

• COL: Shows the current temperature of the coolant (116 = 116°C)

• IAT: Shows the current temperature of the air in the intake manifold (40 = 40°C)

• INJ: Shows the target injector pulsewidth (68 = 6.8ms)

• IGN: Shows the target ignition pulsewidth (23 = 2.3ms)

• VE T: Shows the target volumetric efficiency calculated from the VE table (70 = 70%)

• DEG T: Shows the target ignition degree BTDC calculated from the DEG table (136 =
13.6°)

• AFR T:Shows the target air to fuel ratio calculated from the AFR table (88 = 8.8AFR for
E85)

• GAMMA: Shows the current gamma enrichment (103 = 103%)


54 CHAPTER 3. METHODS

The tables have configurable variables that can be changed while the engine is running. The
values in the tables have to be changed and then burnt into the memory. When the "BURN"
button is pressed, the python program burns the changed values of the current table into the
EEPROM using the I2 C communication protocol. If a variable is changed without burning, the
value returns to its original value when the ECU is restarted.

Figure 3.43: Logging window of the tuning interface

Figure 3.44: VE table window of the tuning interface


3.2. FIRMWARE 55

Figure 3.45: Ignition advance table window of the tuning interface

Figure 3.46: AFR table window of the tuning interface


56 CHAPTER 3. METHODS

The python program sends the character "A", through the serial communication port, to the
ECU and receives a struct containing the desired display parameters. The same logic is used to
change the values in tables and burn the values to the EEPROM. The ECU program uses pages
to direct the correct value to the corresponding table. The following characters represent the
corresponding action:

• "P" indicates a new page is being requested.

• "1" represents the VE page.

• "3" represents the AFR page.

• "5" represents the IGN page.

• "W" represents the write command of the current page.

• "A" requests the struct parameters.

• "B" commands the ECU to burn the current page.

• "V" requests the information on the current page.

For example, when writing the appropriate value in the AFR table, the character order of "P"
"3" "W" is sent to the ECU followed by the value’s address on the x-axis, then the address on
the y-axis and then the value to be changed. the following commands have the representing
operation:

• Sending the combination of "P" "3" "W" "5" "2" "80": The value of 80 is written in the
5th column of the 2nd row.

• Sending the lone character "A": Request the struct of parameters to be displayed.

• Sending the combination of "P" "1" "B": Commands the ECU to burn the VE table to the
EEPROM.

3.2.8 Calibrations and Tests


3.2.8.1 Analog Test
To Measure the results of the configuration of analog inputs, the sensor value and the serial
value was printed out on the serial port and compared to the expected values from calculations.
The test program was written so that when a mechanical debug button was pushed, all serial
and sensor values were printed out only once. This was done three times. First, with all 10K
Ω variable resistor values on the analog test circuits set to the lowest value. The debug button
was then pressed and results on the serial port were analyzed, see figure 3.47. Next, the variable
resistors were set to approximate mid value and result printed out to the serial port, see figure
3.48. Last, the resistors are set to the max resistance value and result printed to the serial port,
see figure 3.49. Table 3.6 shows the results of the analog testing.
3.2. FIRMWARE 57

Figure 3.47: Analog test with the variable resistors at lowest value

Figure 3.48: Analog test with the variable resistors at approximate medium value

Figure 3.49: Analog test with the variable resistors at highest value

Description Low value Serial Mid value Serial Max value Serial
Battery Voltage 0V 0 8.1V 536 15.5V 1023
Air/Fuel ratio (E85) 5.0AFR 0 10.2AFR 530 15.1AFR 1023
IAT 150°C 0 46°C 541 0°C 1023
Coolant temp 150°C 0 49°C 509 0°C 1023
TPS 0% 0 52% 541 100% 1023
MAP temp 0kPa 0 67kPa 575 119kPa 1023

Table 3.6: Results of the analog testing


58 CHAPTER 3. METHODS

3.2.9 Firmware Problems

Frequently occurring problems of the programming was the overflow and rounding of integer
variables. With an 8-bit integer, the maximum number for the variable is 255. If an 8-bit
integer with a value of 255 is added with 1, the variable would overflow and become 0. The
reason being wrong calculations in other variables that sum up to be the resulting overflowing
variable. The rounding of integer happens when, for example, dividing 5 by 2. 5/2 equals 2.5
but is floored by the program down to 2 since the programming language does not recognize
the decimal number and therefore disregards it. This occurred frequently and was fixed with
either multiplying or detracting from an involving factor and then multiplying od dividing it by
the same amount when the resulting variable had finished its calculating process. The cause of
this can be imprecise results.

3.2.9.1 NVIC

The following problem is one of few fundamental errors that occurred during the programming
phase. The chapter shows the process which was used to debug such problems.

The NVIC (Nested Vector Interrupt Controller) is used to prioritize the interrupt routines. If
an interrupt occurs while another interrupt routine is performing, the pending interrupt routine
is either performed right away or when the current interrupt routine has finished depending on
the priority setting of the pending interrupt. If the pending interrupt has higher priority than the
performing interrupt routine, it immediately starts running and goes back to the current inter-
rupt when it has finished. In short terms, the NVIC ensures that when an interrupt occurs, it is
performed, whether it be right away or when a current interrupt has finished.

A problem arose when enabling the UART in the NVIC. The problem is that when writing
the UART designated bit in the ISER[0] (Interrupt Set-Enable Registers), the microcontroller
freezes. The UART interrupt is useful to the project because of interruptions and the time con-
suming process of communicating to the user interface for tuning and logging purposes. This
communication can interrupt important calculations that are required for accurate timing of out-
put signals.

The ISER[0] and ISER[1] enables interrupts, the SETENA (Interrupt set-enable bits) bit value
determines which register to write in. 0-31 SETENA bits are written in the ISER[0] register and
32-63 SETENA bits are written in the ISER[1] register. The UART has a SETENA bit value of
8 and is therefore the 9th bit the ISER[0] register. [4]

The program first initiates the UART by writing in the appropriate registers. Then the program
calls on the function that initializes the interrupt and interrupts variables, inside this function
the NVIC is set for the UART. The debug process was to comment all unrelated function in the
"main.c" file and write out to the serial port a letter after each action. The code can be seen
in figure 3.50 where "irqn" is the SETENA bit value and "priority" is the priority for the set
interrupt. The results from running the code can be seen in figure 3.51.
3.2. FIRMWARE 59

Figure 3.50: Code for tracing the NVIC problem

Figure 3.51: Serial monitor of tracing the NVIC problem

From the results in figure 3.51, it can be seen that the program does not print out to the serial
port after enabling the interrupt for UART. The microcontroller also froze all other operations.

The problem was inspected even further by looking into what the "NVIC_EnableIRQ(irqn)"
function does. The function is found in the "core_cm3.h" header file included in the Atmel
Studio Framework. What it does, is write the SETENA bit in the ISER register.

Figure 3.52: Operation in the "NVIC EnableIRQ()" function regarding NVIC problem
60 CHAPTER 3. METHODS

The next step taken was to put the initiation function for the UART interrupt last of the initiation
functions and print out the ISER[0] register every time the function was called upon. See figure
3.53 for the code and figure 3.54 for the output on the serial monitor.

Figure 3.53: Code printing out ISER[0] register regarding NVIC problem

Figure 3.54: Serial monitor of ISER[0] register regarding NVIC problem

In figure 3.54, the SETENA is printed out first, then the ISER[0] value in decimal format is
printed out. In table 3.7, these numbers are deicected and explained.
3.2. FIRMWARE 61

SETENA bit value IRQn description ISER[]


37 ADC Controller (ADC) ISER[1]
35 Timer Counter 8 (TC8) ISER[1]
27 Timer Counter 0 (TC0) ISER[0]
28 Timer Counter 1 (TC1) ISER[0]
29 Timer Counter 2 (TC2) ISER[0]
30 Timer Counter 3 (TC3) ISER[0]
12 Parallel I/O Controller B (PIOB) ISER[0]
11 Parallel I/O Controller A, (PIOA) ISER[0]

Table 3.7: Table of SETENA bits in the ISER[] register. [4]

ISER[0] decimal value ISER[0] binary value


0 0000 0000 0000 0000 0000 0000 0000 0000
0 0000 0000 0000 0000 0000 0000 0000 0000
134217728 0000 1000 0000 0000 0000 0000 0000 0000
402653184 0001 1000 0000 0000 0000 0000 0000 0000
939524096 0011 1000 0000 0000 0000 0000 0000 0000
2013265920 0111 1000 0000 0000 0000 0000 0000 0000
2013270016 0111 1000 0000 0000 0001 0000 0000 0000
2013272064 0111 1000 0000 0000 0001 1000 0000 0000

Table 3.8: Table of decimal and binary value of ISER[] register

The first two results in table 3.7 and 3.8 can be disregarded since they concern the ISER[1]
register and not the ISER[0] register which is being inspected. When analyzing the results in
3.8 it can be seen that the program successfully writes in the ISER[0] register and writes out the
SETENA bit and the ISER[0] value to the serial port until the function tries to enable the inter-
rupt for the UART. As seen in 3.52, the "NVIC_EnableIRQ(irqn)" function only writes a
numeric value in the ISER[] register and if the function is able to write other numeric values in
the register, then the fault origin is somewhere else. There is the possibility that the fault is the
result of mechanical error, this was also excluded by uploading the program to a new micro-
controller which gave out the same error when executing the program. The fault must then be
somewhere else in the code.

Upon further inspection of the "uart_init(void)" and


"uart_tx_interrupt_init(void)" functions in the "uart.c" file, two faults were
noticed. In the "uart_init(void)", when resetting the interrupt enable register, instead if
disabling the interrupt enable register by filling the interrupt disable register
(UART->UART_IDR = 0xFFFF;), the interrupt enable register was filled resulting in the
activation of all actions in the interrupt enable register (UART->UART_IER = 0xFFFF;).
So to fix the error, the line was changed from "UART->UART_IER = 0xFFFF;" to
"UART->UART_IDR = 0xFFFF;".
62 CHAPTER 3. METHODS

The second error appeared in the "for loop" for initializing the transmit buffer character array.
As seen in figure 3.55, the fault occurs when initializing the integer "i". This fault resulted
in the program being stuck in an infinite loop simulating a freeze in the microcontroller. For
reference, figure 3.56 is the correct version of the "for loop". With the errors fixed, the program

Figure 3.55: The incorrect version of the "for loop"

Figure 3.56: The correct version of the "for loop"

was checked by first, printing out the ISER[0] register after initialization of the UART interrupt.
Second, the UART interrupt printing was checked by printing out the string "ISER[0] = " to the
register. Third, the ISER[0] register was printed out in the main "while loop" using an external
debugging button, which calls functions once every time the button is pressed. The code can be
seen in figure 3.57 and the results in figure 3.58.

Figure 3.57: Test code to test the ISER[0] register


3.2. FIRMWARE 63

Figure 3.58: Results of the test code in figure 3.57

The decimal value of 2013272320 converted to binary format is:


0111 1000 0000 0000 0001 1001 0000 0000
Showing that the UART SETENA bit (9th bit) is set as 1 indicating that the UART interrupt is
enabled.
64
65

Chapter 4

Results & Discussion

The main objective of this project was to cut down costs of an ECU bought by the Formula
Student team of Reykjavík University by designing a dedicated ECU for the specific engine
used by the team. To design the ECU, certain design goals were proposed in chapter 1.2. Those
goals are:

• Write a program that contains all necessary algorithms to make an engine run.

• Accuracy of 0.1ms on injector and ignition pulsewidth.

• Accuracy of 0.1° on timing calculations for injector and ignition outputs.

• Design a PCB capable of receiving and produce the relevant signals with minimum cur-
rent consumption of 1A in a steady state operation.

• Maintain a budget of 100 dollars per unit produced.


66 CHAPTER 4. RESULTS & DISCUSSION

4.1 PCB Design

The PCB design process was performed in Altium and the schematics were sent off to seeed-
Studio for production. The design is a 4-layer 107mm x 88mm with a green finish. The PCB
arrived without components which were soldered on by hand. comparison of the raw PCB and
assembled PCB can be seen in figures 4.1 and 4.2.

Figure 4.1: Top side of PCB Figure 4.2: Bottom side of PCB
4.2. COST 67

4.2 Cost

Beginning with the cost of the design. The goal was to maintain the budget of 100 dollars per
unit produced. To cut down costs, components were purchased from China. Some components
were in stock and did not need to be purchased, however, the prices of these components were
found by looking up prices from China. The total cost of the ECU can be seen in table 4.1.

Component Comp./PCB Price/PCB


PCB Production 1 10.87$
ATP connector 24-pin 1 0.88$
MAX9926 VR interface 1 3.12$
BSS138 transistor 10 0.12$
Arduino Due Core 1 19.99$
LED 3mm red 10 0.10$
HER108 Diode 4 0.10$
IRF3205 MOSFET 4 0.78$
AT24C256C EEPROM 1 0.27$
IRGB14C40L 4 3.20$
Zener Diode 3V6 7 1.14$
MPX115AP MAP sensor 1 24.56$
LM1084IT-5.0 Regulator 2 0.63$
LM1084IT-3.3 Regulator 1 0.32$
SMD Resistor/Capacitors 59 0.37$
WIMA Capacitor 1 In stock
Resistor 1 In stock
Total 66.44$

Table 4.1: The cost of the ECU

The total cost of one ECU produced is 66.44 dollars, making it 33.56 dollars off the target
budget. Some room for development is available, spending more on additional components for
more quality signal receivance or higher stage of circuit protection. For reference, the VEMS
V3 ECU costs 591.22 dollars and uppwards depending on the auxillary devices added to the
ECU and adding the shipping cost. Another example is a local ECU developer has an ECU
is available for 600 dollars. For the school to construct an ECU for them selves is therefore
significantly cheaper then byuing.
68 CHAPTER 4. RESULTS & DISCUSSION

4.3 Current Consumption

The current consumption is allways a factor when it comes to engine power. If the electrical
components of a vehicle consume high current, the power produced by the engine will go into
making the electrical power for the electrical components of the vehicle. The goal was to keep
the current consumption under 1A. The current was measured from the 12V power supply to
the ECU with the ECU in a steady state. In figure 4.3, the current is shown as 129.3mA, making
the specific goal a success.

Figure 4.3: Measurments of the ECU current consumption

4.4 Timing & Pulsewidth Accuracy

4.4.1 Ignition Output Testing

The ignition testing is performed in two ways. The ignition timing and the ignition pulsewidth
(Dwell) is measured with an oscilloscope. Both measurements are performed with the values
from the tuning interface as reference values, explained in chapter 3.2.7. The dwell is measured
in ms and the timing is measured in degree BTDC.

The measurements are taken with test circuits emulating the signals inputs from the sensors
and another microcontroller emulating the crankshaft and camshaft signal. The parameters in-
terpreted by the ECU are shown in figure 4.4. To note, in figures 4.5, 4.6 and 4.7 the pink line
indicates the crankshaft signal and the yellow line indicates the output for ignition 1.
4.4. TIMING & PULSEWIDTH ACCURACY 69

Figure 4.4: Signal parameters for reference of the accuracy testing

The parameter to notice in figure 4.4 for the ignition dwell time, is the value for "IGN ". The
value in this case is 23 and as explained in chapter 3.2.7, the value 23 stands for 2.3ms. For the
ignition degree the value of "DEGT ". In this case the value is 137 indicating the target ignition
to be at 13.7° BTDC.

Figure 4.5: Measurment of ignition pulse durration

In figure 4.5, the pulse duration can be read as 2.33ms. This falls under the requirements of
0.1ms resolution. The signal showed some inconsistency in measurments, but the cause is
presumed to be in the inconsistency in the inputs signal emulating the crankshaft signal.
70 CHAPTER 4. RESULTS & DISCUSSION

Figure 4.6: Measurment of the time between teeth regarding ignition measurments

Figure 4.7: Measurment of the time between ignition event and TDC regarding ignition mea-
surments

In figure 4.6, the time between the tooth before TDC on cylinder 1 to the TDC is measured as
1.980ms. In figure 4.7, the time between ignition spark and the TDC of cylinder 1 is measured
as 1.810ms. Bearing in mind that the angle between 2 teeth is 15° and the target ignition angle
is 13.7°, the measured ignition degree angle is (15°/1.980ms) · 1.810ms = 13.71°. To verify
the target angle, the target time of figure 4.7 is calculated as (1.980ms/15°) · 13.7° = 1.808ms
making the accuracy meet the target accuracy of 0.1°, set for this project.
4.5. ECU TESTING 71

4.4.2 Injector Output Testing


The injector pulsewidth is measured using the parametric value of "INJ" in 4.4. As described
in chapter 3.2.7, the "INJ" value of 67 is 6.7ms. The output signal for injector 1 was measured,
see figure 4.8 where the pink line is the crankshaft signal and the yellow line is the output for
injector 1.

Figure 4.8: Measurment of the injector pulsewidth

4.5 ECU testing


Unfortunately, a complete testing of the ECU did not take place. The reason being a loss of
time. However, the ECU was roughly tested without the correct input signal from any analog
sensor. This meant that the MAP sensor showed maximum atmospheric pressure instead of the
vacuum formed in the cylinders along with other false analog readings. This caused the ECU to
overcompensate the fuel delivered, making for too rich AFR mixture. The test concluded when
the engine started to show audible signs of ignition in the cylinders to prevent possible damage.
72
73

Chapter 5

Conclusion

The final product ended up being unsuccessful. All the design goals were met and reduction in
the cost was significant, but a complete testing of the final product was not performed due to
loss of time.

The whole program for the ECU and the tuning interface along with the schematics of the
PCB can be acquired on GitHub through the link below:

https://github.com/rikardur13/Lokaverkefni

5.1 Future Work


The goal of the thesis was to get a working ECU which allows for further improvements. The
design is a prototype design and requires more development for increased durability and accu-
racy from both the programming methods and hardware design.

The modern ECUs available are a more complete products, the reason being the improvements
for each design. There is always room for improvements and this project is no exception.

5.1.1 Hardware
For the hardware of this project, the microcontroller is the primary subject to be researched. Mi-
crocontrollers dedicated to the use of automotive design exist. The controllers are more durable
to harsh environment and the internal circuitry are more relevant to designing an ECU.

The ignition and injector drivers have room for development. The possibility of using IC circuits
that are dedicated for the single purpose of controlling ignition and injector coils. Research of
the various ignition and injector drivers available is a priority matter for future designs.

The crankshaft sensor and the camshaft sensor needs to be researched further. The MAX9926
VR interface offers the possibility of detecting a digital signal. This could be useful since only
one interface could then be used for both the crankshaft and the camshaft sensor, decreasing the
complexity in design and could also decrease the components used.
74 CHAPTER 5. CONCLUSION

5.1.2 Firmware
The firmware of the ECU uses various methods and algorithms to filter input signals and cal-
culate output signals. The calculations of the output signals is a delicate process and require
much knowledge of timer/counters, and awareness of overflowing integer in calculations. The
methods used to calculate the timing of injector and ignition output signals need attention for
further development.

The communication between the microcontroller and the EEPROM can be optimized even fur-
ther. The communication does not include a checksum making the communication sensetive to
false readings. This can be implemented in future designs.
75

Bibliography

[1] F. Landhäußer, M. Heinzelmann, A. Michalske, M. L. Susaeta, M. Grosser, J. Feger,


L.-M. Fink, W. Gerwing, K. Grabmaier, B. Illg, J. Kurz, R. Mayer, D. Ottenbacher, A.
Werner, J. Wiesner, and M. Walther, “Electronic control unit (ECU)”, in Diesel Engine
Management, ser. Bosch Professional Automotive Information, DOI: 10.1007/978-3-
658-03981-3_21, Springer Vieweg, Wiesbaden, 2014, pp. 272–277, ISBN: 978-3-658-
03980-6 978-3-658-03981-3. [Online]. Available: https : / / link . springer .
com/chapter/10.1007/978-3-658-03981-3_21 (visited on 09/20/2017).
[2] Y. A. Çengel and M. A. Boles, Thermodynamics: an engineering approach, 7th ed. in SI
units. Singapore: McGraw-Hill, 2011.
[3] M. J. Moran, H. N. Shapiro, D. D. Boettner, and M. B. Bailey, Principles of engineering
thermodynamics, 7th ed. Singapore: Wiley, 2012.
[4] L.-p. Modes, “ Power-on-Reset (POR), Brown-out Detector (BOD) and Watchdog for
safe reset Quartz or ceramic resonator oscillators: 3 to 20 MHz main and optional low
power 32.768 kHz for RTC or device clock High precision 8/12 MHz factory trimmed
internal RC oscillator with 4 MHz default frequency for fast device startup”, [Online].
Available: http : / / www . atmel . com / Images / Atmel - 11057 - 32 - bit -
Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf.
[5] A. S. Sedra and K. C. Smith, Microelectronic Circuits Revised Edition, 5th. New York,
NY, USA: Oxford University Press, Inc., 2007, ISBN: 0-19-533883-9 978-0-19-533883-
6. (visited on 03/12/2017).
[6] Vishay. (2017). Small Signal Zener Diodes, [Online]. Available: https://www.vis
hay.com/docs/84122/tzm.pdf (visited on 12/01/2017).
[7] (Aug. 13, 2013). Zener Diode as Voltage Regulator Tutorial, Basic Electronics Tutorials,
[Online]. Available: http : / / www . electronics - tutorials . ws / diode /
diode_7.html (visited on 11/16/2017).
[8] (Aug. 14, 2013). Low Pass Filter - Passive RC Filter Tutorial, Basic Electronics Tutorials,
[Online]. Available: http://www.electronics- tutorials.ws/filter/
filter_2.html (visited on 11/16/2017).
[9] Yamaha Motor Corporation. (2005). Yamaha Owner’s Manuals, [Online]. Available: ht
tp://www.r6messagenet.com/forums/pdf/2007_R6_Service.pdf
(visited on 12/01/2017).
[10] Inhaos. (2016). DUE CORE SAM3X8E 32-bit ARM Cortex-M3 Module, [Online]. Avail-
able: http://www.inhaos.com/product_info.php?products_id=164
(visited on 12/01/2017).
[11] ——, (2016). Mega2560-CORE DataSheet, [Online]. Available: http://www.inh
aos . com / uploadfile / otherpic / DS - Mega2560 - CORE - V01 - EN . pdf
(visited on 12/01/2017).
76 BIBLIOGRAPHY

[12] Atmel Corporation. (2014). Atmel ATmega640/V-1280/V-1281/V-2560/V-2561/V, [On-


line]. Available: http : / / www . atmel . com / Images / Atmel - 2549 - 8 -
bit - AVR - Microcontroller - ATmega640 - 1280 - 1281 - 2560 - 2561 _
datasheet.pdf (visited on 03/12/2017).
[13] ——, (2015). AT24C256C - Memory, [Online]. Available: http : / / www . atmel .
com/images/atmel-8568-seeprom-at24c256c-datasheet.pdf (visited
on 10/31/2017).
[14] Texas Instruments. (1999). LM1084 5-A Low Dropout Positive Regulators, [Online].
Available: http://www.ti.com/lit/ds/symlink/lm1084.pdf (visited on
12/01/2017).
[15] ——, (2000). LM2940x 1-A Low Dropout Regulator, [Online]. Available: http://
www.ti.com/lit/ds/symlink/lm2940c.pdf (visited on 12/01/2017).
[16] Maxim Integrated Products. (2012). Variable Reluctance Sensor Interfaces with Differ-
ential Input and Adaptive Peak Threshold, [Online]. Available: https://datashe
ets.maximintegrated.com/en/ds/MAX9924- MAX9927.pdf (visited on
03/12/2017).
[17] Texas Instruments. (2017). LM1815 Adaptive Variable Reluctance Sensor Amplifier,
[Online]. Available: http://www.ti.com/lit/ds/symlink/lm1815.pdf
(visited on 03/12/2017).
[18] (2011). MicroSquirt® Introduction, [Online]. Available: http://www.useasydocs
.com/theory/vr.htm (visited on 11/28/2017).
[19] Woodward. (2014). Variable Reluctance (VR) Signal Behavior, [Online]. Available: ht
tp://mcs.woodward.com/content/motohawk/Documentation/Moto
Hawk2015bSP0/HTML/MotoHawk_topics/VRInterfacing.html (visited
on 09/28/2017).
[20] Fairchild Semiconductor. (2005). BSS138 N-Channel Logic Level Enhancement Mode
Field Effect Transistor, [Online]. Available: http://www.mouser.com/ds/2/
149/BSS138-1006682.pdf (visited on 12/01/2017).
[21] SHARP Corporation. (2003). DIP 4pin General Purpose Photocoupler, [Online]. Avail-
able: http : / / www . farnell . com / datasheets / 73758 . pdf (visited on
03/12/2017).
[22] F. Semiconductor, “Integrated silicon pressure sensor on-chip signal conditioned, tem-
perature compensated and calibrated”, Technical Data, pp. 1–2, 2009.
[23] M. ROLA, “Integrated Silicon Pressure Sensor On-Chip Signal Conditioned, Tempera-
ture Compensated and Calibrated”, 2002.
[24] J. B. Heywood, Internal Combustion Engine Fundamentals. New York: McGraw-Hill,
1988.
[25] Engine Basics. (2010). Air Fuel A/F Ratio Basics | Wideband vs Narrow O2 sensor,
[Online]. Available: http://www.enginebasics.com/EFI%20Tuning/AF%
20Ratio%20Basics.html (visited on 11/14/2017).
[26] Innovate Motorsports. (2017). LC-2 Digital Air/Fuel Ratio (Lambda) Sensor Controller
Manual, [Online]. Available: http://www.innovatemotorsports.com/supp
ort/manual/LC-2_Manual.pdf (visited on 03/12/2017).
BIBLIOGRAPHY 77

[27] Delphi. (2005). COOLANT TEMPERATURE SENSOR, [Online]. Available: http :


//pe-ltd.com/assets/coolant_temp.pdf (visited on 03/12/2017).
[28] “Coil on plug signal detection”, US6396277 B1, U.S. Classification 324/402, 324/686,
324/388, 324/393, 324/688; International Classification F02P17/08, F02P3/02, F02P17/12,
F02P17/00; Cooperative Classification F02P17/12, F02P2017/003, F02P2017/125, F02P3/02;
European Classification F02P17/12, F02P3/02, May 28, 2002. [Online]. Available: htt
p://www.google.com/patents/US6396277.
[29] R. K. Jurgen, Ed., Automotive electronics handbook, New York: McGraw-Hill, 1995,
1 p., ISBN: 978-0-07-033189-1.
[30] Sport Devices. (2000). CDI and TCI ignitions, [Online]. Available: http://www.spo
rtdevices.com/rpm_readings/CDI_and_TCI.htm (visited on 04/27/2016).
[31] International Rectifier. (2000). IGBT with on-chip Gate-Emitter and Gate-Collector clamps,
[Online]. Available: https://www.hobbielektronika.hu/forum/getfile
.php?id=297878 (visited on 12/01/2017).
[32] Texas Instruments. (2013). LM1949 Injector Drive Controller, [Online]. Available: htt
p://www.ti.com/lit/ds/symlink/lm1949.pdf (visited on 12/01/2017).
[33] B. Bowling and A. Grippo. (2008). MegaSquirt VE Table Determination using Oxygen
Sensor Feedback, [Online]. Available: http://megasquirt.free.fr/sources
/MS/manual/v22manual/ve_tuner.pdf.
[34] ——, (2008). MegaSquirt-II Missing Tooth Trigger Wheel Decoder, [Online]. Available:
http://www.megamanual.com/ms2/wheel.htm (visited on 09/28/2017).
[35] ——, (2007). Injectors and Fuel System, [Online]. Available: http://www.megama
nual.com/v22manual/minj.htm (visited on 03/12/2017).
[36] ——, (2007). How MegaSquirt® EFI Controllers Work, [Online]. Available: http :
//www.megamanual.com/v22manual/mfuel.htm (visited on 03/12/2017).
78
School of Science and Engineering
Reykjavík University
Menntavegur 1
101 Reykjavík, Iceland
Tel. +354 599 6200
Fax +354 599 6201
www.ru.is

You might also like