MODELING A SNOWMOBILE ENGINE CONTROL UNIT IN SIMULINK

advertisement
MODELING A SNOWMOBILE ENGINE CONTROL UNIT IN SIMULINK
by
Benjamin Lakin
A Thesis Submitted in Partial Fulfillment
of the Requirements for a Degree with Honors
(Mechanical Engineering)
The Honors College
University of Maine
May 2007
Advisory Committee:
Senthil Vel, Associate Professor of Mechanical Engineering, Advisor
Michael Peterson, Professor of Mechanical Engineering
Michael Boyle, Associate Professor of Mechanical Engineering
David Hiebeler, Assistant Professor of Mathematics
Kathleen Ellis, Adjunct Assistant Professor in Honors (English)
ACKNOWLEDGMENTS
There are a few people who truly deserve to be acknowledged for their effort in
the support of my honors thesis. First, I would like to thank the work of my Advisory
Committee throughout the process, including the reading of this thesis and making many
important recommendations. I would especially like to thank Professor Peterson and
Professor Vel. Professor Peterson was very helpful in creating this new style honors
thesis and defining its objectives. His experience and insight with regards to the Clean
Snowmobile Project was also very helpful. My advisor, Professor Vel, also deserves
great thanks. He was very supportive and insightful throughout this entire thesis
experience. His occasional assistance with the use of Simulink saved me a great deal of
frustration and time, and his consistently encouraging attitude helped foster my
motivation.
I would also like to thank the members of my capstone team. Without the
assistance and cooperation of John Armitage, Bryant Dear, Erik Lenz, Chang Lin and
Phil Mitchell, I would not have been able to complete this thesis. They helped me obtain
the experimental data needed to validate my Simulink model, and their expertise with the
snowmobile helped me understand the benefits of this computer model.
ii
TABLE OF CONTENTS
ACKNOWLEDGEMENTS.................................................................................................ii
LIST OF TABLES..............................................................................................................vi
LIST OF FIGURES...........................................................................................................vii
Chapter
1. INTRODUCTION...........................................................................................................1
1.1. Unique Style of this Thesis...............................................................................1
1.2. Description of Capstone Project.......................................................................1
1.3. Objectives of this Thesis………………….......................................................2
1.4. Outline of the Thesis………………….............................................................2
2. BACKGROUND AND HISTORY OF ENGINE CONTROL UNITS……...................3
2.1. Introduction……………………………………………………………….......3
2.2. What is an Engine Control Unit?......................................................................3
2.2.1. Description and Function…………………………………………...3
2.2.2. Components…………………………………………………….......4
2.3.3. Inputs and Outputs………………………………………………….6
2.3. History of Engine Control Units……………………………………………...6
2.3.1. Before Engine Control Units……………………………………….6
2.3.2. The First Engine Control Unit……………………………………...9
2.3.3. Subsequent ECUs up until 1997…………………………………..11
2.3.4. Today’s ECUs…………………………………………………......14
3. SIMULINK MODEL OF THE ENGINE CONTROL UNIT…………………………17
iii
3.1. Introduction………………………………………………………………….17
3.2. Why the Computer Model Was Created…………………………………….17
3.3. Description of the Computer Model………………………………………...18
3.3.1. Software…………………………………………………………...18
3.3.2. Fundamental Equations……………………………………………20
3.3.3. Computer Model Inputs and Outputs……………………………...22
3.3.4. Flow Chart of the Program………………………………………..23
3.3.5. Method for Using the Model in General…………………………..28
3.4. Procedure Used for Generating Comparison Results……………………….30
4. ENGINE CONTROL UNIT EXPERIMENTAL SETUP…………………………….31
4.1. Introduction………………………………………………………………….31
4.2. Why the Experimental Data Was Needed…………………………………..31
4.3. Components and Software of the Experimental Setup……………………...32
4.4. Experimental Testing Setup and Procedure…………………………………35
4.4.1. Setup………………………………………………………………35
4.4.2. Procedure………………………………………………………….36
4.4.3. Variables Tested…………………………………………………...37
5. COMPARISON AND SIMULATION RESULTS…………………………………...38
5.1. Introduction………………………………………………………………….38
5.2. Comparison Results…………………………………………………………39
5.2.1. Introduction to Graphical Comparison Results……………………39
5.2.2. Graphical Comparison Results with Brief Discussions…………...40
5.2.3. Summary of Results……………………………………………….53
iv
5.2.4. Explanation of Percent Differences……………………………….53
5.2.5. Effect of Pulse Width Percent Differences on Air-Fuel Ratio…….54
5.3. Sample Simulation Results………………………………………………….55
5.3.1. Introduction to Sample Simulation Results Section………………55
5.3.2. Sample Real-Time Graphical Results with Discussion…………...56
6. CONCLUSIONS AND FUTURE WORK……………………………………………63
6.1. Introduction………………………………………………………………….63
6.2. Success of the Simulink Model……………………………………………...63
6.3. Benefits of the Model………………………………………………………..64
6.4. Future Work…………………………………………………………………65
REFERENCES…………………………………………………………………………..68
APPENDICES…………………………………………………………………………...69
Appendix A. INPUT PARAMETER KEY………………………………………70
Appendix B. MEGA TUNE SCREEN SHOTS………………………………….74
Appendix C. INSTRUCTIONS FOR USING THE “SIMULINK MODEL OF
MEGASQUIRT II V3”…………………………………………………………..79
Appendix D. EQUATIONS BEHIND THE SIMULINK MODEL OF THE
MEGASQUIRT II V3 ECU……………………………………………………...82
Appendix E. AFR UNCERTAINTY CALCULATION…………………………90
Appendix F. ORIGINAL TABULATED COMPARISON DATA……………...92
Appendix G. PRINTOUTS OF MAJOR SECTIONS OF COMPUTER
MODEL………………………………………………………………………….97
BIOGRAPHY OF THE AUTHOR……………………………………………………..104
v
LIST OF TABLES
Table A.1
Key for Simulink Model Block Inputs…………………………………...71
Table A.2
Key for Simulink Model Table Inputs…………………………………...73
Table F.1
Engine Variable Comparison Data………………………………………92
Table F.2
Engine and Tuning Constant Comparison Data………………………….95
vi
LIST OF FIGURES
Figure 3.1
Sample Simulink Block Model…………………………………………..19
Figure 3.2
Simulink Model Flow Chart……………………………………………..24
Figure 3.3
Image of Simulink Model Main Screen...………………………………..29
Figure 4.1
External Photo of MegaSquirt-II V3……………………………………..32
Figure 4.2
Internal Photo of MegaSquirt-II V3……………………………………...32
Figure 4.3
Photo of Stimulator V2.1………………………………………………...33
Figure 4.4
Photo of Power Supply Hooked Up to MegaSquirt with Stimulator…….33
Figure 4.5
Photo of MegaTune’s Main Screen……………………………………...34
Figure 4.6:
Photo of MegaTune’s Real Time Display Screen………………………..34
Figure 4.7
Photo of Experimental Setup…………………………………………….36
Figure 5.1
Comparison Results Graph for Pulse Width vs. Engine Speed………….40
Figure 5.2
Comparison Results Graph for Pulse Width vs. Coolant Temperature….41
Figure 5.3
Comparison Results Graph for Pulse Width vs. Throttle Position Sensor
Voltage Percentage……..………………………………………………..42
Figure 5.4
Comparison Results Graph for Pulse Width vs. Intake Air
Temperature...............................................................................................43
Figure 5.5
Comparison Results Graph for Pulse Width vs. Oxygen Sensor Output...44
Figure 5.6
Comparison Results Graph for Pulse Width vs. Manifold Absolute
Pressure......................................................................................................45
Figure 5.7
Comparison Results Graph for Pulse Width vs. Supply Battery
Voltage.......................................................................................................46
vii
Figure 5.8
Comparison Results Graph for Pulse Width vs. Battery Correction
Factor………………………………………………………………...…..47
Figure 5.9
Comparison Results Graph for Pulse Width vs. Injector Open Time……48
Figure 5.10
Comparison Results Graph for Pulse Width vs. Injector Staging………..49
Figure 5.11
Comparison Results Graph for Pulse Width vs. Number of Cylinders….50
Figure 5.12
Comparison Results Graph for Pulse Width vs. Engine Size……………51
Figure 5.13
Comparison Results Graph for Pulse Width vs. Injector Flow Rate…….52
Figure 5.14
Simulated Results Graph for an Engine Going Through the Initial WarmUp Period………………………………………………………..……….56
Figure 5.15
Simulated Results Graph for an Engine Responding to Oxygen Sensor
Readings………………………………………………………………….57
Figure 5.16
Simulated Results Graph for an Engine Responding to Acceleration and
Deceleration……………………………………………………………...59
Figure 5.17
Simulated Results Graph for an Engine Responding to Cranking,
Acceleration and Increasing Engine Speed…………………………...….60
Figure 5.18
Simulated Results Graph for an Engine Responding to Cranking, Warm
Up, Acceleration and Increasing Engine Speed……………………….…62
Figure B.1
General Settings Window in MegaTune………………………………....74
Figure B.2
Sensor Calibration Window in MegaTune………………………………75
Figure B.3
Injector Characteristics Window in MegaTune………………………….75
Figure B.4
Injection Control Window in MegaTune………………………………...76
Figure B.5
Warm Up Wizard Window in MegaTune………………………………..77
Figure B.6
EGO (Oxygen Sensor) Control Window in MegaTune………………….77
viii
Figure B.7
Acceleration Wizard Window in MegaTune…………………………….78
Figure B.8
Real-Time Output Display Window in MegaTune………………………78
Figure G.1
Print Out of the Main Screen of the Simulink Model……………………97
Figure G.2
Print Out of the Cranking Subroutine of the Simulink Model…………...98
Figure G.3
Print Out of the AFR Subroutine of the Simulink Model………………..98
Figure G.4
Print Out of the Not Cranking Subroutine of the Simulink Model………99
Figure G.5
Print Out of the Require Fuel Subroutine of the Simulink Model……...100
Figure G.6
Print Out from the Oxygen Sensor Subroutine of the Simulink Model...101
Figure G.7
Print Out from the Acceleration Subroutine of the Simulink Model…...102
Figure G.8
Print Out of the Enrichment Subroutine of the Simulink Model……….103
ix
Chapter 1
INTRODUCTION
This chapter will introduce this thesis by covering four major topics. It will
explain the unique style of this thesis, introduce the capstone project linked to the thesis,
present the thesis objectives and briefly outline each of the chapters found in this report.
1.1. Unique Style of this Thesis
Unlike traditional honors theses, my thesis is in collaboration with a capstone
team. Once my team and I selected a capstone project, I worked with the Capstone
Coordinator (Professor Peterson) to define which portions of the project would be my
responsibility. I was expected to work on my portion of the project independently and
according to the current thesis model. However, my team and I had to remain connected
to complete the entire project. Therefore, I shared useful results with my team, and my
team provided all other necessary information or results for my portion of the project. I
was responsible for my portion of the capstone project, and the remainder of my team
was responsible for the rest of the project.
1.2. Description of Capstone Project
Following my interest in snowmobiles and a clean environment, I decided to work
on one of the Clean Snowmobile Capstone Projects. The objective of this capstone
project was to select, model, optimize and install a complete, piggyback engine control
unit (ECU) for a 2007 Yamaha Phazer Snowmobile. This ECU would be used to control
1
the fuel system on the snowmobile, allowing the machine to operate more efficiently and
cleanly.
1.3. Objectives of this Thesis
For the capstone project described above, I was responsible for the following objectives:

Research the background and history of electronic engine controls

Work with my capstone team to assemble an experimental testing board for
testing the newly purchased engine control unit (ECU)

Create a Simulink model of the ECU

Work with my capstone team to establish the validity of the model by comparing
its theoretical results to the experimental results obtained using the test board

Prepare the model for future simulation work

