[Success Story] 1997 Ford F-150 5.4 E4OD

Your chance to introduce yourself and your vehicle
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

1997 Ford F-150 5.4 E4OD

Post by dbh97 »

Well, now that I have a piece of hardware that is running rusEFI attached to my vehicle, I figure it's time to make a forum thread about it.
I plan on building an engine to put in this thing, and running it on rusEFI. For right now, though, it is serving duty as a TCU test mule. I have driven it about 60 miles using a switch to select gears, and with the EPC (Electronic Pressure Control) solenoid running at a fixed PWM.

Today I hooked up a INA219 current sensor breakout to the EPC circuit to figure out what I need to do to control the current, and got a strange result. I'm pretty sure I don't have the INA219 calibrated properly, but nevertheless I can tell that there is something going on that I wasn't expecting. In the graph below, samples were taken every 25 ms, while the EPC was being controlled with 70% duty cycle. The large peaks are roughly 4 seconds apart. the smaller peaks are slightly closer together, which results in the pattern you see above. I have no idea what causes either of these peaks.
Screenshot_20210423_144817.png
Screenshot_20210423_144817.png (54.53 KiB) Viewed 7138 times
Also, due to the fact that I don't have the INA219 properly calibrated, I don't really know what "0" and "4000" mean in terms of current. Are they multiple amps apart, milliamps? I have no idea.
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

After some more experimenting, it seems that signal was somehow a product of the sampling times. I tried again with a 1 ms delay in my main loop, and got this:
Screenshot_20210423_174834.png
Screenshot_20210423_174834.png (83.6 KiB) Viewed 7128 times
This is unusable as is. I guess it needs either:
1. Much faster PWM
2. some kind of filtering
3. use a comparator to switch it on as the current drops below the level set by a DAC.
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

After adjusting the configuration of the INA219 (again, 70% duty cycle):
Screenshot_20210424_113040.png
Screenshot_20210424_113040.png (77.73 KiB) Viewed 7108 times
Here are the results I got with 100% duty cycle:
Screenshot_20210424_113803.png
Screenshot_20210424_113803.png (59.46 KiB) Viewed 7108 times
The above was at idle, below is at 2500 RPM:
Screenshot_20210424_113815.png
Screenshot_20210424_113815.png (62.22 KiB) Viewed 7108 times
The time scale is in milliseconds, and matches between these three graphs.
These graphs tell me:
1. The large oscillations in the first graph do not match the large oscillations in the other two graphs, and are probably aliasing due to the sample rate (1ms).
2. The length of the large oscillations does not go up enough in the third graph for them to be linear with RPM.
3. The amperage goes down with RPM. I guess that this means that the pressure of the ATF on the EPC solenoid moves it somewhat, reducing its current draw.

Does anyone know the cause of the oscillations in the second two graphs?
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

Here are some pictures of my test setup as it is currently:
IMG_20210424_113154.jpg
IMG_20210424_113154.jpg (3.53 MiB) Viewed 7106 times
Discovery, 12V->5V adapter, and relay board
IMG_20210424_113207.jpg
IMG_20210424_113207.jpg (3.07 MiB) Viewed 7106 times
MOSFET with indicator LED
IMG_20210424_113212.jpg
IMG_20210424_113212.jpg (2.08 MiB) Viewed 7106 times
Teensy and INA219 breakout board
IMG_20210424_113202.jpg
IMG_20210424_113202.jpg (3.09 MiB) Viewed 7106 times
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

Given that it appears that the current method of current measurement doesn't seem to be workable, I'm trying to figure out what direction I need to take. @mck1117 suggested in Slack to use a DAC and comparator to "set" the current, and then let the comparator switch the MOSFET on and off as needed to maintain the current. I have tried to create this circuit using https://falstad.com/circuit/.
Screenshot_20210424_161201-annotated.png
Screenshot_20210424_161201-annotated.png (24.38 KiB) Viewed 7094 times
What I'm trying to do with this circuit: measure the current, compare it with a "current" set by the MCU, and switch the MOSFET on if it's lower, and off if it's higher. I'm trying to do this with a DAC (represented by the 3V voltage input), a shunt, and a comparator (represented as an opamp).
Several things make me very uncertain about this design:
1: limitations of the circuit designer/simulator
2: my inexperience in EE
The limitations of the Falstad Circuit Simulator Applet that have affected this circuit are:
1: The only comparator available is Hi-Z/GND, so I used an opamp instead
2: It seems like the MOSFET doesn't match real-world MOSFET's available to me

