Megasquirting My 1983 Datsun Z

When Dinosaurs Drove to Work

Back in the mid 1980’s I worked at a company called Commodore Business Machines, a company that made home computers where our annual Superbowl was the Consumer Electronics Show in Las Vegas the first week in January.

Some time in November a Datsun Z would get parked in the front lot and then not move until whatever snow mounds that got plowed over it melted sometime in early spring. Ultimately I would have it towed leaving behind a sad little pile of rust and nuts and bolts. With a bonus check in hand for finishing the newest computer on time I would go buy another used Z and repeat the cycle.

Climate Change and Rust

These days the old Datsun Z’s; 240Z, 260Z, 280Z, 280ZX, are somewhat rare, probably because they were real rust buckets even when new. After having sacrificed a few myself in search of the next home computer I set out to rescue one for old times’ sake. I really did love the car so I made it my project to restore one. Now I have a total of three Z carcasses, an engine, and a transmission all sitting out back and an almost finished Z in the garage.

Since I had torn the engine down to its bare components I took the opportunity to make some changes: increased the size of the turbocharger, increased bore and stroke of the cylinder/piston, improved the fuel distribution, and improved the flow of air with things like porting the heads and an inter-cooler.

The Need For a New ECU

All of this means that I needed to modify the way the engine mixed fuel with air to support combustion, More air means that more fuel is needed in the same amount of time. Step one was bigger fuel injectors (and bigger fuel pump, regulator, filters, sump, plumbing, etc.) and this is why I needed a programmable Engine Control Unit (ECU).engine2

From a diverse list of alternatives I chose to use a Megasquirt, a design that has heavy DIY roots. In my case I assembled the ECU myself a while back (this particular kit is from 2005). It now controls most of the vital functions in my car short of selecting what music I want to jam to.

Fuel Injected Engine

Air Through the Engine

Seen here is a block diagram of the major components that control the function of the engine and as I say in the video, it’s all about the trip the air takes through the engine. Stepping on the throttle doesn’t directly add fuel as you might think, it really opens up a gate that allows more air into the combustion chambers which the ECU then compensates for by adding the appropriate amount of fuel.


The decision on how much fuel to add is based on not only how much air, but the temperature and a sensor in the exhaust that senses how completely the fuel is being burned. Other functions such as turning on the fuel pump and controlling the idle are examples of other functions the ECU can do. In my case I am not using the new ECU to control the spark that ignites the fuel; I have left control up to the stock ECU.

How to Measure the Airflow

My original Z engine measured the air flow with an inline Volume Air Flow (VAF) sensor that actually (and unfortunately) obstructs the flow of air in the process. This works by measuring the drag force of the air moving on a spring loaded vane. We call this arcane thing “the flapper” due to the way the vane flaps open and closed while operating. As this method measures the volume, the temperature of the air is as needed to determine the mass of the air.

An alternative way of measure the flow of air is the Mass Airflow (MAF) sometimes called a hot wire sensor. The simplest description is that it measures the cooling of a heated piece of wire by measuring its change of resistance or the change of current that is required to maintain it at a set temperature. The flow of air across the wire removes the heat (think thermodynamics) and it tends to rule out the effects of temperatures as it more directly measures mass not volume.

How the Megasquirt Measures Air

veThe Megasquirt does something different from what I described above. It uses a barometric sensor and measures the air pressure in the manifold, the space where fuel and air is mixed just prior to being sucked into the cylinders.

Combining this with other inputs such as the engine speed and O2 sensor is how the Megasquirt calculates how much fuel should be injected. But it gets even better. In addition to this improved method of monitoring combustion, I am in control of the calculations the ECU is making based on these measurements. This gives me a remarkable amount of control over pretty much everything the engine is doing.

The Tuner Studio Software

The software used to configure the Megasquirt is the Tuner Studio MS by EFI Analytics. I use the paid version which has additional features such as advanced tuning based on actual driving logging and performance.

There are a slew of basic configuration parameters that need to be loaded, basically the specifics about the engine including the number of cylinders , the fuel injector flow rates and even the type of fuel being used. Ultimately we end up with a Volumetric Efficiency (VE) map that is very similar to standard Fuel/Air maps in that we program how much fuel should be injected at different speeds and loads.