Determine how the model could be expanded for further application to the Clean
Snowmobile Project
1.4. Outline of the Thesis
Some background information and a brief history of engine control units are
presented in Chapter 2. In Chapter 3, the Simulink computer model will be discussed,
including why it was created, a description of the model and instructions for using the
model. Chapter 4 will examine the experimental setup and procedure used to generate
the ECU comparison results. In Chapter 5, the comparison results and some sample
simulation results will be presented and discussed. Lastly, Chapter 6 will discuss the
success of the model, its benefits and future work that should be considered.
2
Chapter 2
BACKGROUND AND HISTORY OF ENGINE
CONTROL UNITS
2.1. Introduction
This chapter presents some basic background information and history on engine
control units (ECUs). This information is not intended to be all inclusive, and the reader
should consult the references indicated at the end of this report to fully understand the
technical details of the operation of ECUs. Also, to fully understand the applications of
ECUs, it would be helpful if the reader understood the basic components of an internal
combustion engine.
2.2. What is an Engine Control Unit?
2.2.1. Description and Function
An Engine Control Unit (ECU) is basically a miniature computer system designed
to control the operation of an engine. Engine control units (sometimes called Engine
Control Modules) are commonly installed on most recent automobiles and personal
transportation vehicles, including ATVs, watercraft and snowmobiles. They are often the
most powerful computer on vehicles, because they use “closed-loop control, a control
scheme that monitors outputs of a system to control the inputs to a system, [to] manage
the emissions and fuel economy of the engine (as well as a host of other parameters)”
(Nice, 2007). These computers gather data from dozens of different sensors on an engine
3
in an attempt to control primarily two inputs to the engine; how long to open the fuel
injectors (something called a pulse width) and the best spark timing. Engine control units
operate extremely quickly, performing millions of calculations each second in an effort to
provide low emissions and the best fuel mileage. Modern ECUs on automobiles can also
control power steering, cooling fans and automatic transmission shifting (more on this
later).
2.2.2. Components
Engine control units consist of several pieces of hardware and an on-board
software package or code. Some of the most common hardware components consist of a
processor, analog-to-digital converters, signal amplifiers, digital-to-analog converters,
signal conditioners and high speed communication channels. The code is stored in the
processor, which is where all the real-time calculations are completed during engine
operation. “A modern ECU might contain a 32-bit, 40-MHz processor” (Nice, 2007),
which is adequate to perform the relatively simple computations required for engine
control. The analog-to-digital and digital-to-analog converters are necessary for the
processor and the sensors to be able to communicate. The sensors on an engine are
typically analog transducers that measure an input quantity and generate a functionally
related analog output usually in the form of an electric signal. However, most ECUs only
accept digital signals. Therefore, a signal converter is necessary so that information can
be passed from a sensor to the processor and from the computer back to another
component. The signal amplifiers, sometimes referred to as high-level digital outputs,
increase a weak signal from the processor to an electrical voltage large enough to start or
stop engine components, such as cooling fans. “The tiny amount of power that the
4
processor can output energizes the transistor in the digital output, allowing it to supply a
much larger amount of power to the cooling fan relay, which in turn provides a still larger
amount of power to the cooling fan” (Nice, 2007). The coils used to charge the spark
plugs and the solenoids used to open the fuel injectors operate on the same principle. As
for the signal conditioners, these are necessary if the output signal from a sensor is
relatively weak. A weak signal increases the chance for inaccuracy. Therefore, these
devices scale up the signal, thus making it easier to detect changes in an output from a
sensor. Lastly, high speed channels are necessary for each of the components in the
processor to communicate quickly. The processor must be able to perform millions of
calculations each second, so each component on the processor board must be able to
communicate rapidly.
The other major component of ECUs is the on-board code. The code stored in the
processor is equally as important as the ECU components, because the code allows the
ECU to process the incoming signals and determine the output. If one compares the
entire ECU system to a human body, the sensors are like a person’s fingers, eyes, nose,
ears and mouth, and the on-board code is like a human’s brain. The sensors transmit
signals to the ECU like parts of the human body send signals to the brain. The code then
interprets these signals and determines what to output, analogous to how the brain
processes nerve signals and determines what a person’s reaction should be. The on-board
programs can be written in a number of languages, ranging from C to Visual Basic, but
the theory behind them is still relatively the same. Considering the fuel injection portion
of the code, most ECUs have code that accounts for an engine that is cranking or
warming up, atmospheric properties, exhaust gas emissions (indicates rich or lean
5
combustion), manifold air pressure, acceleration or deceleration and physical limits of the
injectors themselves. Different manufacturers modify their codes to emphasize
distinctive aspects of engine operation, but the basic algorithms of all ECU codes are
very similar. The different portions of the code used for this thesis will be examined in
detail in Chapter 3.
2.2.3. Inputs and Outputs
As mentioned earlier, an ECU reads several input signals and generates a series of
output signals. The lists below indicate typical sensor inputs and the ECU output for a
simple, fuel-injection ECU.
Inputs:
Engine Speed
Coolant Temperature
Throttle Position Sensor Voltage
Intake Air Temperature
Initial Barometer Reading
Oxygen Sensor Voltage
Manifold Air Pressure
Supply Battery Voltage
Outputs:
Injector Pulse Width
2.3. History of Engine Control Units
2.3.1. Before Engine Control Units
An engine control unit is a relatively new technology, and before they were
invented, automotive manufacturers used many different styles of fuel regulation.
Unfortunately, these various arrangements also had drawbacks. The most common type
of fuel management system before ECUs was a carburetor. “For nearly a hundred years,
engine [fuel] management was accomplished by carburetors” (Hartman, 2003). Many car
fanatics are very familiar with carburetor operation, because this was the most common
6
fuel management system on vehicles until the 1990s. “By the late 1970s, carburetors had
been engineered to a high state of refinement… however, there were inescapable
problems intrinsic to the concept of a self-regulating mechanical fuel-air mixing system”
(Hartman, 2003). Unfortunately, the limits of carburetors became painstakingly
noticeable when new power-enhancing technologies began to be installed on engines and
when environmental standards were increased. In the 1970s, hot rodders and engine
tuners began to experiment with turbochargers to boost horsepower. Unfortunately,
carburetors tended to perform poorly with turbocharged engines. With a carbureted,
turbocharged engine, “it was possible to make a lot of power, but there were virtually
always sacrifices of drivability, reliability, cold-running, and so forth” (Hartman, 2003).
As environmental standards increased, engine tuners and designers began to realize that
carburetors were not able to accommodate enough engine parameters to provide the
correct fuel-air mixture. Carburetors worked efficiently and effectively when an engine
was warm and operating under design conditions. However, vehicles cannot operate
under optimum conditions all the time. Engines go through warm-up, acceleration and
deceleration periods; are affected by changes in atmospheric conditions; and are subject
to mechanical wear. Carburetors simply could not respond to all the changes in an engine
that occur over time to produce the most efficient fuel-air mixture.
Due to a carburetor’s inability to meet environmental standards, automakers were
forced to deliver solutions to poor emissions in the 1960s and 1970s. “The Clean Air
Acts of 1966 and 1971 set increasingly strict state and federal standards for exhaust and
evaporative emissions” (Hartman, 2003). In an attempt to meet these standards, engine
designers tried a series of add-on emissions-control devices. These included “positive
7
crankcase ventilation (PCV), exhaust gas recirculation (EGR), air pumps, inlet air
heaters, vacuum retard distributor canisters, and carburetor modifications” (Hartman,
2003). These improvements helped some, but they were really only Band-Aids on a
major flesh wound. Eventually, the inherent setbacks of carburetors bled through and
resurfaced. These improved cars “ran cleaner, but horsepower was down and drivability
sometimes suffered” (Hartman, 2003). Unfortunately, the carburetor had reached its
limit. This mechanical fuel-air mixing system, even with add-on emission controls,
simply could not accommodate for enough engine parameters to accurately control the
required fuel-air ratio.
Learning from the limits of carburetors, some engine designers tried another fuel
management system called mechanical fuel injection. Mechanical fuel injection relied on
a series of linkages to open and close fuel ports at the correct time for each cylinder. This
system operated similar to the intake and exhaust valve arrangement on current engines.
Mechanical fuel injection was successful at being more encompassing than a carburetor.
It could respond to more of the engine parameters during operation, which was a step in
the right direction. Unfortunately, the downsides to this newer system soon began to
prevail. “The trouble was, mechanical injection relied on crude mechanical means for
mixture correction across the range of engine speeds, loading, and temperatures”
(Hartman, 2003). These mechanical systems were not only very expensive, but they
suffered from the same sorts of restraints that plagued carburetors. Mechanical systems
simply could not be cost-effectively made to be all encompassing. A reasonably priced
system could not accurately respond to increasing engine speed, changing temperature,
varying load, and mechanical wear all at the same time. Modern performance and
8
environmental standards demanded a system that could cost-effectively handle a host of
engine properties at the same time. Engine designers were going to have to think more
creatively.
2.3.2 The First Engine Control Unit
As mentioned above, environmental standards were calling for more efficient and
accurate engine management systems. As a result of these higher environmental
standards and the need for increased performance, engine designers were forced to use
new technology. They all sought a new solution to their problems. The solution,
surprisingly, was actually nothing new. To solve their problems, engine designers
actually had to apply new technology to a concept developed two decades earlier.
Instead of relying on mechanical systems that continued to fail, engineers began to use
electronic systems. The first electronic engine control unit was developed in two stages
and focused solely on fuel management.
The first phase of electronic fuel systems occurred in the 1950s. “The first
electronic fuel injection (EFI) was invented by Bendix in 1950s America… [and it] used
modern solenoid-type electronic injectors with an electronic control unit based on
vacuum-tube technology” (Hartman, 2003). Why did this fuel system not become
prominent sooner? Unfortunately, the Bendix Electrojector, as it was called, was
developed before the electronics industry was advanced enough to support it. The
following excerpt from How to Tune and Modify Engine Management Systems explains
further:
“The Electrojector system required 40 seconds to warm up before you
could start the engine. Sometimes it malfunctioned if you drove under
9
high-tension power lines. In addition to the liabilities of vacuum-tube
technology, Bendix didn’t have access to modern engine sensors. Solidstate circuitry was in its infancy, and although automotive engineers
recognized the potential of electronic fuel injection to do amazing things
based on its extreme precision of fuel delivery, the electronics technology
to make EFI practical just didn’t exist yet” (Hartman, 2003).
Bendix developed the magical solution that engineers were desperately seeking.
Unfortunately, Bendix was ahead of its time with the invention of EFI. There were
simply too many hassles and far too many risks associated with this new system.
Thankfully, by the 1960s, the electronics industry would be ready for EFI.
By the 1960s, the first engine control unit entered its second phase of
development. By then, engineers had the tools necessary to integrate EFI into
automobiles, which was a huge advancement in the automotive industry. As a result of a
booming electronics industry, transistors were invented, solid-state circuitry was fast, and
microprocessors had just been developed. Armed with these new technologies and the
concepts developed by Bendix, Bosch engineers were able to develop the first practical
ECU. “Volkswagen introduced the first Bosch electronic fuel injection systems on its
cars in 1968” (Hartman, 2003). The new EFI technology was a substantial asset for the
automobile industry because it allowed “engineers to improve drivability and
reliability… [while] complying with federal legislation that mandated increasingly stiff
standards for fuel economy and exhaust emissions” (Hartman, 2003). At last, automotive
engineers were able to please both the government and drivers. Unfortunately, EFI was
still an expensive technology during the sixties and seventies. Despite the cost,
automakers were willing to make the investment. “The cost disadvantages of [electronic]
fuel injection were outweighed by the potential penalties resulting from non-compliance
with emissions and Corporate Average Fuel Economy standards, and the increased sales
10
when offering superior or at least competitive horsepower and drivability” (Hartman,
2003). By bringing new light to an older technology, automakers were finally able to
solve the greatest problem plaguing their industry for over two decades. The
development of the first EFI system paved the way for future improvements and
embellishments, and automotive engine management technology would never be the
same again.
2.3.3. Subsequent ECUs up until 1997
Following the development of Bosch’s first practical EFI, electronic fuel injection
became a center of attention for the automotive and racing industries. For the next 25
years, EFI would continue to evolve and expand as companies invested money in
developing fuel management systems to please the desires of drivers and racers
everywhere. In 1975, “GM marketed its first U.S. electronic injection as an option for
the 500-ci Cadillac V-8 used in the DeVille and El Dorado” (Hartman, 2003). This EFI
and the others that were developed during this time were all “hardwired EFIs.” That is,
their logic was hardwired into the unchangeable circuit of an analog controller. This type
of EFI was definitely far superior to the old carburetor and mechanical injection systems,
because it could more accurately manage the fuel-air ratio injected into the engine.
However, it had one major drawback. In order to tune an engine with one of these
devices, one had to replace the entire ECU. This was a major downside for the racing
industry, which was hesitant to switch to ECUs in the first place. Hot rodders and engine
tuners at that time were very comfortable with the mechanical systems on an engine, and
they had the skills for tuning carburetors. They did not care for the complexity of the
new ECUs, nor did they enjoy the added expense of replacing an ECU every time an
11
engine needed to be tuned. The original ECUs were more than adequate for the average
vehicle operator, but racers desired something more customizable.
As a result of racers’ desires to tune ECUs more cost-effectively, new ECU logic
technology was developed. Instead of using analog controllers with logic hardwired into
the circuitry, carmakers began to develop digital ECUs. These new ECUs “were directed
by software logic and tables of calibration data parameters locked away in a
programmable read-only memory (PROM) device” (Hartman, 2003). The transition to
digital ECUs was another step in the right direction. Instead of having to replace the
entire ECU to tune an engine, one could simply replace the PROM chip. This made
manufacturing ECUs much easier, because a generic ECU could be produced and
different chips could be installed for each vehicle model. However, if you were not an
ECU expert or a skilled programmer, it was extremely difficult to fabricate new chips.
“The documentation, equipment, and technical expertise needed to create or ‘blow’ new
PROMs was not accessible to most hot rodders” (Hartman, 2003). Therefore, racers were
again disappointed. They could purchase new PROMs calibrated to their needs from a
professional tuner, but these were expensive and engine specific. If a racer installed a
customized PROM and then decided to modify his engine again, he would have to buy an
entirely new chip. Clearly, this was not very convenient in the racing world. Overall, the
development of digital ECUs with PROMs greatly benefited automakers, but another
modification would be needed before car enthusiasts could fully benefit from these new
control devices.
Following the creation of digital ECUs, the next phase in ECU technology began.
The need for customizable engine management systems spurred the creation of a new
12
type of ECU called a standalone programmable ECU. Most of these ECUs were
aftermarket designs and could be purchased and installed by car enthusiasts. According
to Jeff Hartman, the most successful ECU was the Haltect F3. It “was an EFI-only
system with an installed base of maybe 2,000 systems” (Hartman, 2003). Engine control
units, such as the F3, were finally appealing enough for racers to seriously consider them.
Even some “old school” racers switched from carburetors to ECUs when they learned
about the benefits and easy operation of standalone programmable ECUs. Most car
manufacturers do not use programmable ECUs, because they do not want inexperienced
operators wildly changing engine management parameters (that is a good way to literally
blow up an engine). Also, manufacturers like to be able to tune the car as they see fit and
still have it meet federal and state regulations. However, standalone programmable
ECUs are still common in racing and performance shows today.
Now that the development of more modern ECUs has been explored, some of the
impressive benefits of using an ECU will be examined. According to Jeff Hartman:
“Knowledgeable racers and hot rodders soon discovered that well-tuned
modern programmable EFI systems almost always produce significantly
higher horsepower and torque than the same powerplant with carbureted
fuel management, especially when the engine is supercharged or
turbocharged. This increased performance is in addition to improved
drivability, cleaner exhaust emissions, and lower fuel consumption.”
These are pretty general benefits, so this paragraph will also highlight a few specifics.
Electronic fuel management systems allow higher air in-flow rates, consistent cylinderto-cylinder air-fuel distribution, more efficient engine compression ratios and extremely
accurate fuel delivery. They can be recalibrated for future engine modifications, can
automatically correct for changes in altitude, and are not susceptible to the mechanical
13
failure or wear inherent with carburetors. It seems pretty clear why many racers and
automakers chose to switch from carburetors to ECUs. Not only are they more accurate,
but they consistently maintain this accuracy. Carburetors often require fine tuning as
they age, because the mechanical components loosen, whereas ECUs maintain tuning
parameters forever. In sum, ECUs are slightly more complicated to use, because they
require a computer to program them, but cars today are also more complicated than they
used to be, so engine controls need to be more encompassing.
2.3.4. Today’s ECUs
Now that the development of automotive ECUs has been explored, there are two
remaining topics to be covered concerning ECUs before concluding this chapter. First,
some light will be shed on the newest type of automotive ECU. The second part of this
report will examine the application of ECUs to vehicles other than automobiles.
As a result of the Clean Air Act of 1990, automakers had to take vehicle control
to the next level. To satisfy even greater environmental standards, engineers designed a
revolutionary engine management system called Onboard Diagnostics, Second
Generation (OBD-II). Unlike the previous ECUs analyzed in this document, this control
system was the first to execute two new functions. First, instead of simply controlling the
fuel-air mixture entering the engine, OBD-II controls the entire engine and other
components of the vehicle. This system controls the ignition timing, shifting timing of
the transmission, coolant system, power steering and antilock brakes. Basically, a tiny
little black box will ensure that a vehicle’s transmission shifts as it accelerates, increases
the flow of the coolant system as the engine warms up and prevents the vehicle from
skidding out of control on a slippery road. This is pretty impressive for a little black box.
14
If managing the entire operation of the automobile is not impressive enough, then
consider the second revolutionary capability of OBD-II. Onboard Diagnostics, Second
Generation control systems have the ability to do real-time self-tests and predict
component failures. OBD-II systems are required to monitor “what goes on and record
troubles for service technicians as they happen, [and] OBD-II rules require the prediction
of deterioration of the following: catalytic converter, fuel delivery and evaporative
emissions systems, crankshaft and camshaft position sensors, oxygen sensors, manifold
air temperature sensors, ignition system and others” (Intel, 2007). Basically, the OBD-II
has the ability to detect malfunctioning components and either tell the driver with the use
of a “check engine light” or correct the problem if possible. OBD-II systems have a
memory, so they can track malfunction signals to determine if there is a legitimate
problem. Then, once the system detects a problem, it illuminates the “check engine
light” and a technician can attach a code reader to the vehicle to determine what the
system senses to be malfunctioning or predicts will breakdown. According to Jeff
Hartman, previous computer ECUs would simply assume that a valve had opened and
continue to operate as if the valve had opened. The OBD-II system actually will check to
make sure the valve did indeed open. Thus, this system can detect problems before they
turn into major mechanical failures or performance issues. These control systems are
truly impressive, and this entire report could be devoted to the intricacies of OBD-II
systems, but that is not the focus of this thesis. If the reader desires more information on
these systems, please consult the references included at the end of this report.
In addition to the discussion of automobile ECUs, it is important to examine the
application of ECUs to other sorts of vehicles. Engine control units have spread from
15
strictly automotive applications to commercial vehicles and smaller, personal vehicles.
“Diesel engines are now equipped with electronic engine management systems”
(Hartman, 2003). Commercial drivers and manufacturers of diesel engines have realized
that the same technology that improved performance and emissions for gasoline engines
can be applied to diesel engines as well. According to my father, a former forklift
mechanic for Hyster New England, electronic fuel injection is even being installed on
modern LPG powered forklifts. Aside from commercial vehicles, ECUs are now being
installed on smaller, personal vehicles. Starting around 2000, “many motorcycles and
boats have moved to electronic fuel injection and engine management as well” (Hartman,
2003). The 2007 Yamaha Phazer Snowmobile used in this project came equipped with a
modern ECU. Engineers have realized that the technology used for so long on
automobiles can be applied to other vehicles that have been polluting the atmosphere.
Snowmobiles, watercraft, and ATVs have had some of the worst pollution records, and it
is encouraging that designers are starting to use ECUs to clean up small engine operation
as well.
16
Chapter 3
SIMULINK MODEL OF THE ENGINE CONTROL
UNIT
3.1. Introduction
This chapter will examine the computer model portion of this thesis project,
which is primarily the theoretical portion of the project. Initially, the reasons for creating
the model will be explored to help the reader fully understand the significance of the
computer model. After the model’s justifications have been explained, a brief description
of the model will be presented. This narrative will explain the basics behind the model,
including the software used, some fundamental equations, the inputs and outputs to the
model, a flow diagram and simple instructions on how to use the model. The reader is
referred to the Appendix as needed for further explanation and details.
3.2. Why the Computer Model Was Created
The computer model used in this project was created for two main reasons. In
general, the computer model was constructed to allow MegaSquirt ECU users to
theoretically predict the response of the ECU. Instead of hooking the ECU up to a test
board or risking testing new tuning parameters on the vehicle itself, MegaSquirt users can
utilize the computer model to predict the response of the system without actually using
the ECU itself. By being able to theoretically predict the response of the MegaSquirt
ECU, my team and I were able to accomplish our main goals. The computer model
enabled my clean snowmobile team to do real-time simulations of the ECU’s operation
17
over time. These simulations allowed my team and I to understand the response of the
ECU subjected to various operating conditions. The full benefit of these real-time
simulations will be explored in the future work section of Chapter 6.
3.3. Description of the Computer Model
3.3.1. Software
The computer model for this project was created in a software package called
Simulink, which is the control systems software component of MATLAB, a MathWorks,
Inc. software package. “Simulink is a software package for modeling, simulating, and
analyzing dynamic systems, [and] it supports linear and nonlinear systems, modeled in
continuous time, sampled time, or a hybrid of the two” (The MathWorks, Inc, 2002 b).
Unlike most programming packages, “Simulink provides a graphical user interface (GUI)
for building models as block diagrams, using click-and-drag mouse operations” (The
MathWorks, Inc, 2002 b). With this interface, modelers can draw models just as they
would on paper. In addition, “Simulink includes a comprehensive block library of sinks,
sources, linear and nonlinear components, and connectors” (The MathWorks, Inc, 2002
b). Another feature of Simulink is that programmers can customize and create their own
blocks. Included in the library of customizable blocks are a series of subsystem blocks.
Programmers can use these blocks to consolidate their models by condensing several
linked blocks into one subsystem block, hence creating hierarchical structures in the
computer models. After creating a model, the user can simulate it using a choice of
integration methods, including standard techniques or specified custom approaches.
Figure 3.1 below displays a simple block diagram that can be created in Simulink to plot
the functions y(t) = x(t) and y(t) = 2x(t) + 1.
18
Figure 3.1: Sample Simulink Block Model
The version of MATLAB used in this thesis was Version 7.0.1 and the Simulink
Version was 6.1. These are full, professional versions of MATLAB and Simulink. Full
versions were necessary, because the computer model grew too large for the Student
Versions.
The computer model used in this thesis was created in Simulink for two major
reasons. First, Simulink has several capabilities that other programming languages,
including C++ and Fortran, lack. Typically, programmers using common compilers have
to create subroutines for signal generators, such as counters, ramp functions or sinusoidal
functions. Simulink has libraries of signal generators that can simply be inserted into a
model. In addition, Simulink has built in plotter blocks called scopes. These blocks
allow the programmer to see real-time results of a model as the simulation is running. If
a programmer was using C++ or Fortran, he would have to save his model’s output to a
file, import the file to a plotting software, such as Excel, and then manually plot the
results. This process takes far longer than using the Simulink scopes, and the
programmer cannot view the results in real-time as they occur. If the modeler desires to
save the results of his Simulink model, he can simply instruct the scopes to save the
output data to the MATLAB Workspace, where it can be copied into another spreadsheet
to be saved. In addition to the advantages of Simulink’s advanced capabilities, this
19
software is extremely user-friendly. Traditionally, programmers would have to enter line
after line of code into a compiler. Using Simulink, users can simply draw block diagrams
to create their code. Simulink is a visual programming-software that enables users to
easily follow logic loops and determine the algorithms behind the block diagrams.
Because of its advanced capabilities and user-friendly interface, Simulink was selected as
the programming software for this thesis.
3.3.2. Fundamental Equations
Below are three of the major equations used in this thesis’ computer model, which
are also three of the fundamental equations used by MegaSquirt. All the equations used
in this computer model were obtained directly from several sources. They were found
using online MegaSquirt Manuals, by searching through the open-source C Code of the
ECU, and by asking MegaSquirt experts on MegaSquirt’s public forums. For more of the
detailed equations used in this model, please consult the Computer Model Equations
section in Appendix D. For more information on the development of the equations,
please consult the MegaSquirt references cited at the conclusion of this report.
3.3.2.1 MegaSquirt’s Air-Fuel Ratio Equation:
MegaSquirt utilizes the following equation to calculate the theoretical air-fuel
ratio (AFR) that is going into an engine. This calculation is not used to control engine
operation; rather it is computed only for tuning purposes and stored in the ECU datalogs.
MegaSquirt calculates and logs the AFR values, because they enable the user to have a
better understanding of how the engine was operating at a given time.
20
VE
 MAP  CYLDISP
