It's Better With Arduino


Leave a comment

Rev Hang Fix

I forgot I hadn’t posted about how I fixed the rev hang. From what I’ve gathered it’s due to the ECU using a minimum cylinder airmass, which in turn sets a minimum throttle position. In other words, the ECU won’t close the throttle all the way to let the revs drop. It continues to add fuel and air even when the accelerator is at 0%. Unfortunately the min cylinder airmass isn’t tunable in HPT so there are two ways to solve it.

The first is to add a clutch position sensor. If one isn’t installed the ECU assumes the car is in gear (clutch pedal not pressed) all the time so the return to idle routine never runs. It also means clutch fuel cut off (CFCO) is never activated. The second is sort of a hack since we can’t lower min cylinder airmass: increasing cam overlap during the low load, low to mid RPM part of the map (IE, return to idle). This causes the cylinder to partially fill with exhaust gas before the intake valve opens, effectively reducing the air that enters the cylinder.

I implemented both solutions and I’m very happy with the results. Increasing overlap is definitely the milder approach and fixes the ~2k RPM rev hang I was having, whereas CFCO is very aggressive. Revs plummet as soon as you press the clutch, and blipping the throttle for rev-matching becomes more difficult due to the fuel ramp in/out behavior. Because of this I’ve configured a transition between the two – below 4500 RPM the valve overlap is enabled and above it CFCO is enabled. Around town the engine feels …less like it has a 60lb flywheel, and above 4500 the revs drop pretty quick. You definitely need to shift like you mean it.

Implementing the valve overlap is definitely easier since there’s no hardware to add, just change the desired exhaust cam angle during min spark reduction:

Getting the clutch position sensor to work is more involved. First, you need a sensor – I used the factory clutch position sensor because I had the car apart. The ECU provides 5V, gnd, and expects a 0-5V signal. The catch is that the ECU range checks that signal, and anything outside 10% – 90% full scale is considered a sensor failure, so the sensor needs to only use the middle 80% of its mechanical travel. Sensor wiring can be found in the latest version of my harness schematic. Assuming that’s installed and wired up you also need to enable DTC P0806 – P080A, P0831 and P0833 with MIL on first or second error. Finally, you may need to do the clutch learn procedure (VCM Scanner -> engine icon). If all goes well you should see a in/out learned position in VCM scanner:

I don’t think the “clutch position valid” bit is readable through HPT, but that’s really what we’re after (0 is valid). The message that bit is in is broadcast on the bus so you really just need to sniff the bus / add it to your dash to read it. If it’s valid you should now be able to adjust CFCO and have it take effect:

Adding the clutch position sensor is kind of a pain. I’m 99% sure we can get the same effect using the stock clutch switch and a tiny PCB. If there’s interest I can get some made, they wouldn’t be very expensive.

Anyways, hopefully this has been helpful. After typing it out I guess I’ve spent a decent amount of time fixing this issue but I think it’s worth it, it certainly makes the car feel more polished to drive. As an aside, I’ve moved my tunes to github, v15 is the one I’m using now.


Leave a comment

canGaugeDriver

It’s been a busy summer and I’ve mostly been working on things that aren’t super interesting to read about – software, tuning, etc. I did meet up with @rdb138 at VIR a few months ago and he was nice enough to give me a ride. His car is …fast around a track. Where my car feels like a stock car with a big engine (because it is), his car feels well rounded. It corners just as well as it goes. Very impressive.

I’ve been messing around with AI and HPTuners and let’s just say it’s been very helpful in understanding exactly what’s going on under the hood – both in HPTuners as well as the ECU’s software. I can now stream any ECU memory location as well as trace what that memory location does in the ECU. As an example, the clutch position sensor was always reading invalid, despite the wiring / sensor range being correct. I was able to figure out it was failing because the related DTCs were disabled. I re-enabled them and voila, no more rev hang. I was even able to get clutch fuel cut working. The ECU is basically wide open now so if you’ve got questions feel free to DM me.

Most of my time has been spent on an electronics project I’m calling canGaugeDriver. This started off as a way to drive the factory gauges but it’s evolved to be something that’ll be useful for more than just the cluster.

It’s a $26 Arduino CAN board with a baseboard I designed. The highlights:

  • 4x 0-20V analog inputs
  • 2x 0-20V digital inputs
  • 10x low side load driver channels (IE, can ground loads like lights, etc.)
  • Powered via 9-28V
  • 24-pin harness connector that contains all power, CAN, and I/O, including 2x 5V/GND connections for powering external sensors

It’s a pretty handy little board. It’ll drive the gauges like I intended (CAN->PWM) but I’m also getting a few more functions out of it:

  • Reading battery voltage / CEL status / AC request status / fuel level
  • Transmitting all of the above for my dashboard to log and display
  • Transmitting the correct messages to the ECU to turn the AC compressor on when requested

Below is a prototype behind the cluster. The final version will be a little smaller, but it shows the relative size. It fits nicely in a space to the left of the cluster.

I’ll use one to drive the cluster and another to read a few sensors in the engine bay. I believe I know enough about the ECU that I could use one to get the factory cruise control working. I won’t because, to be honest, I don’t trust any part of this for a safety critical application, plus I’d have to run another wire to the ECU. But I could!

I fully realize there are probably better commercial options available for less but I wanted to make my own. All of the hardware and software are open source in case anybody wants to make one. If there’s enough interest I could be convinced to sell a few, but that was never the intent. Here’s a quick video of it driving the tach and lights. Pay no attention to the check engine light, it’s not connected yet.

