czwartek, 22 września 2011

How simplest EFI works.

Let's start from scratch. How the engine works.

We'll consider a four stroke spark ignition engine. Fuel contains energy. By burning fuels we release energy from fuel. Burning fuel is hot - therefore we release the energy on the way of heat. A combustion engine is a machine, that converts energy that fuel contains, into work. To do that we need to put a mixture of fuel and air into the engine, compress it and ignite. Exploding mixture will push the piston. In a four stroke engine, the whole cycle is done in two crankshaft revolutions. It goes like this:
  1. Intake. The intake valve opens (thanks to the camshaft). Fuel and air mixture is sucked into the cylinder while the piston goes down. At the end of a intake stroke the intake valve closes.
  2. Compression. Both intake and exhaust valves are closed. The piston goes up compressing the air-fuel mixture. Before the piston reaches the top dead center (TDC), spark plug ignites the mixture.
  3. Work. Combusting mixture pushes the piston down. That's how force is generated. Naturally both valves are closed.
  4. Exhaust. Burned fuel converts into exhaust gases. We need to remove them before the new cycle beginns. Exhaust valve opens and the piston goes up pushing exhaust gases out.
How is the air fuel mixture created? 
Few years back carburetor did the job. Nowadays fuel is sprayed by injectors to the manifold, where it mixes with the air. What the EFI does is calculating time of opening fuel injector. The longer it sprays, the more fuel goes into the cylinder.