100
 MM a
5


R   IAT  32   273 
ma
9


AFR 

mf
PW  INJFLOWM
Where:
VE = Volumetric Efficiency Correction Factor, which accommodates for the change in
air volume as the engine’s manifold air pressure and speed change
MAP = Manifold Air Pressure, which is the pressure of the air before it enters the
cylinders
CYLDISP = Volume of one cylinder in metric units (L)
R = Ideal Gas Constant (8.314351 J/mol-K)
IAT = Intake Air Temperature (oF)
MMa = Molecular Mass of Air (28.97 g/mol)
PW = Injector Pulse Width (ms)
INJFLOWM = Injector Flow Rate in Metric Units (kg/s)
3.3.2.2. MegaSquirt’s Fueling Equation:
MegaSquirt uses the equation below to determine the final pulse width of the fuel
injectors in an operating engine. This computation is done in real-time as the engine
operates, and it is designed to allow the ECU to accommodate for an engine that is not
running stoichiometrically. To understand how the various terms are calculated, please
consult Appendix D.
PW  REQFUEL 
VE MAP

 E  DFP  ACCEL  MIOT
100 100
Where:
PW = Injector Pulse Width, which is how long the injector remains open to insert fuel
(ms)
REQFUEL = Pulse Width required for the engine to burn stoichiometrically (ms)
VE = Volumetric Efficiency Correction Factor, which accommodates for the change in
air volume as the engine’s manifold air pressure and speed change
MAP = Manifold Air Pressure, which is the pressure of the air before it enters the
cylinders
E = Enrichment Coefficient, which accommodates for a cold engine, changes in
atmospheric conditions and the oxygen sensor readings
21
DFP = Deceleration Fuel Percentage, which accommodates for the decreased amount of
fuel needed when decelerating
ACCEL = Acceleration Add-On, which increases the pulse width due to higher fuel
needs when accelerating
MIOT = Modified Injector Open Time Add-On, which accounts for the physical limits
of how long an injector takes to open and any changes in battery supply voltage to
the ECU itself
3.3.2.3. MegaSquirt’s Required Fuel Equation:
MegaSquirt utilizes the following equation to calculate the required injector pulse
width for an engine to burn stoichiometrically. This calculation is done before the ECU
is linked to the engine, and the resulting required fuel constant is burned to the ECU, so it
does not change with real-time operation.
CID  36  10 6  4.1453  10 5
NCYL
REQFUEL 
 0.1 
 INJECTORST AG
