Following a long discussion in this thread
, I've come up with a new spark output circuit, which is an alternative to the one currently (Apr 09) suggested by DIYAutoTune (and implemented by pretty much everybody) that involves soldering a pair of pullup resistors to D14 and D16 and then running them to the DB37.
This applies to both MS1 and MS2, and will run on any year Miata, as well as pretty much every other modern car that uses a solid-state ignition (no points) with or without a distributor, where the igniter is either external to both the coils and ECU (eg: 1.6 Miata, some DSMs) or integrated into the coils (1.8 Miata, vehicles with 3 or 4 pin COPs, some other DSMs, etc) that accept a +5 trigger input, and is driven using the LED output circuits (D14, D15, and/or D16). Apart from EDIS, I’m guessing this covers at least a simple majority of non-chainsaw/lawnmower Megasquirt users.
I’m going to start by discussing what problems that configuration creates and give some analysis as to why these problems happen, and then I’ll describe the new design and explain why it fixes them. It’s ok if you can’t follow some of the deep tech. In the examples which follow I’ll be showing the configuration for a two channel wasted-spark design, though the same basic principles hold for any number of ignition outputs wired using the LED driver circuits. I’m also assuming that you are running “Spark Output Inverted = No”. If that’s not the case, then you’re probably already covered.
What exactly are the problems with the current design?
First, as we all know, if you perform a software reflash on the MS without first unplugging your ignition coils, your igniter and/or coils get fried. Second, some people experience an issue where at initial powerup (before the starter is engaged) they encounter a backfire through the intake, due to the ignition of residual fuel introduced by a leaky injector or simply remaining in the intake or combustion chamber having been injected but not completely inhaled and exhausted at the last shutdown.
So what causes this?
In the current design, the spark outputs are the inverse of the CPU pin which is driving them. When the CPU pin is off, the output is on, and current flows through the ignition coil primary. When the CPU pin is on, the spark output is off, and no current flows through the coil. The problem is that any time there is power applied to the Megasquirt and yet the CPU is inoperative, the outputs will naturally go high. This occurs primarily on two occasions- when the CPU firmware is being reflashed and when the MS is first powered up and the CPU is in the process of booting up.
Why is the circuit set up like that?
I can’t give you a good explanation for why people started configuring this the way that they did. It’s pretty lazy from a design standpoint, dangerous (to the car) from a user standpoint, and just not very smart. But once the first person had done it, and it worked, the second person copied it, and so on and so forth, until it became the canonical method for wiring spark output drivers.
As I said earlier, the current spark output driver design is such that the state of the outputs themselves (either +5 or ground) is a mirror-image of the state of the pins on the CPU which control them. Let’s take a look at the circuit that most of us use to control the ignition outputs. This is taken from a rev 3.0 PCB, though the 3.57 is essentially identical. The “base” circuit (that which is on the PCB itself) is in red and blue, while all added modifications are in black:
The two channels shown here are mirror images of one another, so we’ll focus on just the first one for now. As you can see, we’ve added a pullup resistor, 330Ω in this case, from +5 (which is the same as Vcc) to the junction between D14 and Q6. Typically, this resistor is physicially mounted between the top terminal of the LED and the left terminal of R24, as viewed from the backside.
Now, a quick bit of quick transistor theory for the lay-persons. The transistor in position Q6 is known as an NPN transistor. It can be thought of as somewhat like a relay, where the top terminal (the collector) is the main input, the bottom terminal (the emitter) is the main output, and the terminal on the left (the base) functions like the coil. When a positive voltage is applied to the base, electricity is allowed to flow from the collector to the emitter. When no voltage (ground) is applied to the base, then electricity cannot flow from the collector to the emitter. (I can hear the EEs out there cringing at this oversimplification. Yes, transistors can be operated in a linear mode as is the case with amplifiers, but for our purposes here, they’re just on-off switches. Mmmkay?)
The wire at the very left (Squirt-1) is connected to an output pin of the CPU, and then through R26 to the base of transistor Q6. So when the CPU puts out a voltage on that pin, the transistor turns on. Now, we’ve applied +5, through a current-limiting resistor, to the collector of the transistor. The emitter is grounded. So when the transistor is on, all the power flowing through the resistor is effectively shorted to ground, and there is no voltage potential present at the collector. Since that’s where the spark output is connected (pin 36), the spark output is off.
When the CPU is no longer outputting a voltage, Q6 turns off. Since the current passing through R26 is no longer being shorted to ground through the transistor, we now have +5 present at the collector, and therefore +5 at the spark output pin.
So the problem here is that when the CPU is inactive and yet the MS is powered on, the transistors are off, and thus the spark output pins naturally go to +5, causing the coils to conduct continuously.
During a firmware reflash, the CPU is offline for a considerable period of time. Running the coil primaries continuously for this length of time has been shown over and over again to cause permanent damage to the igniters and / or ignition coils as a result of overheating if the coils are not unplugged during the process. This is of course somewhat of a major nuisance, and more than one person who “knows better” has still forgotten to unplug ‘em just that once, usually at a cost of several days’ downtime and a couple hundred dollars in new ignition components
At initial powerup, the behavior of the system is somewhat more insidious. Like any computer, the Megasquirt CPU takes time to boot up and start operating when first turned on. Not nearly as long as a desktop PC running a big OS from a hard drive, but it still has to fetch data out of EEPROM and start executing it. In the case of an MS1 CPU, it takes appx 600 milliseconds for the CPU to begin operating. During this time, power is available to the spark output drivers, and since the CPU is not asserting the relevant pins high, transistors Q6 and Q8 are off, causing the spark output wires to be at +5, and causing the coils to conduct.
As soon as the CPU “wakes up”, it immediately drives the relevant pins high, causing the transistors to turn on, shutting down the spark outputs and causing the coils to stop conducting. As you probably know, it’s at this moment (when current flow through the coil primary ceases) that the spark plugs actually fire. Any fuel which happened to already be in the combustion chamber at that time will subsequently ignite, causing the backfire which seems to plague some Megasquirt owners.
Here’s an oscilloscope capture of what happens when the MS first powers up:
(click to embiggen)
At point “A” I have applied power to the Megasquirt. The spark output driver immediately goes to +5, and remains there for the whole time that the CPU is booting. At point “B”, after appx. 600ms, the CPU has initialized, its output pins are driven high, the spark outputs turn off, and the coils fire. In this illustration I was driving the MS with a JimStim, so the CPU immediately proceeds to start generating ignition pulses as soon as the incoming crank trigger is captured and synched, which is point “C”. In your car, the outputs would simply sit there at 0v until you actually started turning the starter and achieved capture and sync of the inputs, at which point the ignition pulses would begin.
So how to we fix this?
I thought you’d never ask.
The solution is to configure the spark outputs such that they are on when the CPU’s output pins are on, and off when the CPU’s output pins are off.
We could achieve this by using a PNP transistor on the CPU output pin (PNPs have the opposite control polarity of NPNs) (edit: no, that wouldn't work)
however since NPNs are already a part of the the modkit packages of the various distributors, I’ve chosen a route which will achieve the same results at the same cost, without requiring that new devices be added to anybody’s inventory.
So essentially what I have done is to place a second set of NPN transistors after the first set, to un-invert the signals which Q6 and Q8 have inverted:
As you can see, we’re using the natural pullup of the existing LED to drive the base of the new transistor, which is connected to the collector of Q6/Q8 where the old spark output used to be. In this configuration, the output at the collector of the new transistors is exactly the opposite of what’s happening at the collectors of Q6/Q8, which is turn have always been the opposite of what’s happening at the CPU pins driving them. So, if the CPU is inactive, the spark outputs will be off.
NOTE: Having performed this modification, YOU MUST SET “SPARK OUTPUT INVERTED = YES”.
Let’s take a look at what happens when the Megasquirt powers on in this configuration:
(click to embiggen)
Again, the point marked “A” represents power to the MS being switched on. We can just barely make out a rise in the voltage at the spark output line, which represents the voltage drop across the output transistor. <tech>
All semiconductors have a small voltage drop across them when “on”. This is referred to as the forward voltage across the junction, and varies by device. In this case, the only thing connected to the spark output was the high-impedance scope probe, which is why this rise is visible. Were an actual igniter connected, the voltage would be pulled to zero and thus non-observable. </tech>
Since there is essentially no voltage here, the igniter does not activate, and no current flows through the coils.
At point “B”, the CPU has come alive, and since the ignition output was already off, nothing happens.
Finally, at point “C”, the MegaSquirt has synched to the trigger signal which the stim is feeding it, and spark output pulses commence.
Great! Let’s do it.
: That isn’t a question.
Ok, how do I build this?
First off, get yourself a pair of NPN transistors. Pretty much any small-signal NPN capable of passing 50ma or more will do. Radio Shack sells a variety-pack of NPN transistors (catalog # 276-1617) which contains a mixture of 2N2222, 2N3904 and 2N4401, and any of these will work. You can also use the PN2222A, which is commonly sold by MS vendors as a relay driver. You’ll also want a pair of pullup resistors, something in the 220-330 ohms range. ¼ watt will suffice.
The easiest place to pick up the drive signal for the new transistors is at the top pad of D14-D16, the square pad. This image depicts wiring two drivers for SparkA and SparkB, connected to pins 31 and 36 of the DB-37 on the output side. Double-check the documentation for the specific transistor you select, but generally when holding the part such that you can read the printed side, the emitter is on the left, the base in the middle, and the collector on the right.
Having done this, be sure to set your MS for “Spark Out Inverted = YES”. This will cause the “resting” state of the outputs to be off, with +5 during the dwell period, falling back to 0v at the moment of firing, just like before. You do not need to reset your timing, readjust your dwell, or anything else.
: How many roads must a man walk down?
That’s pretty much it. No more fried coils, no more popping at turn on. Prost!