https://www.youtube.com/embed/jkze_fG8y6c?autoplay=0&start=&origin=You’ll notice the airbag light flashes for a second at first – this is my “idiot light”. It blinks when the engine is running and the oil pressure is low, coolant is hot, or battery voltage is low. It’s a way to grab the driver’s attention and tell them something is immediately wrong.

I need to wrap up a few details like building the final board and designing / printing an enclosure, but after that it should be finished and I can move on to wrapping up the ECU tune and enabling E85.


Leave a comment

LFX AC Compressor Control

This is probably applicable to like 3 other people but I’m pretty pumped – I got the ECU to turn on the AC compressor! Currently I’m running a dumb circuit – as long as the AC button, high side pressure switch, and evap temp switch are closed the compressor is turned on. This works fine on the highway but it’s sort of a pain around town – sometimes when the compressor kicks on at idle it’ll stall the engine. Which, combined with the previously undercharged battery, would cause the car to stall and then not reliably start. My workaround has been to just turn the AC off whenever the engine is at idle but it’s not the best situation.

Getting the ECU to turn on the compressor is more complicated than it sounds – it needs a valid input from a high side refrigerant pressure sensor as well as a few pieces of information from the body control module (BCM), including a request to turn the compressor on. I know this from the GM standards I found – specifically GMW8771 and GMW8762. I initially tried faking out the AC pressure sensor using a 5k pot across the appropriate signals but I was never able to get the ECU to read anything other than 0V

For reference, that’s from my schematic. I was sort of stumped as to why it wasn’t reading the signal and it also wouldn’t turn the compressor on through HPT. Claude suggested it may not read the signal until it received the appropriate messages from the body control module (BCM) so I fired up the script it wrote and voila – compressor cycling! I think the issue is the ECU doesn’t know what kind of compressor it’s got (even though it’s bolted to the engine -_-) until the BCM tells it via CAN. The system is set up to either use clutch or variable displacement type compressors and the BCM needs to tell the ECU which one it’s got.

As a sidebar, this would have taken SO much longer without AI. I’d read through the standards and had a plan for which messages to send (and which bits to set, etc.) but I told Claude none of this and just fed it the standards – it came up with the same conclusion and also wrote a nice script to test it out. Given my success with the AC compressor I may attempt to get cruise control working… but that’s for another post.

Anyways, I’m going to wire my “dumb” circuit to my cluster commander and then let the ECU own the clutch relay. I’m tempted to just braze the actual Camaro high side pressure sensor into the refrigerant circuit (instead of faking it with a resistor divider) because load compensation is a function of high side pressure but… I’m done with the AC lines. At least for a while. I’ll write up the cluster commander when that’s done but figured I’d share this in case it’s useful to others.


Leave a comment

LFX Alternator Control

Quick tip for anyone else running a LFX – by default the factory alternator puts out 13.5V whether or not you plug in the small 2-pin connector or not. This slightly under-charges the battery which is kind of annoying given that it could fully charge the battery just fine.

After messing with it some today I believe I fixed it in HP tuners. Here are the relevant settings under System:
Note: this is for an e39 ECU only! I believe the e39a doesn’t have alternator control, it was moved to the body control module

I put a meter on the bus and noticed that it rose to 14.8V for a short time – roughly 120s, then dropped to 13.5V. This is because the ECM commands a default value for a default time, presumably to let the BCM boot up. Per the HP Tuners tool tips, if the ECM doesn’t receive any data (or you disable voltage control) it just defaults to 100% duty cycle after the default time. Sounds like it should just go maximum output, right? That’s why I thought until I checked the shop manual: “Normal duty cycle is between 5-95 percent. Between 0-5 percent and 95-100 percent are for diagnostic purposes.”

Theres more information in GMW8778 and here, but the GM spec spells it out: “If, when the generator is rotating, the L-terminal is opened, pulled low (0% duty cycle), or pulled high (100% duty cycle), the generator will regulate to a default setpoint of 13.8 V”. How about that. The ECM wasn’t receiving any data so it defaulted to an error state (13.5V in my case), NOT 100% output.

Fortunately it’s a pretty easy fix, all we have to do is to tell the ECM to just stay in “default” mode forever with whatever default duty cycle we choose.

Setting default time to 13,421,733 seconds (~3700 hours, max value) will always keep the alternator at DC min. I then dialed in the duty cycle so I was at 14.25V at the alternator and 14.15V at the battery. This is a big improvement from 13.5V at the alternator and 13.3V at the battery. Anyways, hope this is useful for other people – I don’t think it’ll solve my starting issue (I think my brand-new starter is just bad), but it’ll at least ensure the battery is always charged.

(For my future reference, I measured between 0.6 and 1V drop between the battery and block and 1V to 0.8V from battery to starter positive during cranking)


Leave a comment

Miatas at the Gap

I’m a few months overdue on an update but I’ll cut to the chase – the car successfully made its maiden voyage to Miatas at the gap! It ended up being around 1k miles round trip and it gave me zero reliability issues. I even got to meet up with a few other LFX Miata owners – @rdb138, @flatpick13, and @gooflophaze were there.

This was my first time at the tail of the dragon and the car was an absolute hoot to drive. Actually having power on corner exit was a new experience for me, especially in a Miata :). And, if I’m being honest, I needed this – after 3 years of the car being a project it was nice to get out and actually enjoy it. It’s quite the car and I’m glad I built it.