NCYL  INJFLOW  14.7
DIVIDEPULSE
Where:
CID = Cubic Inch Displacement of the engine (in3)
36E6 = Number of tenths of a millisecond in an hour (used for unit conversion)
4.1453E-5 = Air density at stoichiometric conditions (Air Pressure = 100 kPa, Air
Temperature = 70 oF) (lbm/in3)
NCYL = Number of Cylinders in the engine
INJFLOW = Injector Flow Rate (lbm/hr)
14.7 = Stoichiometric air-fuel ratio
0.1 = Conversion factor from tenths of a millisecond to milliseconds
DIVIDEPULSE = Number of injections per engine cycle
INJECTORSTAG = Injector Staging, which is how the injectors are fired (alternating or
simultaneous)
3.3.3. Computer Model Inputs and Outputs
The Simulink computer model was designed to integrate as many MegaSquirt
variables that affect fueling as possible. In total, the Simulink Model has forty-three
input variables and four input tables. Eight of those variables are considered engine
operating parameters. That is, they are variables that the ECU retrieves from sensors on
the engine, and they change throughout the course of engine operation. The remaining
22
thirty-five variables and four tables are classified as either engine tuning parameters or
engine properties. These variables are changed using MegaTune and downloaded to the
ECU before engine operation, and they do not change over the course of engine
operation. Since forty-seven inputs would generate a lengthy list, please consult the
Input Parameter Key in Appendix A for a complete list of the input parameters and their
descriptions. As for the output this model computes, there are two output variables. One
output is the final injector pulse width, which is the length of time the ECU would hold
the fuel injectors open. The other output is the theoretical air-fuel ratio entering the
engine.
3.3.4. Flow Chart of the Program
In an effort to help the reader understand the processes and logic utilized in the
Simulink model, a simple flow chart of the program is presented on the following few
pages. In this flow chart, a standard style is followed, where parallelograms represent
inputs and outputs, rhombi display logic statements, rectangles represent calculations,
circles correspond to connectors used to link converging paths, and pentagons indicate an
off-page connector. This visual can be used with the equations presented previously and
the specific equations and list of input parameters included in the Appendix. If further
detail is desired, please consult the actual Simulink code on the included CD in the
Appendix.
23
BEGIN
Enter
ENGINE OPERATING
PARAMETERS
Enter
ENGINE TUNING
PARAMETERS
Enter
ENGINE PROPERTIES
Is the
engine
cranking?
No
A
Yes
Is the
engine
flooded?
Yes
PW = 0.3
No
Calculate Cranking
Pulse Width (PW)
Figure 3.2: Simulink Model Flow Chart (Continued on Next 4 pages)
24
B
A
E
Is Barometric
Correction
Enabled?
No
Is Oxygen
Sensor
Correction
Enabled?
BAROCORR=100
Yes
O2CLOSEDLOOP=100
Yes
Calculate
Barometric
Correction Factor
(BAROCORR)
Is Engine
Warming Up?
No
Calculate Oxygen
Sensor Correction
Factor
(O2CLOSEDLOOP)
No
WARMUP=100
Calculate Air
Density Correction
Factor
(AIRCORR)
Yes
Calculate Warmup
Correction Factor
(WARMUP)
25
Calculate
Enrichment
Coefficient (E)
C
E
C
Determine Pulse
Width Required for
Stoichiometric
Combustion
(REQFUEL)
F
Interpolate VE
Value
Calculate the Initial Pulse Width (PWI)
PWI = REQFUEL x (VE/100) x (MAP/100) x E
D
26
Determine MAP
Factor
F
No
D
Is the engine
accelerating?
No
Is the engine
decelerating?
ACCEL = 0
Yes
DFP = 1
Yes
Calculate
Acceleration Add-On
(ACCEL)
Calculate Deceleration
Fuel Percentage
(DFP)
Calculate Intermediate Pulse Width (PWM)
PWM = PWI x DFA +ACCEL
Calculate Modified Injector Open Time (MIOT)
Calculate Final Pulse Width (PW)
PW = PWM + MIOT
B
Display PW
Calculate Air Fuel Ratio (AFR)
27
Display AFR
END
3.3.5. Method for Using the Model in General
A quick explanation will be made here regarding how to use the Simulink Model
of MegaSquirt II, but if further information is desired, please consult the document titled
“Instructions for Using the Simulink Model of MegaSquirt II V3” in Appendix C. A
quick overview is necessary before specific instructions can be given. There are two
versions of the “Simulink Model of MegaSquirt II:” a Real Time Version and a Snap
Shot Version. These two files have similar codes, but are designed for different
purposes. The Snap Shot Version was created primarily for testing and calibrating
purposes, and it is designed to compare pulse width results with MegaTune. This
program is designed to predict the resulting pulse width of the ECU at an instant in time
without regard to variables that change as time goes on. The Real Time version is
designed to simulate real-time operation of the ECU over a period of time. It will
account for all the variables that change as time increases, and the results can be
displayed by opening the PW Scope in the model itself. For accurate simulations, use the
Real Time Version.
Once the correct model version is open on a computer, the user will be looking at
scores of boxes (or blocks, as they are termed in Simulink). See Figure 3.3 below for a
visual. These blocks are one of four colors: orange, blue, red or white. The input blocks
are blue and orange, the output blocks are red, and the calculation blocks (where the code
is) are white. Before the model can be run correctly, the user must enter all the inputs
correctly. Using the instructions and the files called “Input Parameter Key” and “MSII
Screen Shots and Figures” in the Appendix, the user can enter the inputs correctly. Once
the input blocks are complete, the user needs to enter the input tables using the
28
instructions provided. Once the tables are entered completely, the model is ready to be
run. The user can set the simulation parameters as desired in the MATLAB
Configuration Parameters window, and once those are set the model can be run. After
running the model, the red output blocks will indicate the most recently calculated results
for injector pulse width and air-fuel ratio, whereas the plotter will display the last 5000
data points (this can be changed in Simulink if more points are desired). Using the
plotter blocks to view the results over time provides the user with a better visual of the
response of the ECU as time continues. To try different engine or tuning parameters,
simply change the inputs and re-run the model to see how the new inputs affect the
results. The plotters are also configured to save the results to the MATLAB Workspace,
so the user can view them in a tabulated manner or copy them into a spreadsheet.
Figure 3.3: Image of Simulink Model main screen
29
3.4. Procedure Used for Generating Comparison Results
Once the model was completed and passed an initial inspection, we conducted
comparison tests between MegaTune and the Simulink Model. We decided to test as
many input variables as possible. Since MegaTune only displays the response of the
ECU instantaneously and most of the variables going into the ECU affect real-time
response only, the majority of the tuning parameters and a couple of the engine
parameters could not be tested using MegaTune. In total, there were thirteen input
variables that could be tested, of which seven were engine operation parameters and six
were tuning parameters. My team and I only changed one input variable at a time, and
we tested the same ten input values for each variable on the model and in MegaTune.
After the engine variables had all been tested, they were held constant and some of the
ECU tuning properties were tested. The same tuning parameter values that were tested
on the ECU were tested on the Simulink model. All of the model’s input and output
values were logged into a spreadsheet on a laptop. For specific ranges and points used,
please consult Chapter 5 and the Appendix.
30
Chapter 4
ENGINE CONTROL UNIT EXPERIMENTAL SETUP
4.1. Introduction
The intent of this chapter is to familiarize the reader with how the experimental
data were obtained for this project and why these data were needed. This chapter will
discuss the need for experimental data, the components used to obtain the data and the
setup and procedure used to obtain the data. After studying this chapter, the reader
should be able to perform an experiment similar to the one used for this project to obtain
his own set of experimental data.
4.2. Why the Experimental Data Was Needed
Since the main focus of this thesis was to create a computer model of the
MegaSquirt ECU, there needed to be a way to test the accuracy of the model. The
simplest technique to test the accuracy of the model was to compare the model’s
predicted results to the actual results obtained using the ECU. Therefore, an
experimental setup had to be configured such that the ECU could generate mock results.
These mock results were used to validate the computer model and to ensure that the ECU
itself was working properly.
31
4.3. Components and Software of the Experimental Setup
The experimental setup consisted of four major components: the ECU, the ECU
stimulator, a power supply and the ECU’s tuning software. Each of these components
will be examined in detail in this section.
The ECU used in this project was a MegaSquirt-II Version 3 created by Bruce
Bowling and Al Grippo. The MegaSquirt came equipped with the standard MC9S12
processor, and it was purchased from DIY Autotune. This ECU was selected for use,
because it has open-source architecture, which enabled me to create a model to predict
operation of the ECU.
Figures 4.1 and 4.2: External and Internal Photos of MegaSquirt-II V3
The ECU stimulator used in this project was a MegaSquirt Stimulator V2.1
created by Bruce Bowling and Al Grippo. It was purchased from DIY Autotune as well.
The stimulator was used to generate dummy input signals for the ECU, which would
cause the ECU to generate mock output signals. A more detailed discussion is in the next
section.
32
Figure 4.3: Photo of Stimulator V2.1
To power the MegaSquirt ECU during experimental tests, we used an Elenco
Electronics 12V power supply. This power supply was necessary during experimental
testing, because the ECU normally receives its power from the engine, but the ECU was
not affixed to the engine during simulation tests.
Figure 4.4: Photo of Power Supply Hooked Up to MegaSquirt with Stimulator
33
The tuning software used during the experimental tests was MegaTune V2.34.
This software was downloaded to a lab computer and used to read the input and output
signals from the MegaSquirt ECU.
Figure 4.5: Photo of MegaTune’s Main Screen
Figure 4.6: Photo of MegaTune’s Real Time Display Screen
34
4.4. Experimental Testing Setup and Procedure
4.4.1. Setup
The components described above were arranged according to the following
description and the photograph shown in Figure 4.7 below. The MegaSquirt Stimulator
was plugged into the input socket on the MegaSquirt ECU. Then, the ECU was linked to
the lab computer using a serial cable. Once the hardware was hooked up, the power
supply was plugged in and attached to the power ports on the ECU. Then, MegaTune
was opened on the lab computer. Once this setup was complete, the power supply was
turned on and the voltage was set to 13.7 volts initially. Once these steps were complete,
the ECU was ready to be tested.
35
Figure 4.7: Photo of Experimental Setup
4.4.2. Procedure
Once the setup above was complete, the stimulator was used to generate dummy
engine sensor input signals to the ECU, which caused the ECU to generate mock injector
pulse width values (the ECU’s output). MegaTune would read these injector pulse width
signals and display the injector pulse width values on its main screen. Only one input
variable was changed at a time, and ten points were tested for each stimulator input
variable. After the stimulator variables had all been tested, the stimulator values were
held constant and some of the ECU tuning properties were tested. Not all of the tuning
properties could be tested on the ECU using this setup. This is because the software only
36
displays instantaneous results, and some of the tuning parameters only show effects in
continuous, real-time results. Therefore, we varied as many tuning parameters as much
as we could. All of the input and output values were logged into a spreadsheet on a
laptop. The lists below indicate which variables were tested during this simulation test.
For specific ranges and points used, please consult Chapter 5 and the Appendix. For
further explanation on what the input variables mean, please consult the Input Parameter
Key in the Appendix.
4.4.3. Variables Tested
Stimulator/Engine Sensor Variables:
Engine Speed (RPM)
Coolant Temperature (oF)
Throttle Position Sensor Reading (%)
Intake Air Temperature (oF)
Oxygen Sensor Reading (V)
Manifold Air Pressure (kPa)
Battery Voltage (V)
Tuning Parameters:
Battery Correction Factor (ms/V)
Injector Open Time (ms)
Injector Staging
Number of Cylinders
Engine Size (in3)
Injector Flow Rate (lbm/hr)
Output Variable Recorded:
Injector Pulse Width (ms)
37
Chapter 5
COMPARISON AND SIMULATION RESULTS
5.1. Introduction
This chapter will present two sections of results. First, it will cover the results
used to compare the Simulink Model (theoretical) to the results obtained using the
experimental setup with MegaTune (experimental). At the end of the graph section, a
final summary of the results will be presented. Following the summary, an explanation
will be given to explain the percent differences and how they would impact engine
operation overall. To see the tabulated comparison data directly obtained from the
Simulink Model and that of MegaTune, please reference Appendix E. The second
portion of this chapter will present real-time, simulated ECU response curves. These
curves will display the simulated response of the ECU during phases of operation that can
only be observed during real-time engine operation, which means that these response
curves cannot be generated using MegaTune. More importantly, future users of the
Simulink model would use plots like these to predict engine response and perform
optimization work. In essence, the comparison results were useful to establish the
accuracy of the model, whereas the simulation plots are useful for users of the model to
understand the response of the ECU during realistic operating scenarios.
38
5.2. Comparison Results
5.2.1. Introduction to Graphical Comparison Results
This section contains the graphs used to compare the Simulink Model
(theoretical) to the results obtained using the experimental setup with MegaTune
(experimental). These results will be presented graphically one at a time and will include
the maximum and average percent differences for each data set. A brief discussion will
follow every plot, summarizing the relationship between the two data sets and explaining
the correlation between the tested variable and the output. For each graph presented in
this section, only one variable was altered at a time, while the remaining variables were
held constant. The parameter being varied is indicated underneath the horizontal axis of
each plot and mentioned in the figure caption. The result graphed in each of the
comparison plots is the injector pulse width. Lastly, the Simulink results are always blue
whereas the MegaTune results are always colored red.
39
5.2.2. Graphical Comparison Results with Brief Discussions
9
8.5
PULSE WIDTH (ms)
8
7.5
SIMULINK
MEGATUNE
7
Max
Difference:
2.521 %
6.5
6
Average
Difference:
2.109 %
5.5
5
0
2000
4000
6000
8000
10000
12000
ENGINE SPEED (RPM)
Figure 5.1: Comparison Results Graph for Pulse Width vs. Engine Speed
Based on the similar curve trends and the maximum and average percent
differences displayed above, the Simulink Model results agree with the MegaTune results
for varied engine speed. Both of these curves also agree with the response that should be
expected from an ECU experiencing an increase in engine speed. As an engine’s speed
increases, a greater force is required to push the pistons downward faster. Therefore,
more fuel is needed to increase the explosiveness of the combustion, which yields a
greater downward force on the piston. Opening the fuel injectors longer also accounts for
the reduction in volume experienced by the fuel-air mixture as well.
40
12
11.5
11
PULSE WIDTH (ms)
10.5
10
SIMULINK
MEGATUNE
9.5
Max
Difference:
3.487 %
9
8.5
8
Average
Difference:
2.691 %
7.5
7
0
50
100
150
200
250
COOLANT TEMPERATURE (Degrees F)
Figure 5.2: Comparison Results Graph for Pulse Width vs. Coolant Temperature
Since the two curves above follow the same trend and their percent differences
are low, the Simulink model results agree with those of MegaTune. The correlation of
each data set above is also reasonable, because as an engine warms up less fuel is needed
to maintain combustion. This is because fuel is more difficult to ignite effectively at
lower temperatures, so more fuel is used at lower temperatures to boost the combustion
power.
41
8.4
8.2
PULSE WIDTH (ms)
8
7.8
SIMULINK
MEGATUNE
7.6
Max
Difference:
2.397 %
7.4
Average
Difference:
2.397 %
7.2
7
0
20
40
60
80
100
120
THROTTLE POSITION SENSOR VOLTAGE PERCENTAGE (%)
Figure 5.3: Comparison Results Graph for Pulse Width vs. Throttle Position Sensor
Voltage Percentage
The above graph for the Simulink Model and MegaTune are similar, and the
maximum and average percent differences are low, so the Simulink Model results agree
with the MegaSquirt results for varied Throttle Position Sensor Voltage Percentage. The
reason these lines are parallel and horizontal is because Throttle Position Sensor Voltage
Percentage does not affect the ECU instantaneously. This input only impacts the
acceleration add-on, which is not noticeable in instantaneous results of the ECU.
Therefore, both MegaTune and the Simulink model did not show any change in the
response of the ECU as this variable changed.
42
10.5
10
PULSE WIDTH (ms)
9.5
9
SIMULINK
MEGATUNE
8.5
Max %
Difference:
3.057
8
Average %
Difference:
2.099
7.5
7
0
50
100
150
200
250
INTAKE AIR TEMPERATURE (Degrees F)
Figure 5.4: Comparison Results Graph for Pulse Width vs. Intake Air Temperature
Based on the similarity between the two data sets presented above and the low
percent differences between them, the Simulink results agree with those of MegaTune for
Intake Air Temperature. These curves also agree with what should be expected. As the
air temperature increases, the air density decreases, which means that to maintain the
proper air fuel ratio for a set air flow, less fuel is required hence the pulse width
decreases.
43
8.4
8.2
PULSE WIDTH (ms)
8
7.8
SIMULINK
MEGATUNE
7.6
Max
Difference:
2.397 %
7.4
7.2
Average
Difference:
2.397 %
7
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
OXYGEN SENSOR VOLTAGE (V)
Figure 5.5: Comparison Results Graph for Pulse Width vs. Oxygen Sensor Output
Since the sets of curves above are similar, and the maximum and average percent
differences are low, the Simulink Model results agree with the MegaTune results for
Oxygen Sensor Output. Similar to the throttle position sensor results, these results are
also supposed to be constant. This is because the effects of oxygen sensor readings are
only noticed in real-time operation, not snapshots of ECU performance. The effects of an
oxygen sensor’s readings will be addressed in the next section while examining sample
simulation results.
44
10
9
8
PULSE WIDTH (ms)
7
6
SIMULINK
MEGATUNE
5
4
Max
Difference:
5.636 %
3
2
Average
Difference:
2.916 %
1
0
0
20
40
60
80
100
120
MANIFOLD AIR PRESSURE (kPa)
Figure 5.6: Comparison Results Graph for Pulse Width vs. Manifold Absolute Pressure
Since the two sets of data above are very similar and have a low percent
difference, it can be concluded that the Simulink model results agree with those of
MegaTune for changing Manifold Air Pressure. These curves are also what should be
expected. As the manifold air pressure increases, the amount of air injected into the
cylinders when the valves open increases. Since more air is being pushed into the
cylinder, more fuel also needs to be added to maintain the correct air-fuel ratio for
combustion. Therefore, a positive correlation between manifold air pressure and pulse
width should occur.
45
9.5
PULSE WIDTH (ms)
9
8.5
SIMULINK
MEGATUNE
Max
Difference:
2.707 %
8
Average
Difference:
2.423 %
7.5
7
6
8
10
12
14
16
18
SUPPLY BATTERY VOLTAGE (V)
Figure 5.7: Comparison Results Graph for Pulse Width vs. Supply Battery Voltage
Based on the similar curves in Figure 5.7 above and the maximum and average
percent differences displayed in that figure, the Simulink Model results agree with the
MegaTune results for varied Supply Battery Voltage. It is also encouraging that these
curves are both linear and decreasing with respect to battery voltage. These curves
should be linear, because the ECU accommodates for a non-standard battery voltage
using a linear equation. Also, the need for a greater pulse width for lower battery
voltages is expected. Fuel injectors are opened using electrical solenoids, which use coils
to create a magnetic field to move the actuator. Therefore, a low voltage across a coil
will take longer to move the actuator than a higher voltage. This decreased opening time
reduces the amount of time the injector is actually open, which prevents enough fuel from
entering the engine. Therefore, MegaSquirt accommodates for low voltages by opening
the injectors longer, so the amount of time they are actually open will be adequate. The
46
reverse occurs for higher voltages, because the injectors open more quickly, so they do
not need to be open for as long.
9.5
PULSE WIDTH (ms)
9
8.5
SIMULINK
MEGATUNE
8
Max
Difference:
2.441 %
7.5
Average
Difference:
2.315 %
7
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
BATTERY CORRECTION FACTOR
Figure 5.8: Comparison Results Graph for Pulse Width vs. Battery Correction Factor
Since both data sets above are parallel and have a low percent difference, one can
conclude that the results of the Simulink model agree with those of MegaTune for
varying battery correction factor. Since MegaSquirt accommodates for varying battery
voltages using a linear function with a slope equal to the battery correction factor, the
linear curves generated above are as expected.
47
14
13
PULSE WIDTH (ms)
12
11
SIMULINK
MEGATUNE
10
Max
Difference:
2.441 %
9
8
7
0
1
2
3
4
5
6
Average
Difference:
1.949 %
INJECTOR OPEN TIME (ms)
Figure 5.9: Comparison Results Graph for Pulse Width vs. Injector Open Time
The parallel curves in Figure 5.9 above have low percent differences, so the
Simulink Model results agree with those of MegaTune for varied Injector Open Time.
Since MegaSquirt accommodates for the physical limits of an injector’s opening time
with a simple addition on the end of the fueling equation, it is expected that increasing
the injector open time by one millisecond will also increase the resulting pulse width by
one millisecond. Therefore, the results displayed above are also as anticipated.
48
9
8.5
8
PULSE WIDTH (ms)
7.5
7
SIMULINK
MEGATUNE
6.5
6
Max
Difference:
1.305 %
5.5
5
4.5
4
0
0.2
0.4
0.6
0.8
1
1.2
Average
Difference:
1.233 %
INJECTOR STAGING (0.5 = simultaneous, 1 = alternating)
Figure 5.10: Comparison Results Graph for Pulse Width vs. Injector Staging
Since the two data sets above are almost parallel and have a low percent
difference, the results for both the Simulink model and MegaTune agree for varying
Injector Staging. Since MegaSquirt accounts for different types of injection by simply
multiplying the required stoichiometric pulse width by the injector staging type, it is
expected that the correlation between pulse width and injector staging will be linear.
Therefore, the results above are reasonable.
49
8.4
8.2
PULSE WIDTH (ms)
8
7.8
SIMULINK
MEGATUNE
7.6
Max
Difference:
3.367 %
7.4
Average
Difference:
1.288 %
7.2
7
0
2
4
6
8
10
12
14
NUMBER OF CYLINDERS
Figure 5.11: Comparison Results Graph for Pulse Width vs. Number of Cylinders
Despite some variation in the curves of Figure 5.11, the similarities between the
data and the low maximum and average percent differences in the figure denote that the
Simulink Model results agree with those of MegaTune for varied Number of Cylinders.
The horizontal line generated by the Simulink model is reasonable, because the number
of cylinders does not affect the pulse width of an injector, instead it affects the number of
pulse widths needed for an entire engine. My team members and I feel that the variation
in the MegaTune results is a result of rounding error, but this will be addressed further in
the next section.
50
11
10
PULSE WIDTH (ms)
9
SIMULINK
MEGATUNE
8
Max
Difference:
2.718 %
7
6
Average
Difference:
1.024 %
5
20
22
24
26
28
30
32
34
36
38
40
ENGINE SIZE (in^3)
Figure 5.12: Comparison Results Graph for Pulse Width vs. Engine Size
Since the two curves above are reasonably parallel and have a low average
percent difference, the Simulink results for varying engine size agree with those of
MegaTune. The trend of these results is also as expected, because as the cylinder size of
an engine increases more fuel is needed to create enough force to drive the piston down.
51
14
13
12
PULSE WIDTH (ms)
11
10
SIMULINK
MEGATUNE
9
Max
Difference:
1.401 %
8
7
Average
Difference:
0.890 %
6
5
10
15
20
25
30
35
INJECTOR FLOW RATE (lbm/hr)
Figure 5.13: Comparison Results Graph for Pulse Width vs. Injector Flow Rate
Based on how close the above curves lie and the maximum and average percent
differences, the Simulink Model results agree with the MegaTune results for varied
Injector Flow Rate. These curves are also reasonable, because as the flow rate of the
injector increases, more fuel can flow through it per unit of time. Therefore, injectors
with higher flow rates do not need to open as long as injectors with lower flow rates to
input the same amount of fuel.
52
5.2.3. Summary of Results
Overall, the Simulink Model curves and those of MegaTune agree significantly.
There are no plots that have noticeably different correlations between the Simulink curve
and the MegaTune data for the tested input variable and the resulting pulse width.
Considering the engine parameter comparison results (Figures 5.1-5.7), the maximum
percent difference is 5.636% with an average percent difference of 2.418%. Examining
the tuning parameter comparison results (Figures 5.8-5.13), the maximum percent
difference is 3.367% with an average percent difference of 1.285%. Overall, for all
thirteen variables tested, the maximum percent difference is 5.636%, and the average
percent difference is 1.852%.
5.2.4. Explanation of Percent Differences
The small percent differences mentioned above can be attributed to two main
sources of error. The first and greatest cause of error was the discrepancy in the
Stimulator input signals to the MegaSquirt ECU. The Stimulator uses potentiometers to
vary the electrical signals (dummy engine sensor outputs) being sent to MegaSquirt.
These potentiometers are adjusted using a small knob. Since most of the signals going to
the ECU are very sensitive, it is easy to generate a signal from the Stimulator that is not
quite exact. For example, RPM values tended to vary plus or minus ten from the value
we attempted to set the signal. The signals going into the ECU were also very sensitive
to any vibration of the potentiometer. If someone jarred the table while we were sending
a signal to the ECU, it could easily shift the potentiometer setting and thus alter the input
53
signal to the ECU. In an attempt to minimize the error due to vibration, we tried to
double check every input value before we logged any results.
In addition to error being induced by the Stimulator signals, we believe that
MegaTune and MegaSquirt create internal rounding errors. Based on the results
displayed on the MegaTune Real Time Display window (see Figure B.8 in the
Appendix), we noticed that MegaTune often rounded values for certain coefficients that it
used in its calculations. For example, the REQFUEL value in MegaTune, which is a
value that is burned to the ECU, was only determined down to one tenth of a millisecond.
The same variable was calculated down to one thousandth of a millisecond in Simulink.
The same issue occurred with the barometric pressure correction factor. MegaTune
appeared to round this correction factor to the nearest one, whereas the Simulink Model
calculated this value down to the nearest thousandth. In essence, it seemed to my team
and I that Simulink was more accurately computing results than MegaSquirt. This is
understandable for two reasons. First, the ECU needs to be able to do thousands of
calculations every second, so the processing speed would be greatly reduced if the
computer tried to be extremely accurate. Also, controlling the injector’s pulse width
down to a thousandth of a millisecond is far more accurate than the ECU needs to be to
manage an engine effectively. Therefore, it is reasonable that the Simulink Model is
probably more accurate than MegaSquirt.
5.2.5. Effect of Pulse Width Percent Differences on Air-Fuel
Ratio
In an effort to give engine tuners a more appreciable understanding of how much
a two percent error affects the overall operation of an engine, the resulting percent error
54
in air-fuel ratio (AFR) was also calculated. For the details of that calculation, please see
Appendix E. Accounting for a possible 1.852% difference in injector pulse width, the
resulting possible percent error in AFR would also be 1.852%. Thus, for a stoichiometric
air fuel ratio of 14.7, the Simulink model would predict this value to be 14.7 +/- 0.272.
For a richer mixture, such as 13, used to ensure that the catalytic converter on the new
Phazer ignites, the Simulink Model would predict this value in the range of 13 +/- 0.241.
Based on a discussion with my capstone team and the capstone coordinator, we decided
that this percent error was acceptable for reasonable engine predictions and optimization
work.
5.3. Sample Simulation Results
5.3.1. Introduction to Sample Simulation Results Section
This section is designed to present the reader with a few sample plots of real-time,
simulation results that would be generated by the Simulink model if it were used to
predict the response of MegaSquirt. These plots will be presented one at a time and will
include examples illustrating the effects of warm up, oxygen sensor readings,
acceleration, deceleration and cranking. The last example will incorporate as many of
these engine scenarios as possible at the same time. It will display the predicted response
of MegaSquirt undergoing the typical engine cycle of start up, brief idle, acceleration and
continued engine speed increase. Following each sample plot, a description will explain
the different phases of operation present in each graph. Unlike the graphs in the previous
section, these graphs will include both predicted injector pulse width and air-fuel ratio.
55
5.3.2. Sample Real-Time Graphical Results with Discussion
14
13
12
11
10
PW
AFR
9
8
7
6
5
4
0
10
20
30
40
50
60
70
Simulation Time (s)
Figure 5.14: Simulated Results Graph for an Engine Going Through the Initial Warm-Up
Period
Figure 5.14 above displays the predicted response of an engine going through the
initial warm-up period. From 0 to 8.4 seconds, the engine is considered to be initially
warming up. During this period, the Simulink model provides more fuel to the engine
than after it has reached operating temperature, because cold engines do not combust as
well as warmer engines. The amount of extra fuel decreases linearly from 0 to 8.4
seconds, because the engine requires less fuel as it warms up. It is important to note that
this initial warm up period will always occur, even if the coolant temperature is warm,
because engines just starting to operate need extra fuel for the first few hundred cycles to
work properly. After 8.4 seconds, the engine enters the steady idle phase of operation,
where the amount of fuel injected is constant.
56
16
14
12
PW
AFR
10
8
6
4
0
10
20
30
40
50
60
70
Simulation Time (s)
Figure 5.15: Simulated Results Graph for an Engine Responding to Oxygen Sensor
Readings
The graph displayed above is the Simulink model’s response to a series of oxygen
sensor readings. The oxygen sensor reading was set to 0 V from 0 to 30 seconds and then
set to 5 V from 30 to 60 seconds. Since a voltage reading lower than 2.5 V on a
wideband oxygen sensor implies that the engine is running rich, the Simulink model is
trying to lean the mixture out as much as possible. However, at a simulation time of 5.8
seconds, the oxygen sensor correction factor reaches its lower limit, so the Simulink
model cannot reduce the mixture anymore. At a time of 30 seconds, the oxygen sensor
reading suddenly changes to 5 V, which means the engine suddenly switched to running
extremely lean. Therefore, the Simulink model accommodates for this shift by richening
the fuel mixture. The Simulink model continues to increase the amount of fuel going into
the engine until it reaches the upper limit of the oxygen sensor correction factor at 41.1
57
seconds. Once this limit is reached, the model has no choice but to maintain that pulse
width. The upper and lower limits are in place to prevent the engine from running too
richly or too leanly.
58
14
13
12
11
10
PW
AFR
9
8
7
6
5
4
0
5
10
15
20
25
30
35
Simulation Time (s)
Figure 5.16: Simulated Results Graph for an Engine Responding to Acceleration and
Deceleration
The graph above was generated because the Simulink model was subjected to an
acceleration period and a deceleration period. At a simulation time of 10 seconds, the
engine parameters were such that the engine was considered to be accelerating.
Therefore, the Simulink model boosted the pulse width for a brief period of time (0.3
seconds) to give the engine a little extra power to increase speed quickly. After the
acceleration boost period ended (0.3 seconds later), the pulse width increased to a slightly
greater value than before the acceleration began. This increased pulse width is a result of
the increased manifold air pressure after the acceleration. The model maintains this pulse
width until the simulation time reaches 21 seconds. At that time, the Simulink model
experiences a deceleration period for 1 second. As a result of the engine decelerating, the
model reduces the pulse width, because less fuel is required. Once the deceleration
period is finished, the Simulink model resumes the cruising pulse width.
59
13
12
11
10
9
PW
AFR
8
7
6
5
4
0
5
10
15
20
25
30
35
Simulation Time (s)
Figure 5.17: Simulated Results Graph for an Engine Responding to Cranking,
Acceleration and Increasing Engine Speed
The graph above displays the predicted response of MegaSquirt subjected to a
constant increase in engine speed from 0 to 3000 RPMs and a brief acceleration period.
The Simulink model calculates the pulse width to be greater for the first 3 seconds,
because that is the amount of time it takes for the engine to pass through the cranking
phase of engine operation. After the three second mark, the engine speed slowly
increases without much effect, because the engine speed is not great enough yet to
drastically influence the required pulse width. As happened in the previous graph, at 10
seconds the engine experiences a sudden acceleration, which is why there is a drastic
boost in pulse width for a brief time. After 16 seconds of simulation time, the engine
speed has finally reached a value great enough to start impacting the resultant pulse
60
width. As a result of increased manifold air pressure and increasing engine RPMs, the
pulse width increases with time.
61
13
12
11
10
9
PW
AFR
8
7
6
5
4
0
5
10
15
20
25
30
35
Simulation Time
Figure 5.18: Simulated Results Graph for an Engine Responding to Cranking, Warm Up,
Acceleration and Increasing Engine Speed
The sample real-time response plot above displays the Simulink model’s
predicted response of a MegaSquirt ECU subjected to cranking, warm up, acceleration
and increasing engine speed. This plot basically encompasses everything that was
possible to simulate at the same time from the previous few sample plots. The curved
lines in this graph as opposed to the straight lines in the previous graph are due to the
warm up enrichment boosting the pulse width throughout the simulation. This graph
represents the predicted response of the MegaSquirt ECU subjected to a very common
engine scenario. Engines often go through cranking, warm up and brief idle periods
followed by an acceleration period. The fact that the resulting plot above seems
reasonable gives me some confidence that my Simulink model can simulate the real-time
responses of a MegaSquirt ECU subjected to realistic engine operations.
62
Chapter 6
CONCLUSIONS AND FUTURE WORK
6.1. Introduction
This chapter will conclude this thesis by addressing three major points. It will
examine the success of the Simulink Model and its ability to predict the response of the
MegaSquirt ECU. Then, this chapter will explain the benefits of the Simulink Model to
the University of Maine and others. Lastly, this chapter will cover future work that
should be performed to further expand the use of the Simulink Model.
6.2. Success of the Simulink Model
The Simulink Model created for this thesis was a success on multiple fronts.
According to the summary of the comparison results in the previous chapter, the average
percent difference between the MegaTune results and those of the Simulink Model was
1.852%. Based on this figure and the graphs in the previous chapter, the model can
accurately predict the response of a MegaSquirt ECU. In addition to accurately
predicting the pulse width generated by the ECU, this model can also calculate the
current theoretical air-fuel ratio (AFR) going into the cylinders on the engine. The
Simulink Model can predict both the instantaneous and real time response of the
MegaSquirt ECU as well, which makes it even more successful.
63
6.3. Benefits of the Model
There are many benefits to this new Simulink Model of the MegaSquirt ECU. As
mentioned above, the computer model can predict both the instantaneous and real-time
response of a MegaSquirt ECU, which includes the pulse width and the theoretical airfuel ratio. By inputting all the parameters into this computer model, the snowmobile
team can determine the pulse width of the injectors and the air-fuel ratio without having
to remove the ECU from the snowmobile and use the stimulator. This will save the team
time and effort during tuning work, which can often be a painstaking process. Normally,
tuning work requires a guess-and-check process, which can be somewhat abbreviated
using the stimulator, but varying the inputs to the engine manually takes time. Instead of
having to manually test the response of the ECU, my capstone team can simply subject
the Simulink Model to a sequence of engine parameters and let the model determine
which parameters yield the desired ECU response. In addition to benefiting this year’s
capstone team, the model will also be highly useful to future clean snowmobile teams
working on the Yamaha Phazer Snowmobile, because they can use the model for their
tuning work as well.
Using the model will also save my capstone team a lot of time accomplishing
their second major objective. My capstone team’s second major objective was to install a
catalytic converter on the Yamaha Phazer and ensure it works properly. In order for a
catalytic converter to function correctly, it needs to ignite. By running the engine richer
at lower engine speeds, the exhaust gases will be hotter and contain more fuel, which will
ensure the ignition of the catalytic converter. Therefore, my capstone team can use the
AFR curves generated by the model to determine the engine conditions needed for richer
64
combustion. If my team members did not have the computer model, they would have to
remove the ECU and use the stimulator to try various engine parameters until they found
some that caused the engine to burn richer. This guess-and-check method with the
stimulator would be very time consuming, and it would be impossible to simulate the
effects of certain engine operations, including acceleration and the closed-loop oxygen
sensor system. Thus, instead of removing the ECU from the snowmobile and hoping to
find the correct conditions for rich combustion, my capstone team can simply set up a
simulated engine test on the Simulink model, leave the room and come back to find out
which parameters would yield rich combustion.
The final major benefit of the Simulink model is its versatility. The model was
deliberately designed to model the MegaSquirt ECU Fuel Management System
completely. Therefore, the computer model can simulate the response of a MegaSquirt
installed on any engine which can accommodate it. Hence, the Simulink model can be
used for tuning work on other engines controlled by a MegaSquirt ECU as well. This
flexibility will enable future seniors to tackle other engine control capstone projects on
different vehicles.
6.4. Future Work
To make the Simulink Model of MegaSquirt even more useful to the clean
snowmobile project, two related and significant pieces of future work should be
completed. Knowing the theoretical air-fuel ratio going into an engine is very useful for
tuning, but knowing the response of the engine itself as a result of that air-fuel ratio is
also beneficial. At the Clean Snowmobile Competition, emissions, torque and power
output are the factors that determine a team’s score. Therefore, the next major step to
65
improve this model would be to link the air-fuel ratio going into an engine with the
expected work output, torque and emissions of that engine. To determine that link, there
are two possible approaches.
The simplest approach would be to determine the link experimentally. The
Department of Mechanical Engineering owns a dynamometer that can measure the track
torque and power output as well as an exhaust gas analyzer that can measure emissions.
These instruments log the response of a snowmobile during testing, so they can be
revisited later. MegaSquirt ECUs have on-board datalogging capabilities, so they can
store the injector pulse widths and air-fuel ratios during testing operations. Using the
logged data for engine output and input, one could determine emissions, torque and
power output as a function of pulse width and air-fuel ratio. Once this relationship is
determined, the model could be expanded to calculate engine outputs in addition to the
ECU outputs. If the model could calculate engine outputs directly, then it would be even
more useful to the clean snowmobile teams. Fortunately, this experimental work could
probably be completed in about a month, so this is a realistic objective for my team or
future teams.
The second possible method would be to determine the link theoretically. One
would need to create a thermodynamic model of the snowmobile’s internal combustion
engine. Once that was complete, a model of the catalytic converter and one of the track
energy losses would also need to be constructed. Linking these three other models with
the Simulink Model of the ECU would enable future clean snowmobile teams to
determine the theoretical response of the engine at various modes of operation. This
approach is clearly more involved than the previous one, but the resulting model would
66
be more versatile. This model could be easily adapted for different engines, because the
thermodynamic principles of an engine do not change from one engine to the next.
Therefore, if a future student has the time to invest in a comprehensive snowmobile
model, including catalytic converter and track losses, then creating this model is the most
beneficial option.
67
REFERENCES
Bowling, B. and Grippo, A, MegaSquirt Electronic Fuel Injection Computer,
<http://www.megasquirt.info/> (accessed 27 March 2007).
Hartman, J., 2003, How to Tune and Modify Engine Management Systems, Motorbooks
International, St. Paul, MN.
Intel, Engine Control Overview, <http://www.intel.com/design/auto/engback.htm>
(accessed 27 February 2007).
Lakin, J., Interview, Falmouth, ME, March 2007.
Nice, K., How Car Computers Work, <http://www.howstuffworks.com/carcomputer.htm> (accessed 27 February 2007).
The Mathworks, Inc, 2002 a, Learning MATLAB 6.5.
The Mathworks, Inc, 2002 b, Learning Simulink 5.
The Mathworks, Inc, 2007 a, Getting Started with MATLAB 7.
The Mathworks, Inc, 2007 b, Using Simulink 6.
68
APPENDICES
69
Appendix A
INPUT PARAMETER KEY
The tables on the following pages are designed to list and explain the input blocks and tables used in the Simulink Model.
These tables include the name of the input block/table, the units required for values entered into the blocks, and a brief description of
how the input is used in the model. The color indicated for each input block designates the type of input. Blue input blocks/tables are
engine properties or tuning parameters, whereas orange input blocks are engine operation parameters. The blocks are listed in
ascending order of their respective MegaTune Reference Numbers. These reference numbers refer to the numbered inputs specified in
the MegaTune Screen Shots displayed in Appendix B. When a value is entered into a numbered input box in one of the MegaTune
Windows, the user must enter the same value into the Simulink input block corresponding to the same reference number. Users of this
Simulink Model should use this input key and the Screen Shots in Appendix B to ensure they enter the correct values into the correct
input blocks.
70
Table A.1: Key for Simulink Model Block Inputs
MegaTune
Block Name:
Units: Reference
Number:
BAROCORR
unit
ON/OFF
less
2
RPMC
rpm
3
unit
BAROMAX
less
4
unit
BAROR
less
5
IOT
ms
6
BATFAC
ms/V
7
unit
DIVIDEPULSE
less
10
INJECTOR
unit
STAGING
less
11
unit
NYCL
less
12
Description of Input:
Indicates whether MegaSquirt will correct for barometric pressure at start up
Maximum engine speed (RPM) for engine to be considered cranking
Maximum barometric correction factor boost (value used if the engine is at vacuum)
Determines how much to correct for barometric pressure changes (Uses MAPSTART)
Injector Open Time: Time it takes for an injector to fully open
Battery Voltage Correction Factor: accommodates for varying battery voltages
Number of injections per engine cycle
Indicates what type of injector staging the engine uses
Number of cylinders in the engine
CWU
CWH
TPSVFC
ms
ms
%
14
15
16
ASE
%
unit
less
unit
less
unit
less
17
Pulse width at a coolant temperature of -40oF for cranking mode
Pulse width at a coolant temperature of 170oF for cranking mode
TPSV Flood Clear Threshold: A value greater than this will consider the engine flooded
After Start Enrichment: Increases warm-up enrichment until number of ignitions is
greater than NICMAX
18
Number of Ignition Cycles for which ASE is applied
19
%
%
F
21
22
23
Indicates what type of O2 sensor is being used
Ignition Events Per Step: How many ignitions occur before checking O2 sensor
readings
Amount oxygen sensor factor is increased or decreased depending on O2 sensor
readings
(EGOLIMIT + 100) = Maximum value of the oxygen sensor correction factor permitted
Minimum Coolant Temperature for O2 sensor readings to be processed
NICMAX
WIDE/NARROW
BAND
IEPS
EGOSTEP
EGOLIMIT
CLTMIN
20
71
Color:
RPMMIN
rpm
24
%
kPa
%
kPa/s
%/s
s
25
26
29
30
31
32
DFA
ACCELTAPER
%
s
33
34
CAUD
ENDPW
CM
BATT
ms
ms
%
V
35
36
37
N/A
Minimum engine speed (RPM) for O2 sensor readings to be processed
Maximum Throttle Position Sensor Voltage percentage for O2 sensor readings to be
processed
Maximum Manifold Air Pressure for O2 Sensor readings to be processed
Percentage position of slider on MSII Acceleration Wizard
Minimum rate of change of MAP required for acceleration boost to occur
Minimum rate of change of TPSV required for acceleration boost to occur
Amount of time the acceleration boost will stay at full value
Deceleration Fuel Amount Percentage: Decreases amount of fuel injected when
decelerating
After ACCELTIME, the acceleration boost will decrease linearly for this amount of time
Cold Temperature Add-On Enrichment: Increases the acceleration boost if the engine
is cold
Final value of acceleration boost added to the pulse width before the boost shuts off
Cold Acceleration Multiplier: Increases acceleration boost if the engine is cold
Supply Battery Voltage Reading
in3
oF
V
V
oF
lbm/hr
kPa
kPa
rpm
N/A
N/A
N/A
N/A
N/A
N/A
N/A
N/A
N/A
Engine Size (Cubic Inch Displacement)
Coolant Temperature
O2 Sensor Voltage Output
Stoichiometric O2 Sensor Output (typically half of the max O2 sensor voltage output)
Intake Air Temperature
Injector Flow Rate
Manifold Absolute Pressure
Manifold Absolute Pressure at Start Up (Used to determine barometric pressure)
Engine Speed (Revolutions Per Minute)
s
%
N/A
N/A
Step Size specified in the Simulation Configuration Parameters Window in Simulink
Throttle Position Sensor Voltage Percentage
TPSVMAX
MAPMAX
ACCWGT
MAPDOT THRES.
TPSDOT THRES.
ACCELTIME
CID
CLT
EGO
EGOSTOICH
IAT
INJFLOW
MAP
MAPSTART
RPM
SIMULINK STEP
SIZE
TPSV
72
Table A.2: Key for Simulink Model Table Inputs
MegaTune
Table Name:
Units:
Reference
Number:
AEMAP Table
ms,
Interpolation
kPa/s
26
AETPS Table Interpolation ms, %/s
25
VE Table Interpolation
%
N/A
Warm-Up Table
Interpolation
%
11
Description of Input:
MAP-Based Acceleration Table: Used to calculate acceleration boost based on MAP
TPS-Based Acceleration Table: Used to calculate acceleration boost based on TPS
Volumetric Efficiency Table: Used to calculate pulse width based on MAP and RPM
Warm-Enrichment Values: Used to increase pulse width when engine is cold
73
Color:
Appendix B
MEGA TUNE SCREEN SHOTS
The MegaTune screen shots displayed below are designed to be used in
conjunction with the Input Parameter Key in Appendix A. Some of the input boxes in
these MegaTune windows are labeled with a number. These numbers correspond to the
“MegaTune Reference Number” associated with each Simulink input block listed in the
Input Parameter Key. If a value is entered into one of these numbered MegaTune boxes,
then the same value must be entered in the Simulink input block with that MegaTune
Reference Number. Users of the Simulink Model should use the input key and these
screen shots to ensure they enter the correct values into the correct input blocks.
1
2
3
Figure B.1: General Settings Window in MegaTune
74
4
5
Figure B.2: Sensor Calibration Window in MegaTune
6
7
Figure B.3: Injector Characteristics Window in MegaTune
75
8
9
10
11
12
Figure B.4: Injection Control Window in MegaTune
76
13
14
15
16
17
18
Figure B.5: Warm Up Wizard Window in MegaTune
19
20
21
22
23
24
25
26
Figure B.6: EGO (Oxygen Sensor) Control Window in MegaTune
77
27
28
29
30
31
32
33
35
37
34
36
Figure B.7: Acceleration Wizard Window in MegaTune
Figure B.8: Real-Time Output Display Window in MegaTune
78
Appendix C
INSTRUCTIONS FOR USING THE “SIMULINK
MODEL OF MEGASQUIRT II V3”
BACKGROUND OF THE MODEL:
The “Simulink Model of MegaSquirt II V3” is designed to allow a vehicle operator to
predict the response of MegaSquirt II V3’s ECU according to its inputs. This model was
originally created to assist a team of students who installed a MegaSquirt system on a
2007 Yamaha Phazer Snowmobile. However, this Simulink program can be used for any
application of the MegaSquirt II system. Since the program is written in Simulink, a
person desiring to use the model will need to obtain a copy of MATLAB v. 6.0 or higher
(not the Student Version).
Before this model was created, the programmer carefully researched the openarchitecture of the MegaSquirt ECU’s on-board code. The logic and equations used by
the MegaSquirt system were unveiled using the help documents on MegaSquirt’s
webpage and by reading the C code with which the ECUs are programmed. Once this
theory was obtained, it was used as the foundation to create the Simulink model. The
Simulink model encompasses all of these equations and logic in an effort to model the
ECU’s response as closely as possible.
OVERVIEW OF THE MODEL:
There are two versions of the “Simulink Model of MegaSquirt II:” a Real Time Version
and a Snap Shot Version. These two files have similar code, but are designed for
different purposes. The Snap Shot Version is saved as a file named snapshotmodel.mdl.
This program was created primarily for testing and calibrating purposes. It was designed
to compare pulse width results with MegaSquirt’s tuning software called MegaTune.
This program is designed to predict the resulting pulse width of the ECU at an instant in
time without regard to variables that change as time goes on. This model can account for
some variables that change as time increases, but it is not as accurate as the Real Time
Version. The Real Time version is saved as realtimemodel.mdl. This program is
designed to simulate real-time operation of the ECU over a period of time. It will
account for all the variables that change as time increases, and the results can be
displayed by opening the PW Scope in the model itself. For accurate simulations, use the
Real Time Version.
INSTRUCTIONS FOR USING THE MODELS:
Inputs:
79
There are a number of inputs in both the Simulink models. Please read the instructions
below for a general explanation of the inputs. Then, use these instructions and the files
called “Input Parameter Key” and “MSII Screen Shots and Figures” to help you fill in the
correct information.
Input Blocks:
The input blocks are colored either orange or light blue. The light blue blocks are engine
properties or tuning parameters. These input values the user specifies in MegaTune and
downloads (burns) to the ECU. These values do not change with respect to time, they
only change if the user changes them and re-downloads the information to the ECU.
Examples of these parameters include Engine Size, Number of Cylinders, and Threshold
Limits for Pressure and Throttle Sensors.
The orange blocks are engine operation parameters and represent input values that the
engine sensors output and send to the ECU. These values can change with respect to
time as the engine operates and include parameters such as manifold absolute pressure,
throttle position sensor voltage and engine speed. When using the Real Time Version,
these blocks can be changed to more involved signal generators, including ramps, steps,
etc, because these varying signals are more similar to real-time engine operation values
than simple constants.
Input Tables:
In addition to input blocks, the Simulink model requires the user to input values into four
tables. Like the light blue input blocks, these tabulated values do not change as the
engine operates, so they only need to be changed if new information is burned to the
ECU. To edit the tables in this program, one has to use the “Look-Up Table Editor”
feature. On the main screen of the program, click on “Tools” on the menu bar up top.
Then, select “Look-Up Table Editor.” In the look up table editor, there is a file tree on
the left. Expand that file tree until you find all tables that can be edited. To edit a table,
simply click on it in the file tree and it will appear in the window to the right of the file
tree. Then, you can simply type the new values into the cells of the table. DO NOT
CHANGE THE BREAKPOINT ENTRIES UNLESS YOU CAN CHANGE THEM IN
MEGATUNE (ONLY: AEMAP, AETPS, VE). Once all the values have been updated in
a table, click on the button called “Update Block.” Move onto the next table and repeat
the process until all the tables are updated. Once all the tables are updated, you can close
the “Look-Up Table Editor” window. NOTE: The tabulated input values must be entered
into the MATLAB tables in ascending order. Sometimes MegaTune will display the
tables in descending order, but they must be entered into MATLAB in ascending order.
***Before running the program, be sure to enter all the input values correctly
(check units). Also, save the program with a new name once all the inputs are
complete and before you run it.***
Outputs:
There are several red output displays and scopes incorporated into the Simulink models.
The final two outputs of the model that the user is likely concerned about are the final
80
pulse width (PW) and the air-fuel ratio (AFR) values from the main screen of the
program. The other display blocks and scopes nested inside the models are included to
enable a user to check values easily if the final output seems erroneous.
Debugging:
If you encounter a resultant pulse width of zero or a value that seems far off, then open
the subroutine blocks and compare the results of each component of each subroutine to
ensure that those mini-results agree with what MegaTune says you should be getting. If
you find an error there, try to figure out what is wrong. If you can’t find the error there,
then consult someone with more Simulink experience.
81
Appendix D
EQUATIONS BEHIND THE SIMULINK MODEL OF
THE MEGASQUIRT II V3 ECU
Introduction:
The variables presented in this section are named according to how they are presented in
the Simulink computer model. Some of the equations presented in this section are not
simplified, because the programmer wanted to use the exact equations used in
MegaSquirt to be able to check the model easily. To understand how these variables are
entered into MegaSquirt using MegaTune, please use the Input Parameter Key.
MegaSquirt’s Air-Fuel Ratio Equation:
MegaSquirt utilizes the following equation to calculate the air-fuel ratio (AFR) that is
going into an engine. This calculation is not used to control engine operation; rather it is
computed only for tuning purposes and stored in the ECU datalogs. MegaSquirt
calculates and logs the AFR values, because they enable the user to have a better
understanding of how the engine was operating at a given time.
VE
 MAP  CYLDISP