Additional variables such as when to enrich or modify the fuel amount under various conditions such as engine priming , wide open throttle (aka “flooring it”), and a warm-up period. My engine injects almost twice the amount of fuel when the engine is dead cold.

Teaching an ECU

With the Tuner Studio software plugged in and running it can accumulate live results from the way the engine performs under real life conditions and creates a table of suggested modifications to the VE map, which can then be applied. This means that the final performance is optimized beyond simple calculated values, in essence it should drive better every time until all of the parameters have been balanced through the tuning process.


Dash Bling

Finally the software can be run on a laptop of built in car computer using some of the designer dashboards included or the user can design their own dashboard with a wide range of gauges available including calculated values such as fuel economy.

I note that its now also possible to use an Android device for a remote dash cluster and I have to admit that the thought of one of my old mini-tablets on the dash in HUD mode kind of sounds cool.

The Kit

I built my ECU from a kit with the exception of the processor upgrade plugin was pre-assembled (all SMT). Its based on the MC9S12C64, a 16 bit processor running at 24 MHz with 4kB or RAM and 128 kB of flash, and has a few useful addons such as PWM controller and CAN interface.megasquirt


with stimulatorAnytime you work on a system you’ll save yourself a lot of time with proper testing. In this case, removing the biggest variable — the car — is paramount. I have two different test units that plug into the “Big Ass Connector” of the ECU.

Shown here is my Megasquirt with one of the stimulators (the green PCB) available for configuring and troubleshooting. This was so much more useful than I thought it would be.


All of the stuff I talked here is for off-road usage; it is unlawful to modify anything to do with federally mandated emissions control.