The trip did reveal a few quirks:

  • The driveshaft sounds like it’s in a torsional resonance at neutral throttle. This makes sense since both the engine and diff are stiffly mounted. It’s not too hard (if not annoying) to drive around but it doesn’t sound great.
  • Stock battery is barely not enough. On hot starts I sometimes have to bump the engine by moving the car before it’ll turn over
  • I just about ran out of gas by accident – I put in 12.22 gallons at one point. Gas gauge is top of my list now
    • Tank is very slow to fill. I think I overfilled it at one point and got some gas in the breather system.
  • There’s a pretty annoying resonance in the exhaust at like 2100 RPM. A helmholtz resonator should take care of that.
  • Shocks are definitely shot, which is not surprising since they’re stock. It leads to some pretty dramatic squatting on corner exit

None of these are particularly difficult to fix, and it’s a pretty short list for having completely rebuilt the car.

Leading up to the event I made a bunch of little changes:

Added clearance between the header and steering shaft

Added spartan 3 v2 wideband. I really like this because it transmits lambda over CAN (as well as having an analog output). Since the HP Tuners dongle is also on the CAN bus I figured it would just pick it up – nope, you have to buy another $80 cable from them to loop the same bus around to another input. Dumb. The wideband does work well though and the tune is spot on at steady state. It goes lean on tip-in so I need to investigate that, but it explains why tip in/out feels off.

I finally printed a backshell for my firewall connector. It all clears… barely. This was just a prototype, the final version is printed out of carbon-filled nylon

I also spent more time than I’m willing to admit trying to get the AC to work. I added way too much oil at first (like 2.5x too much) because I’m dumb, meaning I needed to pull apart and flush the system for a THIRD time. I was not happy. To make a long story short, once it had the correct oil fill it blows 60F on the highway at max fan speed. It’s not chilly, but it’s enough to make highway driving manageable. Other swapped cars seem to cool better so I think my stupid TIG welded lines are just clogged from the welds. That, and I initially underfilled the system because airflow across the condenser sucks when the car is stationary. I could go on, but I don’t think anyone is here to read about the AC system. I may revisit it at some point but I’m done with it for now.

And with that… I think the car is “phase 1” complete. All the major issues have been worked out and the drivetrain is reliable. I’m far from done with (and posting about) the car – it still needs suspension, seats, and a million little details, but I can tackle those one at a time. Thanks for coming on the journey with me.


Leave a comment

Misc.

Back to some actual Miata content. I’d put ~800 miles on it since I got it on the road (I don’t know the real number since I didn’t have an odometer) and identified all the teething issues, so it was time to do the (hopefully) final teardown and fix all the little issues.

Sound deadening
The car was pretty loud on the highway without any of the carpet installed. Not surprising, but while it was apart I went ahead and added some boom mat and then a sound deadening kit from FM. It’s probably overkill for a convertible, but it wasn’t all that expensive or heavy so I figured it was worth a shot.

Wiring
The interior wiring was pretty rough – nothing was really combined into a harness, most of the connections in the glove box were done with wire nuts, etc. That was all pretty straightforward to clean up. Before I finished, though, I wanted to add the clutch position sensor from the Camaro. This would hopefully fix the rev hang I was experiencing between gears with the engine warmed up. I picked up the sensor and connector from Rockauto and with those in hand I had to figure out how to mount it. The factory the position sensor (a potentiometer) directly engages with a pin on the pedal.

Why this is a position sensor and not a switch is beyond me. HPTuners has an option to use a switch, but based on my experience with some of the ancillary ECU features it can control, I’m skeptical it works as advertised. Directly actuating this with the pedal was out of the question as it would have been a total PITA, so I came up with a workaround:

https://www.youtube.com/embed/myGKmXttAsk?autoplay=0&start=&origin=
I shaved the fingers off, epoxied on a 3d printed pully, and ran a string between the pully and a hole I tapped in the pedal. I was surprised by how well this worked – the range is spot on and it’s dead simple. TBD if this solves the rev hang, but it was a fun project either way. With the carpet installed and wiring cleaned up it was starting to look like a real car again

Passenger Airbag Area
I’d initially removed the airbags in the car because I want to eventually add an aftermarket steering wheel, but one of the unintended benefits is I created an area to mount my Raspberry Pi.

As an aside, after giving it some more thought I’m not super excited that I removed the airbags – turns out the NB2 seatbelts likely have a deformable member inside them that slows your body into the airbag. Without the airbag in place it just slows my face into the steering wheel. Not really sure what to do about this. As Dave Coleman said, “On the one hand, I kinda wish I still had that big, explosive face pillow in the car. On the other hand, if this was a 1970 Miata, would I still be doing this? Hell yes, I would. Time to man up and not crash…”

Anyways, the first step was trimming the airbag cover so I could fit stuff in there

An oscillating tool made quick work of this. I also needed a way to remove it without reaching up behind the dash and pushing it out, so after removing half the clips to make it easier I stuck a piece of duct tape to the back and let it dangle out the front. It’s not pretty, but it works for now. I’ve got a better solution in mind long term but this works for now. Next I needed something flat to mount the Pi to – a few hours with some sheet AL and I and I had a mount