100
 MM a
5


R   IAT  32   273 
ma
9


AFR 

mf
PW  INJFLOWM
Where:
VE = Volumetric Efficiency Correction Factor, which accommodates for the change in
air volume as the engine’s manifold air pressure and speed change
MAP = Manifold Air Pressure, which is the pressure of the air before it enters the
cylinders
CYLDISP = Volume of one cylinder in metric units (L)
R = Ideal Gas Constant (8.314351 J/mol-K)
IAT = Intake Air Temperature (oF)
MMa = Molecular Mass of Air (28.97 g/mol)
PW = Injector Pulse Width (ms)
INJFLOWM = Injector Flow Rate in Metric Units (kg/s)
MegaSquirt’s Cranking Fuel Equation:
MegaSquirt uses this algorithm to determine the injector pulse width when the engine is
cranking. The engine is considered to be cranking when the RPM are less than the
maximum cranking RPM value specified in MegaSquirt, a variable named RPMC in the
Simulink Model.
82
IF TPSV<TPSVFC:
PW  CWU 
CLT  40
 (CWH  CWU )
170  40
Where:
TPSV = Throttle Position Sensor Voltage percentage
TPSVFC = Throttle Position Sensor Voltage percentage Flood Clear threshold
PW = Injector Pulse Width, which is how long the injector remains open to insert
fuel (ms)
CWU = Pulse width at -40oF (ms)
CWH = Pulse width at 170 oF (ms)
CLT = Coolant Temperature (oF)
IF TPSV<TPSVFC:
PW = 0.3
MegaSquirt’s Fueling Equation:
MegaSquirt uses the equation below to determine the final pulse width of the fuel
injectors in an operating engine. This computation is done in real-time as the engine
operates, and it is designed to allow the ECU to accommodate for an engine that is not
running stoichiometrically. To understand how the various terms are calculated, please
see the different sections below.
PW  REQFUEL 
VE MAP

 E  DFP  ACCEL  MIOT