All this gives me some questions:
1: The comparator in this circuit will have inputs in the range of ~4mV to ~200mV. Will this work?
2: A real world MOSFET will in fact handle the solenoid load with a 5V Vgs, right?
3: I haven't measured the inductance of the EPC solenoid. What effect will it have on this circuit, if any? I'd like this circuit to be perfectly reusable for any transmission solenoids, only needing tuning of the desired DAC output in TunerStudio
4: Because the sim is using an opamp instead of a comparator, it just reduces the voltage to the MOSFET, which then flows less, instead of switching it on and off. I'm /assuming/ that it'll switch on and off properly with a comparator, but I don't know that.
User avatar
AndreyB
Site Admin
Posts: 12794
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: 1997 Ford F-150 5.4 E4OD

Post by AndreyB »

What is this blue stm32 board? It kind of looks like discovery but why is that blue?!
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
blundar
contributor
contributor
Posts: 141
Joined: Tue Jan 07, 2014 4:38 am
Location: Cincinnati, Ohio
Github Username: blundar
Slack: Dave B.
Contact:

Re: 1997 Ford F-150 5.4 E4OD

Post by blundar »

it got sad, Andrey. It's what happens to depressed PCBs.
blundar
contributor
contributor
Posts: 141
Joined: Tue Jan 07, 2014 4:38 am
Location: Cincinnati, Ohio
Github Username: blundar
Slack: Dave B.
Contact:

Re: 1997 Ford F-150 5.4 E4OD

Post by blundar »

dbh...

https://www.ti.com/lit/ds/symlink/lm2903b.pdf

LM2903/393/etc are about as basic bitch of a comparator as you can get.

page 4 of datasheet covers voltage inputs: you can go from 0 to 36V BUT it is good practice to limit your input voltages to GND < Vin < Vsupply

Comparators are *very* sensitive. You can typically protect their inputs fairly well by just an obscene series resistor, i.e. 10k-100k.

MOSFETs can be thought of as voltage controlled switches. Vgate <= Vgs(th) and they are "very high" resistance, i.e. no current flow. Vgate >= Vgs(th) and they are close to a short circuit, namely Rds(on). There is a linear region in between on and off that in most cases is best to avoid because of the high power dissipation in the linear region. You will probably want to run a diode across the solenoid because it is an inductive load. This will effectively limit the maximum switching frequency but will keep your MOSFET from exploding in a fiery ball of inductive kickback. The alternative is to limit gate drive current in order to limit the speed at which the MOSFET switches in order to limit how high the inductive kick goes but this will require a MOSFET with much higher Vds(max). It is not inconceivable that you could switch 100A worth of current with a single well chosen MOSFET.

If you don't know the inductance of the solenoid, the safe bet is to use a diode to direct flyback current safely. You probably won't need to be switching that fast so it probably won't hurt that much. If you have a scope, you can monitor the junction of the MOSFET and the solenoid and make sure your spikes are less than the voltage rating of the FET with the diode installed.

The key to making this circuit work properly with a comparator is going to be hysteresis. You want the window between on and off to be slow enough that you end up with the MOSFET turning completely on and off. This is typically accomplished with positive feedback. The whole point of the comparator circuit is to switch the FET 100% on and 100% off quickly (as opposed to driving it in its linear region with the op-amp) but too fast can be bad.

I'd also pay VERY close attention to driving the FET. Depending on choice of FET, you may need to use a gate driver to provide enough oomph (i.e. current) to open and close the gate quickly. The basic bitch LM2903 comprator I referenced has open-collector outputs that are rather limited in current (20/25mA) which may not be enough to do things as quick as you'd like to.
blundar
contributor
contributor
Posts: 141
Joined: Tue Jan 07, 2014 4:38 am
Location: Cincinnati, Ohio
Github Username: blundar
Slack: Dave B.
Contact:

Re: 1997 Ford F-150 5.4 E4OD

Post by blundar »

User avatar
kb1gtt
contributor
contributor
Posts: 3732
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: 1997 Ford F-150 5.4 E4OD

Post by kb1gtt »

Perhaps change the current sensor? It seems you just trying to sense the amps. See below video it details the use of a low cost board you can get on ebay.

Welcome to the friendlier side of internet crazy :)
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

kb1gtt wrote:
Sun Apr 25, 2021 10:13 am
Perhaps change the current sensor? It seems you just trying to sense the amps. See below video it details the use of a low cost board you can get on ebay.
I'd forgot about hall current sensing. That could be a nice option.
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