It’s attached to the dash with some

 3M dual lock– if you haven’t used it, it’s amazing stuff. I have to limit how much I use so that I can actually get stuff apart. Everything is mounted to the plate with dual lock as well. The tube on the left side is from the HVAC vent – I noticed during my initial drives that it got pretty warm under there, so I wanted a way to get at least some fresh air in there. The wiring is …still not done. I plan on designing a board to go on top of the pi to power it and allow it to gracefully shut down. Right now power just gets cut and it can corrupt the file system. In the meantime I’ve hacked a 12V to USB power supply in and taped it down, hence the wire nut.

The other item of note in that image is the red thing in the back – that’s the inertia switch attached to the dash

I welded 2 studs on to the dash bar and attached it with locknuts. When that switch opens (in the event of a crash) it opens the powertrain relay, which then cuts power to the ECU and fuel pump. It’s cheap insurance against gasoline spraying everywhere.

Garage AC
It’s starting to heat up here in NC so it was time to finish the garage remodel I’d started over Christmas. One of the last items on my list was plumbing in fresh air to the AC unit. For those unfamiliar, most floor units (like mine) take air from the room to cool the hot side, then dump the hot air outside. This sounds fine until you realize that it’s taking quite a lot of air from the room and the makeup air has to come from somewhere – in my case it’s directly past the garage door. So while the unit is pumping ~12k BTU of heat out of the room, it’s drawing probably ~4k BTU of 90° outside air inside, significantly reducing the overall efficiency. I solved this by 3d printing a manifold to go around the air inlet and plumbing it to 2, 4″ ducts to the outside

The 2×4″ ducts already existed from when the garage was finished in (long story) and I added the 6″ dryer duct for the hot air, both vent to outside. It’s certainly not the prettiest solution, but it’s better than spending ~$2k for a mini split, plus the time and headache to rearrange my breaker box for a 220V circuit, etc. I’ll have to wait until it gets hotter to see if it makes a big difference, but it certainly seems like it should. Prior to the fresh air mod it would keep the garage at 80° on a 95° day. I also plan on insulating the garage door, so hopefully between the two I can keep it to ~75° during the summer. I also put a wall-mounted fan up, an excellent $60 purchase. I should have done that years ago.

I’ve got a few things left to do before I get the Miata back out on the road: replace the entire AC system AGAIN, install a roll bar, wire in wideband, fuel pressure, and clutch position sensors, design a PCB to read the oil temp and fuel pressure sensors, etc. Once it’s back on the road, though, it shouldn’t need to get taken apart again for a while. If all goes well I’ll have it done by MATG and then I can hopefully get it out to VIR before the end of the year.


Leave a comment

Misc. details (and garage upgrades)

Been making progress on a bunch of little things, none of which really deserve their own post.

Exhaust
The biggest annoyance on the Miata was the exhaust – it was just too damn loud (shakes fist at clouds). Fortunately I (and my AI friend) were correct about the resonator – the shop replaced the puny resonator a vibrant ultra-quiet and it’s MUCH quieter. It’s still plenty loud when you step on it so I’m happy with where it’s at.

The second issue with the exhaust was the rattle that, in hindsight, is clearly setting off the knock sensors. I was convinced the flex pipe was the culprit, I could bang on it and hear things moving inside. After the shop replaced it the sound persisted, unfortunately. I once again had violated the first rule of troubleshooting – fix the broken thing first. In this case I knew the header occasionally touches the steering shaft and apparently the sound traveled down the exhaust to the flex pipe. At least I know what the issue is now, I just need to pull the header out and give it a nice dent. Also, kudos to the exhaust shop – they’ve done all of this labor for free. I stand corrected on my initial assessment and would recommend them.

After taking that picture I’ve realized I need to keep the brake line away from the header, too.

Gauge cluster
I’ve been driving the car with my DIY gauge cluster for a few months now and… I love it. It’s exactly what I want. I thought I’d want a physical needles instead of a screen but I fixed two things that would drive me nuts: first, the refresh rate is at least 30fps so it’s never laggy. Second, the tach is huge so it’s still easy to read just by glancing down. I’ve decided to just run it full time which means I need to clean it up:

  • Better mounting / finish around the screen, including adding “normal car” lights like high beams, turn signals, etc.
  • Adding a trip meter
  • Adding a fuel gauge
  • Add an “idiot light” that does not depend on the pi
  • Dim the lights / screen with the rest of the interior lights
  • Design a PCB to safely shut down the Pi

Adding “normal car” lights is pretty straightforward, I can just buy a set on Amazon and connect them to the factory wiring. I’ve already added an odometer in software which, due to how SD cars work, was much harder than anticipated. Adding a trip meter is pretty straightforward now, though.

The fuel gauge and idiot lights are going to be more work. Fuel level is an analog signal and because the Pi is basically a PC it doesn’t have any analog inputs. The solution isn’t super hard, it’s just work: wire in a CANbed which does two things: reads the fuel gauge (and bus voltage) and transmits them on the CAN bus, and monitor the CAN traffic for anything alarming. IE, if there’s low oil pressure, coolant temp too high, etc., blink an LED so the driver knows something’s up. I want this function to be on a µC because they’re way more reliable than something running Linux. That, and they boot almost instantly, whereas the Pi takes about 25 seconds.

I could add the voltage scaling, etc. for the CANbed in the harness but… I don’t want to. It’s ugly and hard to service. Instead I’ll design a PCB that does the analog scaling and also includes PWM outputs to drive the stock gauges in case I ever feel like going down that path in the future. More to come on this.