97 thoughts on “Megasquirting My 1983 Datsun Z

      1. He’s also lying through his teeth if he claims he’s not driving it on public roads.

        It’s also not an issue since the car is a 1983 model and exempt from nearly any emissions regulations in almost any state – I don’t think this is even illegal in CA. Chances are with a modern catalytic converter and running well-tuned EFI, it’s probably got lower emissions than it did stock anyway.

        In short, nobody really cares.

  1. This is really cool and the megasquirt is decent and has a big community surrounding them. Yes them as there is not just one. They are working on version 4 and the 3rd version allows for upgrades to most other sub systems so he could make that datsun a coil on plug with a completely electronic managed ignition and fuel system.

    1. The reason I haven’t gone to spark management is that the Z’s of this era “rode the detonation sensor” meaning that it backed the timing off at the first indication of detonation (lean) and would hover there. I traced the circuit out a bit on the stock ECU and it is a complex analog circuit no doubt tuned to the properties of the stock det sensor.

      I have a add-on det sensor wired in but without dyno runs there isn’t a safe way to characterize how the type and placement sensor specifically indicates the danger zone.

      The alternative is to carefully tune but again that requires time on the dyno.

      Agreed that they do keep a fairly list of improvements over time.

      1. Hi Bill,
        The ford “knock sensor” measures the harmonics a few thousandths of a second after TDC on the “bang” cycle. This harmonic has a normal curve to it during normal running but as soon as that changes, the ECU retards timing assuming there is combustion happening prior to the spark event.
        On the MS3 there is a provision for adding your own knock sensor but it is a stand alone unit that feeds a signal to retard or advance timing.

        What I do at the shop is tune @ 2000 to 2500 RPM and retard until it stumbles, then I advance until ping… Divide the two extremes to find the middle and ballpark it there. I will put 2 or 3 degrees advance and use 87 octane. Hotter cams may require a few more degrees but like every build, you gotta know what you are going after before turning the first bolt.

        1. Thanks for the info. My first concern is where to place it to hear all cylinders equally or at least well. My experience with ultrasonics is that the transducer has a fairly narrow pass for its primary frequency and so specialized filtering may not be needed.

          However my biggest concern would be I am not hearing the det at all and I end up detting without knowing it.Right now in theory there is very little det so I would have to disconnect the stock unit and then run it kind of hard, at least I thought until you mentioned how you do it.

          I may carefully try this once the weather cools down, too humid to work for long in the garage right now.

          1. On v6 and v8 engines, the knock sensor is located almost always on the centerline between the cylinder banks. On a inline engine there could be multiple sensors. (one on the front, one on the back or placed between number 1 and 2/ 3 and 4).
            I say, if you are gonna tune it on a dyno anyway, you could avoid the knock sensor and have the timing curve adjusted to avoid any pre/post ignition events.

  2. The problem that I see now with megasquirt is that yes it is cheaper in kit form, but between hours spent building it and buying all the “extras” you might as well get a holley efi for what 5-10% more? As much as I love the megasquirt stuff, I think there should be a setup based on a arduino “gasp” that can do the same if not more for much less money, last I checked a full megasquirt setup can easily run you about 800bux+.

    1. Part of the equation was the fact that this was around 10 years ago when I started and a lot of the other EFI’s were for newer cars with OBD, etc. At the time the prevent EFI’s would break into the sensor loops and “lie” to the stock ECU to get it to go richer. Self-learning came later.

      Also I liked the idea of building it myself and I think it gave me a better understanding of some of the details.

      1. It’s a through-hole kit for easy assembly which is what gives it the ’70s look. Once it’s together and in the case it works like a charm so no harm. Also, this is a kit Bil picked up about 10 years ago and they have refined since then.

          1. Look at the MS3 PRO it uses GM style weather loc style connectors. Also the Mustang kits come with fords OBD2 style 104 pin or a 60 pin OBD1 style ECU connector. Unless you harvest a connector, the DSUB works…

    2. I think the microcontroller doesn’t matter all that much… as long as you have firmware that is working and fully debugged. That’s a pretty big caveat though.

      This succeeds on being the whole package: hardware to interface with the vehicle, software to give you dashboard readouts and to issue commands back to the controller, and the firmware glue that holds everything together.

    3. My megasquirt was built in aprx 2002, fitted to a mini which slowly evolved into a drag car, was used daily and clocked up a good 50,000 miles under megasquirt, never once had an issue with the d-sub connector, and liked the thro hole tech as when i changed from wasted spark to coil on plug the changes were nice and easy.

        1. sparkplugs in series so that two cylinders fire at the same time, one of them wasted because it is in the
          exhaust stroke. So a four cylinder only needs two coils and no distributer or cam sensor

        2. Wasted spark really only refers to firing spark plugs in two opposed cylinders simultaneously. Whether that is one coil shared between two cylinders or each cylinder has its own coil.

          For instance a 4 cyl with a 1-3-4-2 firing order could have separate coils for each cylinder, but fire 1 and 4 together, or 2 and 3 together, as those cylinders are 360 degrees apart meaning one cylinder is near top-dead-center compression and the other is near top-dead-center exhaust. The one firing during the exhaust stroke is “wasted”, which means it doesn’t contribute to making any power.

          A single cylinder, 4-stroke lawn mower or similar engine will often fire the plug once during each revolution which makes the spark during exhaust unneeded, but that is usually not considered wasted spark: it just simplifies the ignition system so it doesn’t need to track 720 degrees crankshaft rotation.

          1. That’s definitely still wasted spark though on the mower. it doesn’t have to be 1 coil serving two cylinders, it’s simply whenever there’s a spark occurring on the exhaust stroke as well as the compression.

  3. Nice article. Always liked the Datsun Z cars, and have been running MS (v2.2) on a Rover V8 in a kit car since 2003. “Real soon now”, I’ll be ‘nSpark ing it, as I’ve had the parts ready since 2005…

          1. It’s called “offset grinding” which moves the journal centerline further from the centre of the crank thus increasing the stroke, this requires either resized big end journals on the rods or different rods and in turn possibly different pistons.

      1. Wow! a DieZel! I remember seeing a brochure at a Datsun dealership in the late ’70’s. IIRC, it was titled “Do you really want to own a diesel?” and it proceeded to trash talk diesel engines. (Diesel fuel was cheaper per gallon at that time). A few years later I bought a 1982 Datsun 720 diesel pickup. (CD-22) Around 100K miles the rings were worn, 1 quart of oil every 700 miles.

    1. Many options. Regrinding the rod journal on the original crank can provide a slight change in the stroke. Building up the rod journals and regrinding them is another option. Often a crank from another engine in same engine family can providing an option; For example Small block Chevy 350 can be stroked buy using the crank from from a Chevy small block 400. Popular engines my have after market crankshafts made for them. In any event While it’s not difficult in theory all the options require learning all the details and paying attention to them. Clearances are very tight inside an gong the the big end of the connecting rods are flying close to the camshaft and the engine block.

      1. I used the crankshaft out of a Datsun Diesel engine known as an LD28 I believe.When done I had to still have the right compression which was accomplished with the right pistons and a different head gasket (1mm) I found several cool online resources to help calculate all of this at the time.

    1. During the ’70’s the Datsun Z-2*0s were marketed to college kids. In the early ’80’s they moved into the Corvette arena, at which point I lost interest in them (sour grapes on my part, no way could I afford the new ones).

  4. If the tailpipe emissions are within the limits of the original engine, the government shouldn’t care what is under the hood. Some states give exemption to cars over 25 years old as long as it’s not used as a daily driver.

    1. California is *special*. When Congress passed the 25 year old exemption, they left it up to the States to decide whether or not to accept it. Of course California ASAP passed their own legislation disallowing the exemption.

      Emissions controls on all vehicles and newer in California must be kept as they were when the vehicle was new. It’s actually illegal to make your old car *less polluting* in California. That’s why on those shows like “Overhaulin” they never do any vehicle newer than the late 1960’s and never ever install an aftermarket EFI system on them. Shows that did newer cars, like “Pimp My Ride” didn’t touch the drivetrain.

      In other words, it’s an utterly illogical set of laws and rules and regulations when all that should matter is the result, what comes out the exhaust pipe, not how the exhaust is made. Why not some kind of bonus for people whose vehicles are upgraded to run cleaner than when they were fresh off the assembly line?

      One thing that spurred complete adoption of fuel injection was a test CARB invented specifically to fail every vehicle with a carburetor. The Sealed Housing for Evaporative emission Determination or S.H.E.D. test. The basics are the vehicle is placed into a sealed building (or shed, haha) then the air pressure inside is lowered a small amount. The amount of fuel evaporated into the air is then measured.

      Since carburetors rely on the vacuum produced by the engine to draw fuel out of the float chamber, they naturally will have plenty of fumes go into the lower pressure air in the shed.

      1. That is pretty much what I thought, you can’t change the system unless the change is tested and approved, for example I have the CARB stickers for my cold air intake on the BMW.

      2. California is the exception and not the rule. Move to Texas and as long as it is 25 years or older, they do not care. Most inspection places do not even have an ASE master mechanic on staff. Most counties do not even test emissions and the ones that do are the metro areas.

    2. Agreed more often then not the aftermarket system is actually cleaner then what it replaced esp if new catalysts are installed.
      In fact with the newer monolithic catalytic converters a well tuned carburated setup can actually be cleaner than an EFI one still using the bead bed style catalysts.
      I read an article in hotrod magazine a few years back where someone got a big block camaro to pass emissions with no EFI,no EGR, and no airpump.

      1. Far as I know the loose bead cats were never used with fuel injection. Never saw one myself. In theory the beads were supposed to be replaceable. Pry a plug out of the bottom to drain the old out as much as would, then run the engine or blow air up the exhaust pipe to get the stragglers. Refilling involved using a vacuum on the exhaust pipe.

        In practice the cat housing wouldn’t last that long and replacing it with a straight pipe or (in CA) gutting it and welding a pipe inside was what usually happened.

        The sheer size of the things also helped eliminate them. To get enough flow through, the beads had to be spread over a large area so the gas could flow vertically through the gaps among the beads. Then came 2 and later 3 stage cats. Pretty certain the bead type were all single stage.

  5. It’s always nice to learn about things like combustion engines, but anytime I see how complicated these things are, I always wonder why we’re still bothering with all that, instead of switching to electric motors.

    Oh wait, right… Batteries. Never mind. :-)

  6. Note using MAP instead of MAF is not better, it’s just different and better systems use both a MAP sensor and a MAF sensor as you can get even more control over the combustion with information from both. There are threads out there to add both sensors to a GM7730 ECM or a megasquirt, the two most used ECM’s for car engine management hacking like this.

    Anyone doing this I really recommend using the latest megasquirt as they are far more capable and with the extra money. the MS3 on it’s own is massively superior in knock sensor and a Megasquirt3-pro is the absolute best you can get if you want a sealed and ready to go unit.

      1. flapper MAF is restrictive, hot wire not so much. The advantage of MAF is that it is a direct measurement, with MAP you need to take the temperature and varying volumetric efficiency into account

        1. MAF’s still measure temperature, the resulting fuel map is basically a map of volumetric efficiency (it’s called the VE map in MS). TBH it’s just two equally fine ways of measuring – and many modern cars use both MAF and MAP sensors.

          One issue that can hurt hotwire MAFs is oiled air filters, seen a few people kill them by fitting an oiled K&N filter.

    1. I mention this more in the video to the point where the MAF I show was good enough for a BMW M3. The MS can also do other methods such as actually using the throttle position with other parameters.

      1. I was kind of wondering why you measure all three: map, maf, and tps. I’m putting a (homebrew) distributorless electronic ignition on a (smaller) Datsun engine and had come to the conclusion that I could get by with just a TPS or just a MAP (although I have both.)

    1. If I did one on the car itself it would be a half hour video including the fiberglass work. First I started by taking an automatic and making it a manual shift (welding clutch brackets under the dash upside down) and it just goes on from there…

  7. I looked at Megasquirt some time ago and felt that it was too expensive and not truly an open system. The cost of a commercial system was not that much more for my application (1970s big block Mopar engine). It would be nice if there was an up to date open efi system out there. These days actually soldering a board is not longer necessary for DIY, it is mainly about interfacing and software. Something with a nice 64 bit CPU and/or FPGA/ASIC/PSOC would be interesting. Any suggestions?

    1. Not the sales guy but look at the MS3 pro. “not truly an open system”…. they give you the firmware and you can flash the microcontroller with code. Not sure where the “lockout” is you are suggesting. Even my MS2 has a canbus on it and there is even a prototyping area on it so I can add my own electronics.

  8. Bill, I like the video and that is a grate write up! I am a big fan of Nissan,s, I would love to see some pictures of the restoration!!!

    What I find really nice is that the dashboards that you make in TunerStudio,s dashboard designer can be downloaded to a android device, phone or table and used as one of the dashboards in Shadow Dash. I have heard of a lot of people using this setup as there dedicated dashboard in there race cars, they use a Bluetooth adapter to connect Shadow Dash to the ECU. I plan to do this in my drift car, its a 240sx S14 with a 1Jz controlled by a MS3x ECU that I built. I had a blast assembling the ECU, making the wiring harness was a bit more work and less fun but when you get your engine fired up on the ECU and wiring harness that you just assembled / made for the first time it sure does make you feel good after all that hard work!!!

    Here is a grate video to show how flexible TunerStudio,s dashboard designer is, this guy made a custom dash modeled after the Lamborghini aventador.

    This one is showing a bunch of different custom dashboards that people have made, lots of grate ides for that HUD display in the Z!

    Nice work and I hope to see some pictures of the Z!?

    1. I have an extra half hour of video showing off the cool stuff on the car. :)

      It was a stupid digital dash and I fitted it with the analog dash with 165mph speedo and redid the whole center console around a doubledin GPS/Sterio

  9. What drives the logic behind the spark plugs and fuel injectors? I assume the timings have to be spot on, so some sort of programmable logic would make sense, or do they just use microcontrollers?

    1. There is a crankshaft sensor that synchronizes all of the cylinder positions to the electronics and then timers and other techniques in the microprocessor accurately determine event times. Things like the injector open times can be fairly short and need to accurately be controlled, which is what the code is all about.

  10. Accept for school buses and random on the highway inspections of commercial vehicles Kansas has no mandatory vehicle in inspection of any kind. The exhaust behind the Cat. converter has away and fell off. The guts of the converter evidently blew out. Basically a V8 with a straight pipe. While getting tired of the noise custom exhaust of any sort behind the factory exhaust manifold cost more that the vehicle is worth. Such is life when you become disable to the point where you can’t earn a just wage and can’t do lot of work for yourself.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.