AndreyB wrote:
Sun Apr 25, 2021 2:15 am
What is this blue stm32 board? It kind of looks like discovery but why is that blue?!
I don't know why it's blue. Someone else here (forum? slack? I don't remember) got a blue one too.
I got it from a legitimate supplier. I can't remember which one though.
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

Regarding a flyback diode:
Is there any chance that there is one integrated into the solenoid?

The solenoid is hard wired to +12V, and the ECU switches the GND to it. So I would need to put one to the 12V that is connected to the ECU. That would be satisfactory, wouldn't it? Or does it need to be closer to the solenoid for some reason?

I'm going to throw together a prototype. I've got some LM311s kicking around that I think will work. All I need is a DAC. I'll probably try it with a potentiometer first.
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

Just putting this here so I can remember it.
out.png
out.png (543.49 KiB) Viewed 7051 times
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

I built this circuit and it doesn't work. Both ICs get hot. I guess I need to break out the scope.
out.png
out.png (133.56 KiB) Viewed 6934 times
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

After some review, it turns out I totally botched the wiring. Specifically, reversed power and ground.

whoops-resize.png
whoops-resize.png (1.08 MiB) Viewed 6928 times
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

Current sensing and control status update:
The circuit kind of works, but it seems that dunce me got Ohm's law wrong, and the ~2.3 amps that the solenoid draws and the 100 ohm resistor I have are not the match I am looking for.
2.3 * 100 = 230 V
I'm looking for something more in the range of 100-200mV.
0.1 / 2.3 = ~0.0434
0.2 / 2.3 = ~0.0869
So I need a 43-87 mOhm resistor.
How many watts does it need to be rated for?
0.2 / 0.087 = ~2.298 W
0.1 / 0.043 = ~2.32 W
Looking on Digikey the cheapest SMT resistor I see that meets these requirements is:
https://www.digikey.com/en/products/detail/riedon/CSR2512C0R05F/5723640
This is a 50mOhm resistor with a 3W rating.
Let's figure out what our voltage would be with this resistor.
2.3 * 0.05 = 0.115 V
That seem to be workable.

Am I barking up the wrong tree? Should I be using hall current sensing instead?

Also I'm having a wierd issue where my MOSFET driver seems to be turned on partially when it shouldn't be. With a input signal to the driver of about 50mV, the MOSFET is turning on enough to flow about 315 mA. I need to do some more poking around with the scope to see what's causing it.
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

So I hooked up 3 1.5 Ohm resistors in parallel because that's the smallest resistor I have on hand.
It seemed to work pretty well, but after a drive of about a mile, the MOSFET heatsink was quite hot.
Here is a scope screenshot taken while driving, with A channel attached to the MOSFET driver output, and B channel attached to the high side of the shunt resistor.
Screenshot_20210512_200741.png
Screenshot_20210512_200741.png (101.3 KiB) Viewed 6424 times
What I don't understand here is why the MOSFET drive out doesn't go between Vin (5V) and GND, but in between? This seems to be related to the behavior I mentioned in the last post. I suspect it's also why the MOSFET is getting hot.
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

Schematic with updated resistor values:
out.png
out.png (133.81 KiB) Viewed 6421 times
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

After a talk with @mck1117 in Slack, I have decided on a few changes to try:
1. With the 0.5 ohm shunt resistor I have now, the shunt voltage at max on is about 1.2 V. This leaves the Vgs at about 3.8 V, which is very marginal. To counteract this, I am going to supply the MCP1407 with 12V instead of 5V.
2. The 50k pullup resistor on the output of the LM311 is too large to reasonably supply the gate driver's required 10 uA, especially with the 24k hysteresis resistor trying to pull it back down to whatever the input to the comparator is set to. (0-1.2V is the useful range with the current setup.) I will change this resistor to a much lower value. (@mck1117 suggested 1k)

I also need to do some scoping so I can see how well the MOSFET driver output correlates with its input.
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

After some more discussion (a gross simplification), @mck1117 pointed out the obvious face-palm-inducing problem with this design: If the MOSFET is off, there is no current to sense.
My plan now is to add an op-amp, and move the shunt resistor to between the solenoid and the diode+MOSFET.
Matt posted this, which isn't exactly right, as the load isn't in the right place, but the idea is right.
image.png
image.png (39.6 KiB) Viewed 6411 times
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

Playing around with Falstad Circuit simulator, I've come up with this:

https://falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWEA2Z0FgCxmQZl5JprsmABwgKSWXUICmAtGGAFABO4ATBVptxS5d+1GIQDsHASCH9ZMyBWpcwcKfLDjk0vlAVqAJtPmZeyZSAP0AZgEMArgBsALq0fgiIMtTA8PI8ChYOCFkBABOKlxxSGRw4UhxQWhcVgBnfxlxLmNhPQg7RzT6VlsZPLB4kBJeKvDwJGYkVXg4bmgtMPDozC4tMjJ+Xw7UUkU4iJjs8FbIVgB3cqGtLJy+nLnF+S5FVek5znXpGv2Z1qldI6vpnxa1RZPfCkequYBzTKPdXB29OYAlECmcDmIGCXaiIE+XB-IIIKTAnA+TzePQIaDIVgAe3AEGQAUwkHC9SQYjglQQuF8pJkuOqrCAA

Noob questions:
1. I'm representing the solenoid with a resistor and an inductor. Is this good enough?
2. I gave the resistors going to the op-amp slightly different values. In this configuration they create a little bit of hysteresis. If they're swapped around they create some "anti-hysteresis". Could this be a problem?
3. I picked resistor values by trial and error. Please critique.
mck1117
running engine in first post
running engine in first post
Posts: 1268
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: 1997 Ford F-150 5.4 E4OD

Post by mck1117 »

Notes from discussion about how to sense high side current:

What we're trying to do is output a voltage proportional to the current.

With a shunt resistor, you now have two voltages (either end) whose difference is proportional to the current. So we need something that can do output = gain * (v1 - v2), with the caveat that v1 and v2 may be may be considerably more than the supply rail of the amp. That caveat is the kicker, because most opamps don't work when you do that. Current sense amps (INA214, for example) are specifically designed to handle that case.

Here's a differential amp circuit built with a normal opamp, computing Vout = 1V/A * I1 (one volt output per amp across R1):
image.png
image.png (91.02 KiB) Viewed 6371 times
The X axis is a sweep of the source labeled V_cm from -5 to +15 volts. The output of the opamp is only sensible when the common mode voltage (average of the voltage either end of R1) is inside the supply rails, in this case 0 to 5 volts.

Solutions:
  • Use a purpose-build current sense amplifier, like the INA214 (et al)
  • Use a hall effect current sensor, which has the added bonus of having functionally no limit on common mode voltage, since the actual sensing element is magnetically coupled to the current path.
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

Posting this here so I don't have to keep googling for it: https://www.analog.com/en/analog-dialogue/articles/current-measurement-in-solenoids.html
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

:o :shock: :D
IMG_20210516_075420.jpg
IMG_20210516_075420.jpg (1.45 MiB) Viewed 6334 times
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

Ford was nice enough to put detailed thermistor values in their service docs:
Screenshot_2021-05-22 Direct-Hit -- Search.png
Screenshot_2021-05-22 Direct-Hit -- Search.png (19.46 KiB) Viewed 6128 times
mck1117
running engine in first post
running engine in first post
Posts: 1268
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: 1997 Ford F-150 5.4 E4OD

Post by mck1117 »

I love how hilariously wide both the temperature and resistance ranges are.
dbh97
contributor
contributor
Posts: 82
Joined: Sat Jul 19, 2014 10:43 pm
Location: 67867
Github Username: chuckwagoncomputing
Slack: dbh97

Re: 1997 Ford F-150 5.4 E4OD

Post by dbh97 »

So I'm taking a step back and forgetting about current mode control for now.
One of the things I learned from trying to figure out how to do it was that I need a gate driver for the MOSFET. So I built this circuit.
driver.png
driver.png (116.61 KiB) Viewed 6031 times
At first I did not connect the two outputs of the driver, and this was the result:
Screenshot_20210523_154348.png
Screenshot_20210523_154348.png (100.7 KiB) Viewed 6031 times
I concluded that the second output needed to be connected in order to pull the gate back down.
I connected it and got this. Note that the yellow trace, the gate voltage, is set to 2V/div.
Screenshot_20210524_065941.png
Screenshot_20210524_065941.png (104.66 KiB) Viewed 6031 times
It's clearly not getting pulled anywhere close to ground. After poking around for a while, suddenly it was stuck at about 4.5 volts, and the driver was very hot. I replaced the driver and the replacement fried instantly, and was doing Not Nice things to my Discovery board, and when disconnected from the Discovery, would blink the LED on the input at maybe 10hz by my eye gauge.

So now I'm trying to figure out what happened. I guess I should check if the MOSFET is good. Perhaps I fried it with static at some point.
mck1117
running engine in first post
running engine in first post
Posts: 1268
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: 1997 Ford F-150 5.4 E4OD

Post by mck1117 »

dbh97 wrote:
Wed May 26, 2021 3:02 am
It's clearly not getting pulled anywhere close to ground.
what are your Y offsets set to on the scope? are you sure they aren't both going to ground?
Post Reply