Band saw
When the exhaust got built I had about a week without a car and, well, I got bored. A while back I’d bought a second 4×6 band saw to convert to vertical-only use – there’s really no cheap metal cutting vertical bandsaws on the market. Even the portaband + swag offroad stand is around $500 all in. I bought the HF bandsaw for $125 on marketplace and decided to build a stand for it like this or this or this or this. $60 at the scrapyard got me some steel plate, a segment of angle iron, and this nice aluminum base. A few hours of cutting and welding and I had this:

Definitely worth the $200 I have into it. It’s a little top heavy (hence the sandbags and I-beam) but overall it’s way better than using the saw in stock form. I do plan on making a better table at some point, the stock table is pretty flimsy. Some people rotate the guides such that the band is parallel with the wheels but that significantly limits how wide of a piece you can cut – by leaving it as-is I can always rotate the guides to trade off depth of cut for more width and vice versa.

Wall takedown
I should have knocked out a bunch of work on the car over Christmas but… it was cold (for NC) and I needed to work on not-a-car for a few days. When we moved into our house the garage was finished in (hence the crown molding) and one of the first things I did was to turn it back into a garage. I tore out everything (carpet, wall in front of the garage door, etc.) except for the utility closet on the left side:

That remained because there were 7 switches in the two walls and I didn’t feel like dealing with the electrical at the time. My Miata did fit sideways but just barely, the bumper had to be removed. Because I’d like to store the Miata there again without removing the bumper (and because I need space for a chassis table eventually) I decide it was time to tackle the job. It took …way longer than I was expecting but I’m very happy with the results, I’ve gained a lot of room and the space is much more usable.

Pictures don’t really do justice to how much additional space there is now. I also installed 33,000 lumens of harbor freight shop light while I was at it and, well, I might get a tan if I spend enough time out there. If I screw something up it won’t be because I can’t see what I’m doing.

The electrical work wasn’t terribly difficult, just time consuming. I got lucky in that I only really had to run wire for one switch, the romex exited the drywall at the top back of the garage and the switch needed to be next to the door to the house. The rest of the work was really just converting the wiring back to how the house was when it was built. Mounting and pulling wires through the wiremold took most of the time but I’m pretty happy with how it turned out.


Leave a comment

AC part 3

This is a little out of order – I started on the AC lines back in July and didn’t finish them until early September. Just keep that in mind.

I ordered the fittings from rock auto and hose from cold hose (full BOM in my spreadsheet). I attempted to braze a few fittings on assuming it would work the first time – I know how to solder and weld so brazing should be easy, right? As is usually the case things didn’t go as expected and all of the joints leaked immediately. I think the leaks were because I didn’t use any flux and the joint kept moving as it was cooling, but whatever the case I had a TIG hammer and this was a nail-shaped problem.

Welding the fittings on was pretty straightforward, the hardest part was all the start/stops due to the small diameter. I made up all the individual segments, leak checked the best I could, then got them crimped at a local hydraulic hose shop.

There aren’t any commercially available 90° splices for reduced barrier hose so I made my own out of a #12 (5/8″) barbed elbow and some weld-on fittings, visible in the top of the image. I installed the lines, leaving the old condenser / dryer so I could leak check using compressed air – refrigerant is nasty stuff and I’d rather not weld parts that have been exposed to it. Leak checking revealed probably 6 pinhole leaks that I hadn’t seen before so out came the lines, repair, reinstall, and pressurize. I repeated this process probably 5 times before I fixed all but one leak.

See that gusset on the compressor manifold? It leaked no matter what I did. I spent probably 3 hours trying to fix the leak before I finally gave up and cut the manifold up to hopefully fix the leak. This was not my favorite move since I really liked how the manifold looked but such is life I suppose. It would have been fine if that fixed the leak… but it didn’t. No matter what I did I couldn’t fix this stupid leak, and now it was even harder to weld on the manifold because I didn’t want to cook the hose that was crimped on. After another 3+ hours of trying to fix the new leak, I gave it up and cut the manifold up AGAIN. Third time was the charm, though. This time it didn’t leak, at least with 120psi of compressed air. I lost count of how much time I spent leak checking and repairing these stupid lines, it was way more time than it took to make them in the first place. Tens of hours probably. Why I, as an amateur welder, thought it was a good idea to weld a small diameter, thin wall aluminum pressure vessel is beyond me. We do not do these things because they are easy, we do them because we thought they would be.

Here’s a few pictures of the lines installed. I secured them to the lower radiator support by drilling a hole, wrapping the line in some spare AC line to prevent it from chafing, and running a zip tie around it.

And for my future reference, this is the only way the manifold goes into place. It does not fit any other way

I pulled a vacuum on the system, backfilled with refrigerant to atmospheric pressure, then replaced the condenser. When the car was running I put half a can of refrigerant in the system mostly to see if it would hold pressure. I did notice something strange when I added refrigerant, though – I was seeing 130psi on the high side and a vacuum on the low side.

To be honest I was so excited to have the car driving I forgot about this. I’d occasionally try the AC to see if it worked and it would – sometimes. Other times it wouldn’t do anything. I was more concerned about making sure the engine wasn’t knocking so I didn’t pay it much attention, I just figured I’d troubleshoot it when I had time. That time, it turns out, was a few days ago.

