The algorithms that control the engine are quite complicated. The software has to allow the car to satisfy emissions requirements for 100,000 miles, meet EPA fuel economy requirements and protect engines against abuse. And there are dozens of other requirements to meet as well.
The engine control unit uses a formula and a large number of lookup tables to determine the pulse width for given operating conditions. The equation will be a series of many factors multiplied by each other. Many of these factors will come from lookup tables. We'll go through a simplified calculation of the fuel injector pulse width. In this example, our equation will only have three factors, whereas a real control system might have a hundred or more.
Pulse width = (Base pulse width) x (Factor A) x (Factor B)
In order to calculate the pulse width, the ECU first looks up the base pulse width in a lookup table. Base pulse width is a function of engine speed (RPM) and load (which can be calculated from manifold absolute pressure). Let's say the engine speed is 2,000 RPM and load is 4. We find the number at the intersection of 2,000 and 4, which is 8 milliseconds.
RPM

Load

1

2

3

4

5

1,000

1

2

3

4

5

2,000

2

4

6

8

10

3,000

3

6

9

12

15


4,000

4

8

12

16

20

In the next examples, A and B are parameters that come from sensors. Let's say that A is coolant temperature and B is oxygen level. If coolant temperature equals 100 and oxygen level equals 3, the lookup tables tell us that Factor A = 0.8 and Factor B = 1.0.
A

Factor A


B

Factor B

0

1.2


0

1.0

25

1.1


1

1.0

50

1.0


2

1.0

75

0.9


3

1.0

100

0.8


4

0.75

So, since we know that base pulse width is a function of load and RPM, and that pulse width = (base pulse width) x (factor A) x (factor B), the overall pulse width in our example equals:
8 x 0.8 x 1.0 = 6.4 milliseconds
From this example, you can see how the control system makes adjustments. With parameter B as the level of oxygen in the exhaust, the lookup table for B is the point at which there is (according to engine designers) too much oxygen in the exhaust; and accordingly, the ECU cuts back on the fuel.
Real control systems may have more than 100 parameters, each with its own lookup table. Some of the parameters even change over time in order to compensate for changes in the performance of engine components like the catalytic converter. And depending on the engine speed, the ECU may have to do these calculations over a hundred times per second.