There is an important parameter called AFR. It means "Air Fuel Ratio". Petrol AFR is 14,7. That means that 1 mass unit of fuel needs 14,7 mass units of air to burn completely. Basically AFR higher than 14,7 is lean mixture, lower than 14,7 is rich mixture.
  • The lean mixture gives a better fuel efficiency. When the amount of oxygen exceeds the needed value to complete burn, petrol particles can find oxygen particles easier. There is a great chance that all particles of petrol will be burned therefore we get good fuel efficiency. However there is no way that all the oxygen particles burn so we get less power. Combusting lean mixture generates more heat. It is dangerous for the engine. The other danger thing is knocking. It occurs earlier on lean mixtures.
  • The rich mixture gives more power. There is more fuel than could be burned by the amount of oxygen in cylinder so there is a great chance, that all air will be burned. We use all air in cylinder in order to produce a maximum output. Rich mixture burns in lower temperature (I'll probably cover this in future) - which is very desirable, furthermore the possibility of knocking is minimized.
  • Stoichiometric mixture (AFR = 14,7)  is a compromise between the rich and lean mixture. The oxygen sensing in exhaust gases can be used to help keeping stoichiometric AFR.
Ignition.
Air fuel mixture is ignited by spark plug. Basically mixture is ignited before TDC. It takes a while before mixture burns out. In order to get highest pressure in the optimal point of crankshaft revolution we need to ignite it before TDC. (In some cases of huge load, spark advance must be retarded to near of TDC). The more spark advance we apply, the more power and better fuel efficiency we get, but igniting to soon results in detonations (knocking). 

In the old, mechanical ignition systems there was a fixed point of ignition. Nowadays electronic circuits can modify the spark advance on the fly depending on conditions.

So what does the engine controller do?
The simplest controller just controls amount of fuel and spark advance. Basically:

  • The more load, the more fuel.
  • The more rotation speed, the more fuel.
  • The more load, the more spark timing retardation.
  • The more rotation speed, the more spark timing advance.

Maps.
Information about injection time and spark advance are stored in maps. In most cases these are 3D maps that show a function of chosen parameter in domain of load and engine speed. Now we know how it works, don't we? ECU measures engine speed and load, checks values in maps and sets proper injection time and spark advance. But how to measure engine speed and load?

RPM - Engine speed.
There are two common ways of measuring engine speed. The first way utilizes magnetic induction while the second one utilizes Hall effect. In both cases sensors are attached near to a sprocket wheel which spins dependently to crankshaft (in most cases it's attached to camshaft). When a tooth passes the sensor, it generates an electrical signal. The ECU measures time between the signals and simple computing gives time that one revolution takes and later number of revolutions per minute.

Load.
Engine load depends on how much air fuel mixture goes into the cylinder. Simply - the load is controlled by the throttle. The wider it opens the more load gets to the engine and the engine load increases. How to measure volume of air getting to the engine?

  • You can measure air velocity. Engine load depends on air mass velocity. Air velocity and it's density is measured by thermo-anemometer, so called MAF (mass airflow sensor).
  • You can measure absolute pressure in manifold. When the throttle is closed in manifold arises big under-pressure, when throttle is wide opened under-pressure almost disappears.  Knowing the value of absolute pressure and air temperature in manifold, we can predict what mass of air can get to the cylinder. MAP (manifold absolute pressure) sensor converts value of absolute pressure to an electrical signal, that ECU can interpret.
Seems simple? Yay, it is. But in fact these aren't all things ecu must know to work properly.

Crankshaft position.
ECU must know when the piston reaches which position and in which cycle, so it can decide when to start the fuel injection and when to ignite the spark. Position is measured similarly to the engine speed and it can be measured with the same device - a sprocket wheel and a sensor. Difference between speed and position measuring is that the speed must be measured a few times per revolution (RPM can be suddenly changed - that's why there are many teeth on the wheel). But the ECU couldn't figure position from a regular sprocket, that's why one tooth is removed from the sprocket wheel. When the sensor passes larger space between teeth than regular one, ecu knows that it just passed a determined position. Now figure out why "positioning" sprocket must be attached directly to the camshaft and not the crankshaft?
Answer: crankshaft spins two times every time the camshaft makes one spin.

poniedziałek, 19 września 2011

Embedded programming - how to choose a target processor

Purpose of this blog is not a step by step tutorial, therefore I won't make a tutorial about uC's programming (besides I'm a beginner as well). If you want to program uC's I'll give you some advices:
- First of all, don't ask me or communities questions like: "What's a debugger". Most questions are answered thousands times, you just need to do the search, if you ask, you'll just be another lazy, annoying newbie.
OK. Real advices:
- Learn C programming language, its simple and efficient. "ANSI C" by Brain Kernighan and Dennis Ritchie is a good point to start. Go through this book before buying a MCU dev kit.
- Find out which uC suits you best:

  • Atmel's AVR is very popular, there is a lot of support, there is a free IDE (from Atmel?): Avr Studio (C, ASM, C++), programmer devices are simple and cheap, there are tons of sample projects, schematics, examples on the internet. A great advantage is BASIC compiler for most AVRs (called Bascom). BASIC is a great programmer's time saver in some applications, but in some cases produces slow and large output. Bascom isn't free, but there is some kind of evaluation. Avr is an 8bit uC. And it's good for beginners. Cont's of AVR:
  1. Atmel for unknown reasons, discontinued for a couple of month's production of world's most popular hobby MCU's. That increased AVR's prices incredibly. Atmel is an unreliable manufacturer.
  2. Programming devices are cheap and simple, but programming-debugging devices are quite complicated and aren't that cheap. You will need a debugger sooner or later.
  3. To be honest AVRs are becoming out of date.
  • On the other hand very popular are MCUs based on ARM core. These units are 32bits, have tons of peripherals and are a nightmare for beginners. Most manufacturers don't provide a free IDE, some have very poor support. If you choose an ARM based MCU, you should have some knowledge about uC's. Debuggers are very expensive and in fact essential. If you already know something about programming, choose it. (Later you'll have to choose between the manufacturer and between core version).
  • My advice for beginners is to choose Texas Instruments MSP430 16bit uC's. It's cheap - search for TI Launchpad dev board, this board has an integrated programmer-debugger. TI provides an Eclipse based IDE that is limited to 16k output code, but 16k is quite a lot of code. Bet you won't be able to fill a 2k space for a long time ;) MSP430 has a big community, a marvelous and clear support, you don't need anything else. TI is an excellent choice for a beginner.
  • There are many other kinds of MCU's. Microchip PIC and Motorola are very popular, but I have no experience about it. Worth mentioning is that there are thousands kinds of PIC's and that Megasquirt is based on Motorola MCU.
  • Summary: ARM based uCs seem to be the future in very advanced systems. TI offers a variety of MSP430 uCs from simple units to quite powerful ones.
- Get familiar with Assembler. It's useful. I don't mean, try to write complicated algorithms in ASM, just get familiar with it's commands and syntax. It will help you figure out how MCU works.

My gear:
  • TI Launchpad MSP430 + CCS
  • ARM Cortex M3 STM32 (STM32F103RBT) Attached to a simple dev board with fancy TFT Touch Screen (which I haven't used once ;). I must warn you, that ST provides awful and poor support. Perhaps NXP or TI would be a better choice - I'll consider this if I need a change.
  • A simple DIY contact board with couple of switches, a 2x16 HD47780 Lcd and transistors attachable for both TI and STM32 devboards.
  • ARM programmer-debugger: A copy of Amontec JTAG-Key.
  • IDE: Eclipse + Codesourcery Toolchain + OpenOCD. Very useful and totally free with no limitations.
I think that's all for today.
Cheers.


Update:

Recently I got a new devboard from ST STM32F4 and a copy of TI's BeagleBoard - DevKit8000 equipped with a Cortex A8 processor. It's a powerful processor with a huge core designed to run under control of an OS rather than bare metal like other MCUs I mentioned in this post. I am trying to make use of it.

Hello World!

Hi, I am a student of Mechanical Engineering. Issues of combustion engines control bothers me a lot so I decided to try to gain some knowledge by building an electronic engine control unit. I'll keep the project open and share experiences here.

There is already an open efi project (Megasquirt), but I think, that learning on my own mistakes is much more fun.

If you find any mistakes or have any remarks, please leave feedback.