I’d heard the compressor make some strange sounds when it kicked on but I figured a pebble or some road debris just got in the clutch, I’ve had something similar happen with my other cars and it wasn’t an issue. I hooked up my gauges with the compressor off and, to my surprise, the system was holding pressure! This is a huge win after spending so much time fixing leaks. I then turned the compressor on and… nothing. The clutch was engaging and spinning the compressor but zero pressure differential from high to low side. Uh oh.

As an aside, chatting with an AI isn’t always helpful. It’ll tell you garbage sometimes. But as a tool to do some rubber duck debugging it’s fantastic. I eventually concluded that some debris, either from my fabricated lines or desiccant that broke off from the new condenser, clogged the expansion valve and caused the high pressure differential I observed when I was charging the system. Here’s roughly what normal R-134a pressures should look like:

My pressures were a little on the low side since I didn’t fully charge the system, but even at 130psi I should have been seeing some positive pressure on the low side. This indicates that there’s a significant flow obstruction between the low and high sides, and since I didn’t modify the high side lines very much it’s most likely a clogged expansion valve. This explains why the AC would work sometimes – whatever was clogging it would shift or clear and allow refrigerant to pass, then more garbage would clog it up again and the AC would stop cooling.

Unfortunately, this wasn’t only a cooling issue – a clogged valve also doesn’t allow oil to pass. The compressor would pump all the refrigerant and oil into the high side then continue to run dry, frying the internals. Burned-smelling refrigerant oil confirmed this. I also turned the compressor over by hand and it felt gritty.

I initially thought the system would protect itself from something like this – it has a trinary switch which should shut down the compressor if the high side pressure gets too low or high. In this case it did not do its job because the design assumes that the low and high side pressures scale together – if the low side pressure is low, so is the high side. Because the expansion valve was clogged the high side pressure was normal-ish but the low side was under partial vacuum. An additional low side pressure switch would solve this although I don’t think they’re very common – I kept the Miata system as close to stock as I could.

To be honest I’m pretty disappointed, I’ve spent SO much time getting this AC system fabricated and leak-free. I now have to replace the entire system for a second time – compressor, condenser, expansion valve, and evaporator – and now flush all the lines with AC solvent (which gives you a great buzz if you’re not careful). It’s a least a full day’s worth of work, probably more since I’ll have to pull the dash. But that’s how these things go sometimes, I guess. At least it’s winter and I don’t need the AC for a while.


Leave a comment

tuning pt2

After chatting with my AI friend for a while I think I have a decent understanding of how the ECU works. I’ve left off some of the things we don’t care about (the idle system comes to mind) for the sake of simplicity:

There are two primary signal paths: the top, from accelerator pedal to throttle opening and the bottom, from air measurements (MAP, MAF) to cam angle, spark angle, and injector pulse width. The top path is primarily trying to get the engine to do what the driver wants and the bottom path is running the engine under the current conditions. First, let’s discuss the top path in a little more detail.

The accelerator pedal is converted to a driver torque request through the driver demand table. Vehicle speed is also an input to the DD table which allows for a shallow torque slope at low speeds (to avoid bucking) and a more linear response at higher speeds. Engine braking (negative torque) is also defined in the DD table in the low (<4%) rows.

Driver demand table, each cell is torque in Nm

This driver torque request is then fed into a bunch of different slow torque limits – slow because it affects the throttle opening. I won’t go into detail about these, if you’re interested in learning more see the link in my last post. For our purposes all of these should we moved well outside of what we expect them to be – with the exception of the peak torque limit, which should be ~20% higher than the max torque the engine can produce. We can also move peak torque out of the way, it’s just a nice safety limit to have in the event something goes sideways.

The limited torque request is then fed into the inverse engine model, which is defined by the virtual torque tables (VTT). This model takes all of the inputs the engine does – RPM, airflow, cam angle, etc. and estimates how much torque the engine is making. A feedback loop then tries to drive the estimated torque to the torque request by opening and closing the throttle body. Estimated torque is also fed back to the limiters so that estimated torque doesn’t exceed any of the limits.

The virtual torque tables, as their name implies, aren’t actually real – the inverse engine model is actually defined by a set of curve fit coefficients and the tables you can see in HP Tuners is just that model evaluated at whatever conditions you specify. This is also why when you change them you need to click “update coefficients”. While this may sound unnecessarily complicated it actually simplifies things from an OEM calibration standpoint. Because there are so many inputs (dimensions) to this model you’d need a ton of lookup tables to fully characterize the engine (HP Tuners defaults to 120 tables for gas alone). That takes a lot of memory and compute time in the ECU, so it makes much more sense to curve fit a function and just store 20 or so coefficients.

Note the intake and exhaust cam phase dropdowns – there are 4 and 5 of each, respectively. 6 tables * 4 intake angles * 5 exhaust angles = 120 tables

The bottom path starts by measuring or estimating how much air is actually entering the engine. The MAF is relatively straightforward – the MAF outputs a frequency which is then converted into a mass flow rate through a lookup table. Estimating airmass with the MAP is a little more complicated and uses a technique very similar to the virtual torque tables. MAP -> mass flow is not a lookup table but rather a curve fit function, which makes sense due to the dimensions added by variable cam phasing. It’s also a pain to tune since you have to deal with zones, getting the surface to be smooth, etc. I didn’t change the VVE tables because my engine is stock but I think this would probably take a long time to tune if you were to change cams, add boost, etc.

Again, note the intake and exhaust cam phasing. This is much more than one map.