100 100
Where:
PW = Injector Pulse Width, which is how long the injector remains open to insert fuel
(ms)
REQFUEL = Pulse Width required for the engine to burn stoichiometrically (ms)
VE = Volumetric Efficiency Correction Factor, which accommodates for the change in
air volume as the engine’s manifold air pressure and speed change
MAP = Manifold Air Pressure, which is the pressure of the air before it enters the
cylinders
E = Enrichment Coefficient, which accommodates for a cold engine, changes in
atmospheric conditions and the oxygen sensor readings
DFP = Deceleration Fuel Percentage, which accommodates for the decreased amount of
fuel needed when decelerating
ACCEL = Acceleration Add-On, which increases the pulse width due to higher fuel
needs when accelerating
MIOT = Modified Injector Open Time Add-On, which accounts for the physical limits
of how long an injector takes to open and any changes in battery supply voltage to
the ECU itself
MegaSquirt’s Required Fuel Equation:
83
MegaSquirt utilizes the following equation to calculate the required injector pulse width
for an engine to burn stoichiometrically. This calculation is done before the ECU is
linked to the engine, and the resulting required fuel constant is burned to the ECU, so it
does not change with real-time operation.
REQFUEL 
CID  36  10 6  4.1453  10 5
NCYL
 0.1 
 INJECTORST AG
