Click here for MegaSquirt® MegaManual™ Information, Guides, and Links

MegaSquirt-II GPIO General Purpose Input Circuits

In addition to dedicated variable reluctor (VR) and exhaust gas temperature (EGT) inputs (and a variety of output circuits), the General Purpose I/O (GPIO) board has five general purpose input circuits. These can be configured by the builder to operate as voltage sensing circuits, resistances sensing circuits, or hardware-debounced switch input circuits. Clever users can find other ways to configure these input circuits, of course.

Circuit
CPU Port
AMP pin
number
GPI1PAD005
GPI2PAD016
GPI3PAD0230
GPI4PAD073
GPI5PAD064

Any of the input circuits can be configured in any way, they don't all have to be the same, and not all have to be installed.

The full general purpose input circuit looks like this:

Note that on the beta boards only, the resistor R2 is not connected to the Ampseal connector. It is connected to ground at the other end. R2 is used mostly in applications that need to respond rapidly to voltage changes, such as an EGO signal. If you install R2, you should jumper it to the closest end of R1.

ComponentDefault ValuesMarkingNotes
R1
R2
R3
C1
C2

However, to make it a voltage, resistance or switch sensing circuit, you will install only some of the components.

Resistance Sensing Circuit

This circuit acts like a voltage divider. The supply voltage (5.0 Volts) is dropped to zero (ground) through R3, R1 and the variable resistance (Rv) itself. The output voltage to the processor is taken from between R3 and R1. It varies from 0 to 5 volts by the function:

Vout = Vsupply * [(R1 + Rv)/(R1 + R3 + Rv)]

Normally we want the middle of the voltage range (i.e., 2.5 Volts) to correspond roughly to the middle of the sensors most widely used range.

For example, with a GM temperature sensor, the resistance at 70°F is about 3400 Ohms, so

2.5 = 5.0 * [(2.2K + 3.4K)/(2.2K + R3 + 3.4K)]

or

R3 = (5.0/2.5) * [2.2K + 3.4K] - 2.2K - 3.4K = 8.0K - 2.2K - 3.4K = 2.4K Ohms

This explains why the standard MegaSquirt® configuration for GM temperature sensors uses a 2.49K Ohm resistor.

Software De-Bounced Switch Circuit

For a software de-bounced GPIx circuit, you can do this simply by installing R3 and jumpering the R1 location, and leaving out all the other components. For the GPOx circuit, you would leave out all the components, and jumper 'a' to 'p' (don't forget to set the port as an input). The other inputs/outputs can be jumpered similarly.

The resistor R3 limits the current flow when the switch is closed. Generally, you want to keep this to about 10 to 25 millAmps, so a value of:

R3 = Vsupply/I = 5.0/0.015 = 330 Ohms should work well.

Some users may want to de-bounce in hardware. This can be done, but requires a Schmitt trigger in addition to other components. Some of these can be installed in the existing locations, but some would have to be installed in the proto area.

Voltage Sensing Circuit

This circuit is the equivalent of the MegaSquirt® TPS voltage sensing circuit. It works well for voltages that transition smoothly. Note that R2 is not normally installed. However, in some cases where the voltage swings rapidly, installing a 1M Ohm resistor and leaving C1 out is preferable (this creates the equivalent of the MegaSquirt® EGO input circuit).

Note that if you wish to measure voltages greater than 5 volts, you must create a voltage divider. You do this by replacing C1 with a resistor. the voltage signal to the CPU is then:

Vout = Vsignal * [(R1)/(R1 + R2)]

For example, if you have a nominal 12 Volt signal (up to 15 Volts in practice), then since we want Vout to be no more than 5 Volts when Vsignal = 15, we calculate:

5.0 = 15.0 * [(R1)/(R1 + R2)]

If R1 is 1.0K Ohms, then:

R2 = (15.0/5.0) * R1 - R1 = 3R1 - R1 = 2R1 = 2K Ohms

and the current draw on the signal source is:

I = Vsignal/(R1 + R2)) = 15.0/(1.0K + 2.0K) = 5 milliAmps, which is minimal

This would be good values for a stop lamp switch input, for example.

The voltage divider method above works well if the signal voltage is known and not prone to spikes. However, it does have the disadvantage of the output voltage being a function of the input voltage. Where there are spikes in the supply, or where a more certain ON/OFF voltage is needed, or the processor port needs protection from over-voltages, a Zener diode can be used instead (in the place of C1).

A Zener diode flows current in one direction, but only flows in the other direction above a certain specified voltage. The Zener diode reverse voltage can be chosen to be 4.9 Volts, and used to shunt the signal to ground. This gives the processor 4.9 Volts whenever the signal voltage is greater than or equal to 4.9 Volts. A current limiting resistor (R1) must be used to prevent the diode from overheating.

The power dissipated by the diode will be:

P = I * VZener, in Watts

So for a typical 1.0 watt diode, with a 15 Volt supply:

P = 1.0 = I * 4.9, so the current (I) must be less than 1.0/4.9 = 204 milliAmps

This means the current limiting resistor R2 needs to be at least:

R = (Vsignal - VZener)/I = (15 - 4.9)/.204 = 50 Ohms

For maximum life, however, we would want to dissipate much less than 1.0 Watts in the diode, so lets choose 0.10 Watts instead. Then:

P = 0.10 = I * 4.9, so the current (I) must be less than 0.1/4.9 = 20 milliAmps

This means the resistor R2 needs to be at least:

R = (Vsignal - VZener)/I = (15 - 4.9)/.020 = 500 Ohms (this is Ohms Law rearranged slightly)

A 560 Ohm resistor should be fine in this case. Note that we do not want to make the current limiting resistor so high that no signal is transmitted, though this isn't generally a problem for most processor port inputs, and values up to 1K Ohm are generally okay.



©2006 Al Grippo and Bruce Bowling - All rights reserved. MegaSquirt® and MicroSquirt® are registered trademarks.