Both MAP and MAF airflow estimate are fed into the dynamic airflow model which, as previously discussed, blends the two estimates together. The MAP (and VVE tables) are good at transients and the MAF is good at steady state accuracy -sounds an awful lot like a Kalman filter to me. At some point the VVE algorithm can’t keep up with engine speed so dynamic airflow switches over to MAF only.

Once we have cylinder airmass things get a lot simpler – cam and spark phases are both lookup tables using RPM and cylinder airmass. Fueling is even simpler, once you know how much air is in the cylinder all you have to specify the equivalence ratio (AFR / stoich) and ethanol content and the ECU takes care of the rest. It even has a power enrich mode where at high engine loads it’ll lower the AFR to make more power.

There are, of course, more details that complicate things. The fuel system uses the O2 sensors to dial in the AFR under cruise conditions (narrowband O2s only tell you if you’re above or below 14.7). The spark system “learns” away knock using knock retard using a per-cylinder calibration table. There are spark adders for intake air temp, engine coolant temp, power enrich mode, etc. Compared to how airflow and torque get estimated, though, these are pretty simple. Just a few more PIDs to keep an eye on when tuning.

The last detail in the spark system is are the fast torque limiters. The ECU has two ways of reducing torque: reducing airflow or retarding spark timing. If the ECU needs to cut torque really quickly it’ll retard or cut spark (think rev limiter), and if it can happen slower it’ll dial back the throttle. It’s probably a combination of the two but this illustrates the basic concept.

So how does this relate to how my car was driving? First off, dynamic airflow was set to be disabled at 500 RPM, forcing the ECU to only use the MAF sensor. I talked about this in my last post so I won’t cover it again.

The second issue was that someone had copied the virtual torque tables from what appears to be an entirely different engine into the tune. I’m not sure what they were trying to achieve but the effect was the ECU thought the engine was making more torque than it was. This was an issue for two reasons:

  • The inflated torque estimate was causing the VVT’s estimated torque to exceed a transmission torque limit, causing it to pull timing between 2-3000 RPM
  • Because the torque estimate didn’t match reality it caused drivability problems – the throttle wasn’t super linear and transient response was thrown off

I copied over the stock virtual torque tables and it solved both of those problems, I’m very satisfied with how it drives now. Transient response is actually pretty good, it’s not far off of a cable throttle. The only thing I may add is a clutch switch – right now the ECU thinks it’s in gear all the time, causing it to not cut fuel between gears. It also filters the throttle input too much when rev matching, again because it thinks it’s in gear. This is a pretty minor detail, though, and I’ll probably move on to other projects for the time being.

Hopefully this has been helpful (or at least interesting). I’ve enjoyed learning how it all works and it certainly helps understand what all the tunable parameters do.


Leave a comment

Tuning part 1

I’ve been driving the car around to shake out any bugs and so far nothing alarming – I’ve got what sounds like a 1/rev click coming from the driveshaft area and the engine’s running better, but not quite what I’d call 100%. I pulled the Keisler tune and started poking around in HP tuners and… well, it’s obvious why the throttle response sucks. Before we get to that I’d like to explain (mostly to my future self) how the ECU works. Full disclaimer – everything I’ve learned has been either from YouTube videos or AI… mostly AI with some sanity checking. Google’s AI has been trained on a bunch of material that’s behind a paywall for me so it’s been giving surprisingly good advice. Everything it’s said has passed the sniff test, but with that being said feel free to correct me if I get something wrong or if you have experience with this sort of stuff.

Unlike older ECUs the Gen V GM stuff does not just use a few lookup tables for fuel and spark. Fundamentally, the ECU is designed to respond to what the driver wants the vehicle to do, not just the engine. This article does a good job of explaining it in more detail but the short version is when you press the accelerator you’re requesting a torque value from the engine, not a throttle body opening percentage. The ECU can decide to open the throttle, advance the timing, change cam phasing, or add more fuel to meeting this torque request.

It’s probably obvious that getting this complex system to do what you want isn’t entirely intuitive, or at least it wasn’t to me. The first step in tuning is to make sure the ECU knows how much air is entering the engine since that drives most of the other calculations. For the LFX it does this using both a MAF and MAP sensors.

The MAF directly measures the airspeed in the intake, and using a calibration curve, provides an accurate estimation of the air mass flow rate. This is great – it’s a direct measurement of the parameter the ECU cares about. The drawback is that it’s not great at transients and often lags behind what’s actually happening.

This is where the MAP sensor comes in. Since it’s reading pressure it can respond to fast changes in the intake manifold, but the downside is that it relies on a model (typically a volumetric efficiency, VE lookup table) to estimate the airmass entering the cylinder.

GM blends these two approaches using a model called “dynamic airflow”. Below the disable RPM it blends MAP and MAF using some algorithm (my guess is some sort of Kalman filter). At some point VE model evaluation time becomes significant compared to engine speed, so above the disable RPM the ECU primarily relies on the MAF. For the engine to run right, then, both the MAP (VE tables) and MAF sensor need to be calibrated correctly.

Tuning the MAF is relatively straightforward – it outputs a frequency proportional to velocity and the ECU has a lookup table to turn that into a mass flow rate (and therefore cylinder airmass). Tuning the VE tables (GM calls them virtual VE tables) are …painful since they’re not defined by a lookup table but rather a curve fit function with tunable coefficients. This function takes RPM and MAP (speed density) and estimates cylinder airmass. I think HP Tuners has a way tool to make tuning the VE equations easier but I haven’t worked with that yet.