NCYL  INJFLOW  14.7
DIVIDEPULSE
Where:
CID = Cubic Inch Displacement of the engine (in3)
36E6 = Number of tenths of a millisecond in an hour (used for unit conversion)
4.1453E-5 = Air density at stoichiometric conditions (Air Pressure = 100 kPa, Air
Temperature = 70 oF) (lbm/in3)
NCYL = Number of Cylinders in the engine
INJFLOW = Injector Flow Rate (lbm/hr)
14.7 = Stoichiometric air-fuel ratio
0.1 = Conversion factor from tenths of a millisecond to milliseconds
DIVIDEPULSE = Number of injections per engine cycle
INJECTORSTAG = Injector Staging, which is how the injectors are fired (alternating or
simultaneous)
MegaSquirt’s Volumetric Efficiency Coefficient Equation:
The Volumetric Efficiency Coefficient (VE value) is simply a 2D Interpolated valued
from the Volumetric Efficiency Table stored in MegaSquirt and the Simulink Model.
The inputs to this table are RPM and MAP.
MegaSquirt’s Enrichment Coefficient Equation:
MegaSquirt utilizes the following algorithm to calculate the Enrichment Coefficient (E)
used in the fueling equation. The Enrichment Coefficient accommodates for an engine
that is warming up, oxygen sensor readings and changes in atmospheric conditions.
These calculations are done in real-time operation. See below for the equations used to
determine the other variables used in this equation.
E
WARMUP 02CLOSEDLOOP AIRCORR BAROCORR



100
100
100
100
Where:
E = Enrichment Coefficient
WARMUP = Warm Up Coefficient
O2CLOSEDLOOP = Oxygen Sensor Coefficient
AIRCORR = Air Density Correction Coefficient
BAROCORR = Barometric Pressure Correction Coefficient
Determining WARMUP:
IF NIC<NICMAX:
84
WARMUP  WE1 
CLT  T1
NIC 

 (WE 2  WE1 )  ASE  1 

T2  T1
 NICMAX 
Where:
CLT = Coolant Temperature (oF)
T1 = Temperature just below CLT in the Warm Up Enrichment Tables (oF)
T2 = Temperature just above CLT in the Warm Up Enrichment Tables (oF)
WE1 = Warm Up Enrichment value at T1
WE2 = Warm Up Enrichment value at T2
ASE = After Start Enrichment percent value, which increases the fuel for the first
NICMAX ignitions
NIC = Number of Ignitions
t
1
NIC 
  RPM , t = time elapsed
120 0
NICMAX = Number of Ignition Cycles the After Start Enrichment percent is
applied
IF NIC≥NICMAX:
WARMUP  WE1 
CLT  T1
 (WE 2  WE1 )
T2  T1
Where:
CLT = Coolant Temperature (oF)
T1 = Temperature just below CLT in the Warm Up Enrichment Tables (oF)
T2 = Temperature just above CLT in the Warm Up Enrichment Tables (oF)
WE1 = Warm Up Enrichment value at T1
WE2 = Warm Up Enrichment value at T2
Determining O2CLOSEDLOOP:
MegaSquirt and the Simulink model use the following algorithm to determine the
Oxygen Sensor Coefficient.
O2CLOSEDLOOP = 100
DO WHILE TPSV<TPSVMAX:
DO WHILE CLT>CLTMIN:
DO WHILE RPM>RPMMIN:
DO WHILE MAP<MAPMAX:
IF NEC = IEPS:
IF O2CLOSEDLOOP<(100+EGOLIMIT):
IF EGO<EGOSTOICH:
IF NARROWBAND O2 SENSOR:
O2CLOSEDLOOP = O2CLOSEDLOOP+EGOSTEP
IF WIDEBAND O2 SENSOR:
O2CLOSEDLOOP = O2CLOSEDLOOP-EGOSTEP
85
ELSE:
O2CLOSEDLOOP = 0 (Error)
IF EGO>EGOSTOICH:
IF NARROWBAND O2 SENSOR:
O2CLOSEDLOOP = O2CLOSEDLOOP-EGOSTEP
IF WIDEBAND O2 SENSOR:
O2CLOSEDLOOP = O2CLOSEDLOOP+EGOSTEP
ELSE:
O2CLOSEDLOOP = 0 (Error)
IF EGO=EGOSTOICH:
O2CLOSEDLOOP = O2CLOSEDLOOP
IF O2CLOSEDLOOP = (100+EGOLIMIT):
IF EGO<EGOSTOICH:
IF NARROWBAND O2 SENSOR:
O2CLOSEDLOOP = O2CLOSEDLOOP
IF WIDEBAND O2 SENSOR:
O2CLOSEDLOOP = O2CLOSEDLOOP-EGOSTEP
ELSE:
O2CLOSEDLOOP = 0 (Error)
IF EGO>EGOSTOICH:
IF NARROWBAND O2 SENSOR:
O2CLOSEDLOOP = O2CLOSEDLOOP-EGOSTEP
IF WIDEBAND O2 SENSOR:
O2CLOSEDLOOP = O2CLOSEDLOOP
ELSE:
O2CLOSEDLOOP = 0 (Error)
IF EGO=EGOSTOICH:
O2CLOSEDLOOP = O2CLOSEDLOOP
ELSE:
O2CLOSEDLOOP = O2CLOSEDLOOP
ELSE:
O2CLOSEDLOOP = O2CLOSEDLOOP
ELSE:
O2CLOSEDLOOP = O2CLOSEDLOOP
ELSE:
O2CLOSEDLOOP = O2CLOSEDLOOP
ELSE:
O2CLOSEDLOOP = O2CLOSEDLOOP
ELSE:
O2CLOSEDLOOP = O2CLOSEDLOOP
Where:
TPSV = Throttle Position Sensor Voltage Percentage
TPSVMAX = Maximum Throttle Position Sensor Voltage that O2CLOSEDLOOP will
change
CLT = Coolant Temperature (oF)
86
CLTMIN = Minimum Coolant Temperature that O2CLOSEDLOOP will change (oF)
RPM = Engine Speed (Rotations Per Minute)
RPMMIN = Minimum RPM that O2CLOSEDLOOP will change
MAP = Manifold Air Pressure (kPa)
MAPMAX = Maximum Manifold Air Pressure that O2CLOSEDLOOP will change
(kPa)
NEC = Number of Engine Cycles Counter (increases by one from 1 to IEPS then resets
to 1)
IEPS = Ignition Events Per Step, which is the number of ignition events the ECU counts
before reading the O2 Sensor
EGOLIMIT = Maximum value O2CLOSEDLOOP is permitted to reach
EGO= O2 Sensor Output (V)
EGOSTOICH = O2 Sensor Output when the engine is burning stoichiometrically (V)
EGOSTEP = Amount O2CLOSEDLOOP is increased or decreased if necessary
Determining AIRCORR:
AIRCORR 
(70  459.7)  100
IAT  459.7
Where:
IAT = Intake Air Temperature (oF)
Determining BAROCORR:
IF BAROCORR ENABLED:
BAROCORR  BAROMAX 
BAROR  MAPSTART
100
Where:
BAROMAX = BARCORR value for operating in a vacuum (max reading)
BAROR = Rate of decrease of BAROCORR as MAPSTART increases
MAPSTART = Barometric Pressure at start up
ELSE:
BAROCORR = 100
MegaSquirt’s Deceleration Fuel Percentage Equation:
MegaSquirt utilizes the following equation to calculate the Deceleration Fuel Percentage.
This computation is done in real-time as the engine operates, and it is designed to
accommodate for the reduced amount of fuel required for a decelerating engine.
IF –TPSR>TPSDOT THRES:
IF RPM<1500:
DFP = DFA*0.01
ELSE:
DFP = 1
ELSE:
87
DFP = 1
Where:
TPSR = Throttle Position Sensor Rate of change
TPSDOT THRES = Minimum TPSR required for deceleration reduction to occur
RPM = Engine Speed (Rotations Per Minute)
DFA = Deceleration Fuel Amount, which is the user specified percent that the pulse
width will be reduced to when the engine is decelerating
MegaSquirt’s Acceleration Add-On Equation:
MegaSquirt uses the algorithm below to determine the Acceleration Add-On. This
computation is done in real-time as the engine operates, and it is designed to allow the
ECU to accommodate for an engine that is accelerating.
IF TPSR>TPSDOT THRES:
IF MAPR>MAPDOT THRES:
IF TIME<ACCELTIME:
AE CM
ACCEL 

 CA
100 100
Where:
AE  AETPS  ACCWGT  AEMAP  (100  ACCWGT )
CAUD
CA 
 (170  CLT )
210
IF ACCELTIME<TIME<ACCELTAPER:
ACCEL  ACCEL 
ENDPW  ACCEL
 (TIME  ACCELTIME )
ACCELTAPER
IF TIME>(ACCELTIME+ACCELTAPER):
ACCEL = 0
ELSE:
ACCEL = 0
ELSE:
ACCEL = 0
Where:
TPSR = Throttle Position Sensor Rate of change
TPSDOT THRES = Minimum TPSR required for acceleration boost to occur
MAPR = Manifold Air Pressure Rate of change (kPa/s)
MAPDOT THRES = Minimum MAPR required for acceleration boost to occur (kPa/s)
TIME = Time the engine has been accelerating (s)
ACCELTIME = Amount of time the acceleration enrichment will stay at full value (s)
CM = Cold Acceleration Mutiplier
AETPS = Interpolated value from the AETPS Table
88
ACCWGT = Percentage Position of Slider on MSII Acceleration Wizard
AEMAP = Interpolated value from the AEMAP Table
CAUD = User Defined Cold Temperature Add-On Enrichment
CLT = Coolant Temperature (oF)
ACCELTAPER = Acceleration boost will decrease linearly for this amount of time after
TIME>ACCELTIME
ENDPW = Final value of acceleration boost to the PW before the boost shuts off
MegaSquirt’s Modified Injector Open Time Add-On Equation:
MegaSquirt uses this equation to determine the Modified Injector Open Time Add-On.
This computation is done in real-time as the engine operates, and it is designed to allow
the ECU to accommodate for the physical limits of the injectors as well as any change in
supply battery voltage.
MIOT 
1 
132  10  BATT 
 10  IOT  60  BATFAC 

10 
60

Where:
IOT = Injector Open Time (ms)
BATFAC = Battery Voltage Correction Factor
BATT = Battery Voltage (V)
89
Appendix E
AFR UNCERTAINTY CALCULATION
The following derivation was used to calculate the theoretical air-fuel ratio uncertainty.
The method used for calculating the uncertainty was the Kline-McClintock method. This
uncertainty calculation accounts only for the possible induced uncertainty in the predicted
pulse width of the injectors.
This derivation begins with the equation used to calculate AFR presented in Appendix D:
VE
 MAP  CYLDISP
100
 MM a
5


R   IAT  32   273 
ma
9


AFR 

mf
PW  INJFLOWM
(E.1)
Next, the general Kline-McClintock uncertainty equation is used:
w AFR
 AFR
 
 wm a

m
a

  AFR
  
 wm f
 m
f
 
2




2
(E.2)
Since this derivation only accounts for the uncertainty in the PW, which only affects mf:
wma  0
(E.3)
Therefore,
w AFR 
AFR
 wm f
m f
(E.4)
AFR  ma

2
m f
mf
(E.5)
where,
and,
m f
 m f
 

 
 wPW   
 wINJFLOW M 
 PW
  INJFLOWM

2
wm f
90
2
(E.6)
Since this analysis is only considering the uncertainty in PW:
wINJFLOW M  0
(E.7)
Therefore
wm f 
m f
PW
 wPW  INJFLOWM  wPW
(E.8)
Based on the results from Chapter 4, the uncertainty in PW is
wPW  0.01852  PW
(E.9)
Substituting Equation E.9 into E.8 yields
wm f  0.01852  PW  INJFLOWM
(E.10)
Substituting Equations E.10 and E.5 back into E.4 and doing some algebra yields
wAFR  0.01852  AFR
(E.11)
Sample Calculation:
For a predicted stoichiometric air-fuel ratio (AFR) of 14.7, the uncertainty would be:
wAFR  0.01852 14.7  0.272
Thus, the Simulink Model would predict the AFR of stoichiometric combustion to be in
the range:
AFR = 14.7 +/- 0.272 or 14.428 to 14.972
91
Appendix F
ORIGINAL TABULATED COMPARISON DATA
Table F.1: Engine Variable Comparison Data
RPM
2000
3000
4000
5000
6000
7000
8000
9000
10000
11000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
CLT
170
170
170
170
170
170
170
170
170
170
30
50
70
90
110
130
150
170
190
210
170
170
170
TPSV
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
10
20
30
IAT
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
EGO
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
MAP
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
BATT
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
92
BATFAC
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
SIM PW
5.7297
6.4152
7.0115
7.4891
7.9095
8.1593
8.3116
8.403
8.3421
8.1974
11.419
10.505
9.7009
9.0794
8.7503
8.4579
8.3604
8.3116
8.3116
8.3116
8.3116
8.3116
8.3116
MEGA PW
5.633
6.304
6.842
7.312
7.715
7.983
8.117
8.252
8.185
8.05
11.048
10.211
9.374
8.871
8.62
8.201
8.117
8.117
8.117
8.117
8.117
8.117
8.117
% DIFF.
1.717%
1.764%
2.477%
2.422%
2.521%
2.208%
2.397%
1.830%
1.919%
1.831%
3.358%
2.879%
3.487%
2.349%
1.512%
3.133%
2.999%
2.397%
2.397%
2.397%
2.397%
2.397%
2.397%
MEGASIM
-0.0967
-0.1112
-0.1695
-0.1771
-0.1945
-0.1763
-0.1946
-0.151
-0.1571
-0.1474
-0.371
-0.294
-0.3269
-0.2084
-0.1303
-0.2569
-0.2434
-0.1946
-0.1946
-0.1946
-0.1946
-0.1946
-0.1946
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
40
50
60
70
80
90
100
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
150
150
150
150
150
150
150
30
50
70
90
110
130
150
170
190
210
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
2.5
2.5
2.5
2.5
2.5
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
20
30
40
50
60
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
93
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
8.3116
8.3116
8.3116
8.3116
8.3116
8.3116
8.3116
10.103
9.7461
9.4159
9.1097
8.825
8.5596
8.3116
8.0794
7.8615
7.6566
8.3116
8.3116
8.3116
8.3116
8.3116
8.3116
8.3116
8.3116
8.3116
8.3116
2.0768
2.733
3.4529
4.2828
5.1284
8.117
8.117
8.117
8.117
8.117
8.117
8.117
9.876
9.457
9.29
8.955
8.704
8.369
8.117
7.866
7.699
7.531
8.117
8.117
8.117
8.117
8.117
8.117
8.117
8.117
8.117
8.117
1.966
2.672
3.311
4.212
4.986
2.397%
2.397%
2.397%
2.397%
2.397%
2.397%
2.397%
2.299%
3.057%
1.355%
1.728%
1.390%
2.277%
2.397%
2.713%
2.111%
1.668%
2.397%
2.397%
2.397%
2.397%
2.397%
2.397%
2.397%
2.397%
2.397%
2.397%
5.636%
2.283%
4.286%
1.681%
2.856%
-0.1946
-0.1946
-0.1946
-0.1946
-0.1946
-0.1946
-0.1946
-0.227
-0.2891
-0.1259
-0.1547
-0.121
-0.1906
-0.1946
-0.2134
-0.1625
-0.1256
-0.1946
-0.1946
-0.1946
-0.1946
-0.1946
-0.1946
-0.1946
-0.1946
-0.1946
-0.1946
-0.1108
-0.061
-0.1419
-0.0708
-0.1424
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
49.5
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
70
80
90
100.1
110
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
13.2
13.2
13.2
13.2
13.2
8.2
9.2
10.2
11.2
12.2
13.2
14.2
15.2
16.2
17.2
12.2
12.2
12.2
12.2
12.2
12.2
12.2
12.2
12.2
12.2
94
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
6.0923
7.1349
7.2892
8.3151
9.0385
9.3151
9.1151
8.9151
8.7151
8.5151
8.3151
8.1151
7.9151
7.7151
7.5151
8.3151
8.4151
8.5151
8.6151
8.7151
8.8151
8.9151
9.0151
9.1151
9.2151
5.942
6.977
7.124
8.117
8.787
9.117
8.917
8.717
8.517
8.317
8.117
7.917
7.717
7.517
7.317
8.117
8.217
8.317
8.417
8.517
8.617
8.717
8.817
8.917
9.017
2.529%
2.263%
2.319%
2.441%
2.862%
2.173%
2.222%
2.273%
2.326%
2.382%
2.441%
2.502%
2.567%
2.635%
2.707%
2.441%
2.411%
2.382%
2.354%
2.326%
2.299%
2.273%
2.247%
2.222%
2.197%
-0.1503
-0.1579
-0.1652
-0.1981
-0.2515
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
Table F.2: Engine and Tuning Constant Comparison Data
RPM
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
8000
CLT
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
170
TPSV
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.6
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
IAT
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
150
EGO
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
MAP
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
100.1
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
BATT
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
BATFAC
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
IOT
1
1.5
2
2.5
3
3.5
4
4.5
5
5.5
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
INJECTOR
STAGING
2
2
2
2
2
2
2
2
2
2
0.5
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
95
NYCL
2
2
2
2
2
2
2
2
2
2
2
2
2
4
6
8
10
12
2
2
2
2
2
2
2
2
2
2
2
CID
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
20.45
22.45
24.45
26.45
28.45
30.45
32.45
34.45
36.45
38.45
30.45
INJFLOW
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
19.6
11.6
SIM
PW
8.3151
8.8151
9.3151
9.8151
10.3151
10.8151
11.3151
11.8151
12.3151
12.8151
4.6575
8.3151
8.2973
8.2973
8.2973
8.2973
8.2973
8.2973
5.9008
6.3801
6.8594
7.3387
7.818
8.2973
8.7766
9.2559
9.7352
10.214
13.33
MEGA
PW
8.117
8.617
9.117
9.617
10.117
10.617
11.117
11.617
12.117
12.617
4.604
8.208
8.208
8.208
8.298
8.208
8.208
8.027
5.775
6.315
6.766
7.216
7.757
8.208
8.748
9.199
9.649
10.19
13.163
%
DIFF.
2.441%
2.299%
2.173%
2.060%
1.958%
1.866%
1.782%
1.705%
1.635%
1.570%
1.162%
1.305%
1.088%
1.088%
0.008%
1.088%
1.088%
3.367%
2.178%
1.031%
1.380%
1.700%
0.786%
1.088%
0.327%
0.619%
0.893%
0.236%
1.269%
MEGASIM
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.1981
-0.0535
-0.1071
-0.0893
-0.0893
0.0007
-0.0893
-0.0893
-0.2703
-0.1258
-0.0651
-0.0934
-0.1227
-0.061
-0.0893
-0.0286
-0.0569
-0.0862
-0.024
-0.167
8000
8000
8000
8000
8000
8000
8000
8000
8000
170
170
170
170
170
170
170
170
170
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
49.9
150
150
150
150
150
150
150
150
150
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
99.9
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
13.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
96
2
2
2
2
2
2
2
2
2
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
30.45
13.6
15.6
17.6
19.6
21.6
23.6
25.6
27.6
29.6
11.517
10.168
9.1265
8.2973
7.6216
7.0604
6.587
6.1821
5.832
11.451
10.1
9.018
8.208
7.577
7.036
6.496
6.135
5.775
0.576%
0.673%
1.203%
1.088%
0.589%
0.347%
1.401%
0.768%
0.987%
-0.066
-0.068
-0.1085
-0.0893
-0.0446
-0.0244
-0.091
-0.0471
-0.057
Appendix G
PRINT OUTS OF MAJOR SECTIONS OF
COMPUTER MODEL
Figure G.1: Print Out of the Main Screen of the Simulink Model
97
Figure G.2: Print Out of the Cranking Subroutine of the Simulink Model
Figure G.3: Print Out of the AFR Subroutine of the Simulink Model
98
Figure G.4: Print Out of the Not Cranking Subroutine of the Simulink Model
99
Figure G.5: Print Out of the Require Fuel Subroutine of the Simulink Model
100
Figure G.6: Print Out from the Oxygen Sensor Subroutine of the Simulink Model
101
Figure G.7: Print Out from the Acceleration Subroutine of the Simulink Model
102
Figure G.8: Print Out of the Enrichment Subroutine of the Simulink Model
103
BIOGRAPHY OF THE AUTHOR
Benjamin A. Lakin was born in Portland, Maine on August 26, 1984. He was
raised in Falmouth, ME and graduated from Falmouth High School in 2003. Majoring in
mechanical engineering, Ben has a minor in mathematics. He is a member of Tau Beta
Pi, Order of Omega, and Pi Tau Sigma.
Upon graduation in May 2007, Ben plans to work as a process engineer for
Proctor and Gamble in Auburn, ME.
104
Download