I downloaded the Keisler tune from the ECU but I needed something to compare it to. HP Tuners has a tune repository so I grabbed a tune from a stock 2012 Camaro (automatic, since that’s all they had). There were a bunch of differences but these stood out to me:

  • Dynamic airflow was always disabled (disabled at 500 RPM), forcing the ECU to always use the MAF
  • MAF is reading more airflow than engine is actually getting
  • VVE tables are unchanged
  • Virtual torque tables have been modified from stock, increasing by roughly 30% at high load
  • Power enrich is enabled at much lower RPM and load
  • Driver demand tables have been increased at the high end

Dynamic airflow being disabled certainly explains why the transient response sucked – the engine was going lean on tip-in, then the MAF would catch up and AFRs would normalize. The second issue was the MAF was over-reporting airflow, causing all of the long term fuel trims (LTFTs) to be ~-14%:

The air over-estimation is probably just an artifact of my intake tube size being smaller (3″). This sounds like a good thing – start by over-fueling, then let the ECU pull back – but there’s an important detail this overlooks. The long term fuel trims (LTFTs) ALSO apply during WOT, meaning it’s also pulling fuel when you want it the most! The crux of this is how ECU calculates fueling – The fuel calculated by over-measuring 14% more air should, but is not guaranteed to equate to 14% more fuel, but the LTFT WILL cut 14% fuel. The bottom line is the ECU should know how much air is entering the engine and faking it out probably isn’t a great idea.

The right way to dial the MAF in is to use a wideband… which I don’t have. A quick workaround is to scale the whole MAF curve (frequency -> airmass) until the LTFTs are dialed in, which is what I did. I linked a couple good resources on how to do so at the end, it’s not particularly difficult, just takes a few iterations. An important note: LTFTs aren’t learned at WOT (only learned in closed loop), those are just the trims being applied at WOT. I ended up with the following LTFTs (tune v7):

Interestingly, the LTFTs for bank 1 (passenger) and 2 (driver) are not the same – bank 1 is leaner by a few percent. Not sure if this is real or just an artifact of O2 sensor accuracy, but either way I’m calling anything ±5% good enough.

With the MAF dialed in I verified the virtual volumetric efficiency (VVE) table was correct by failing out the MAF and looking at LTFTs, all of which looked good

With both airflow measurements looking good I enabled dynamic airflow and… it drives a lot better. There’s still a little delay in the pedal but previously I could hear the throttle open, then the engine would start making power. That delay is now gone and I can actually rev-match on downshifts.

I then started looking at knock, which can be measured in two ways: directly by looking at the knock retard (KR) which how much timing the ECU pulls immediately (and decays quickly), or the knock learn factor (KLF), a learned parameter the ECU uses to permanently pull timing. Spark advance is calculated as [high octane table]*(1-KLF) + [low octane table]*KLF. To my surprise I was seeing some KLF and KR at all loads (v7_log4):

KLF (averaged over the whole log, 0 to 1):

KR (averaged over the whole log, degrees of timing):

I think KLF is more relevant here since it integrates as I drive, whereas KR decays quickly and is just the average over the whole log. I think there are two things going on here:

  1. The knock sensors are set fairly sensitive from the factory and are picking up mechanical noise between 2400 and 4800 RPM. There’s no way I’m getting knock at idle manifold pressures (20kPa, 3psia)
  2. There is some correlation between KLF and load, so that either means that:
    1. There is actual knock
    2. The added engine load makes the mechanical noise louder, causing more false KLF

This ECU allows me to log KLF per cylinder which is pretty telling, This is cylinder 1 (front passenger) and cylinder 6 (rear passenger, v7_log4)

This trend seems fishy to me, it’s only in one cylinder and it’s pretty strongly related to RPM, not just load. In an effort to try and distinguish if this is real or not I pulled 10° from the whole high octane map and logged some data. It tells a similar story (v8_log2). There’s a lot less KR in this log so I’m displaying the max values to illustrate the trend:

With 10° of timing pulled the car definitely had a lot less power and I could smell the exhaust getting hotter, but it should entirely eliminate any possibility of knock. What this tells me, then, is that I’m picking up some sort of mechanical noise primarily on the passenger side bank (1,3,5) and that it gets louder with more engine torque. It’s a little strange the frequency shifted down but this is pretty unlikely to be real knock. I should note that this dataset does not have any KLF, IE the duration was insufficient to start integrating.

I think I’ve convinced myself that the knock retard / KLF I’m reading is just noise and not real knock. I’m going to fix the cat heat shield rattle I’ve got and see if that clears it up, if not I’ll just desensitize the cylinder 1 knock sensor from 3-4k and move on. The overall knock sensor limits are a little more sensitive than I need them to be but it’s better than the alternative.

The next thing I’d like to look at how spark gets calculated – When I measure actual advance there’s a weird hole in timing between 2k and 3.6 kRPM which is noticeable when driving. This hole doesn’t exist in the high octane spark table so I’m guessing it’s a consequence of the virtual torque tables being inflated (spoiler: I’m 99% sure it is). Now that I know I’ve got reasonable AFRs and the engine isn’t knocking I can mess around with that as I have time. I also have a laundry list of other things I’d like to address (Lower rev limit to stock, disable clutch switch, put a wideband on it, enable flex fuel sensor, etc.) but one thing at a time.

_____

Create your own website, free on WordPress.com.Create your own website.
Start free