SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By Mee_n_Mac
#140410
hassmaschine wrote:my EE friend had this to say:
I think you're focusing on the potential difference with 5v too much. You should care about what the potential difference with ground is, which is equal to the pontential. You're trying to make 5v the ground, which it's not. Ground is the ground...
so, I'm going to target an inverting circuit, with 5v-0.5v inputs, and .9v-2.75v outputs.
The graph below indicates the input (stock curve) and output (from an op-amp) and the desired output (what a new gauge+new sender would do). The gain of this circuit was ~ -0.41 and allowed for an offset voltage of 3.4 V. Given your stock sender has a bit of a curve to it (vs being a straight line), and the new gauge wants more of a straight line, You can see there's some error btw the op-amp output and the desired curve. Some of this error may be the eyeball estimation of gauge/fuel level that went into your measured data. I'd make the gain and offset of the op-amp circuit somewhat adjustable to mitigate any error.

If the curves look OK to you, I'd say just about any general purpose op-amp will do, the LM358 SF sells is fine. Look up inverting op-amp circuits w/offset adjustment. One thing I've not thought through is what voltage you'll need to run it off of. It might be you need a simple voltage regulator as well.
BMWfuel.jpg
You do not have the required permissions to view the files attached to this post.
By Mee_n_Mac
#140413
While the insomnia lasts ...
Here's a 1'st cut at your circuit for discussion by all. I thought about it and you'll want a voltage regulator so the fuel tank reading doesn't change when the car is running vs not running (just on battery). So that means R1 below (which sets the stock sender voltage curve) and the gain of the op-amp circuit (-R3/R2) and the offset voltage (R4 and R5) will depend on the output voltage chosen for that regulator (and so will be different from the above post). I've made the assumption that the trip computer, which needs the stock voltage curve, is a fairly high input resistance. R1 would be something in the range of a hundred+ ohms, R3 - R5 in the range of K ohms to 10's of K ohms. Since most op-amp ICs come in at least dual op-amp packages, you'll also need to properly terminate any unused op-amps so they don't cause problems.
BMWcircuit.jpg
You do not have the required permissions to view the files attached to this post.
By hassmaschine
#140418
thanks - I'm sure there is some error in my eyeballed measurements. I extrapolated another curve in a straight line based off empty/full and they were pretty close to my eyeballed readings. I can probably fine tune some error in software, and as long as empty and full are working I should be OK.

also, I'm going to run it off the new cluster's 5v supply, which is clean/regulated. I've identified like 12 places I can splice into for power. :)
By Mee_n_Mac
#140429
hassmaschine wrote:also, I'm going to run it off the new cluster's 5v supply, which is clean/regulated. I've identified like 12 places I can splice into for power. :)
Running the stock sender portion off 5V presents a problem. When the sender is at it's ~3 ohm point, the output wants to be 5V, or pretty close to it. That means R1 has to be smaller than 3 ohms and that means a lot of power dissapated in R1 and the sender. That's not good. You could run the sender portion off another voltage and the op-amp off the 5V from the new cluster. You then need to be a little careful in your choice of op-amp in that it must work off a "low" voltage and it's output must be able to go from pretty close to zero volts and up to +Vsupply - 2V (3V) when run off +5 and ground for it's + and - supply voltages. I believe an LM358 still works as it goes to some 10's of millivolts above the -supply (ground) and up to +Vsupply - 1.5V.

If you run the sender off the battery, as was done originally, the trip computer will "see" a different tank level depend in whether the car is running or not. Since that's the way it was when stock, perhaps that's OK.

Going with the above, the revised circuit would be as follows. Note R3 and R5 should probably be adjustable around the nominal values shown.
BMWcircuitA.jpg
I've not shown some bypass/filtering capacitors that will want to be added.
You do not have the required permissions to view the files attached to this post.
By hassmaschine
#140432
yeah the sender will run off the battery as it does now. I did realize that it probably reads differently with the car off than it does with it in (~12v vs 13.5v). that's fine, it's not often used when the car is off anyway. the main thing it does is calculate remaining miles left until you run out of gas, which is surprisingly quite accurate for 1980s tech..

I used a calculator on TI's website to come up with the resistors I'd need with the inverting circuit. I've ordered the parts - will put it together and start testing.

if I wanted it to be adjustable, which resistors would I change to a potentiometer? the gain and offset? of course, as soon as I'd ordered I came up with a list of like 10 more parts I'd like to have. haha.

With the knowledge learned from this excersize I'm also going to be able to fine tune the speedo reading and make the LED backlights dim with the stock light switch. :D

will update this post after I've built the op-amp with results (and likely questions). thanks for the help!
By Mee_n_Mac
#140444
hassmaschine wrote:if I wanted it to be adjustable, which resistors would I change to a potentiometer? the gain and offset? of course, as soon as I'd ordered I came up with a list of like 10 more parts I'd like to have. haha.
Those would be R3 and R5. Changing the gain will affect to output offset voltage so there's a little bit of chasing your own tail involved. If you get a dual op-amp package, the gain and offset functions could be separated so that doesn't happen.
By Mee_n_Mac
#140506
I was going to put the above circuit into a Spice circuit simulator but my PC w/Spice on it died. Seems to run for 60 to 400 secs and then it's BSOD and worse. I think the fan isn't running anymore. In any case the circuit is simple enough I did a crude sim in Excel and the resultant plot should be below. What I did find was R5 needs to be a little bigger (or R4 a little smaller), specifically R5 = 14.3K.
BMW_sim_plots.jpg
If I could attach the Excel file you could play with the inputs yourself. Alas I can't seem to do that.
You do not have the required permissions to view the files attached to this post.
By hassmaschine
#140771
Mee_n_Mac wrote:I was going to put the above circuit into a Spice circuit simulator but my PC w/Spice on it died. Seems to run for 60 to 400 secs and then it's BSOD and worse. I think the fan isn't running anymore. In any case the circuit is simple enough I did a crude sim in Excel and the resultant plot should be below. What I did find was R5 needs to be a little bigger (or R4 a little smaller), specifically R5 = 14.3K.
BMW_sim_plots.jpg
If I could attach the Excel file you could play with the inputs yourself. Alas I can't seem to do that.
can you email it to me? hassmaschine79 at gmail dot com

I've built two prototype circuits. No Bueno. The first one definitely had some errors in it. I made a second one and checked and double checked - it performs even worse than the first one I built! I'm not sure what I'm doing wrong yet. I'm going to try to build another tonight.

Also, I have another application for an inversion circuit - for the backlight/dimmer. I need to invert the voltage (because of the way the light switch is wired and where I have to pull power from). But, this one is really simple - a gain of -1 and an offset of 0. I'm going to attempt to build this one and see if I can make it work since it should be simpler.

I've also started an ExpressPCB layout, but I don't want to order anything until I know the circuit is working properly.... :)
By Mee_n_Mac
#140819
hassmaschine wrote:can you email it to me? hassmaschine79 at gmail dot com

I've built two prototype circuits. No Bueno. The first one definitely had some errors in it. I made a second one and checked and double checked - it performs even worse than the first one I built! I'm not sure what I'm doing wrong yet. I'm going to try to build another tonight.
I'll see what PC it's on and send it out when I find it.

Can you post a schematic or wiring diagram of what you think you have that didn't work ? Perhaps there's something obvious ... or perhaps I screwed up. :o
By hassmaschine
#140844
Well, it wasn't anything you did! Or me, either!

It turns out the $4 breadboard I bought has a short in it. the 5v input and Vout were shorted together. So no matter what I did with the inputs, the output was always about 5v. doh!

I built a 3rd prototype, soldered this time, that works perfectly! I just roughed in the resistance values with what I had laying around - 10k, 10k, 4.3k, and 12k. It needs fine tuned of course, but I could see that it was working just fine. the final circuit will have potentiometers so I can adjust it.

I'm having a software issue I need to figure out with the cluster. The ADC count into both inputs varies just fine, but the left sensor input is "stuck" at 24 liters. Each sensor seems to measure half the tank, (30+30 = 60l). The right sensor changes the level from 3-33 with the ADC count just fine, but the left stays at 24 even as the ADC input changes. So what happens is the fuel gauge doesn't really go below 1/2 tank. I was monkeying with calibration values a while back, I probably just need to reset it to stock. I know it worked before - and I couldn't get it to work recently with the actual level sensors either. I even tried it with the right input hooked to the op-amp, and the left hooked to a level sensor. Same problem.

Since I can see the ADC inputs changing, and the sensors don't work either, it's gotta be something I did with the software. :)
By Mee_n_Mac
#140845
hassmaschine wrote:Well, it wasn't anything you did! Or me, either!
It turns out the $4 breadboard I bought has a short in it. the 5v input and Vout were shorted together. So no matter what I did with the inputs, the output was always about 5v. doh! I built a 3rd prototype, soldered this time, that works perfectly! I just roughed in the resistance values with what I had laying around - 10k, 10k, 4.3k, and 12k. It needs fine tuned of course, but I could see that it was working just fine. the final circuit will have potentiometers so I can adjust it.
Well that's good ! A little tweaking and it's done. Also nice to know I can still figure out basic op-amp circuits.
hassmaschine wrote:Since I can see the ADC inputs changing, and the sensors don't work either, it's gotta be something I did with the software. :)
Software ... it's always the software. :doh:
By hassmaschine
#140847
yep - software! I only had calibration for one sensor loaded. By default each sensor gets it's own calibration curve - I had it set for a single-sensor tank. a couple clicks and I'll have a working level gauge! :D

Here's my schematics/PCB:
http://www.325ix.com/pics/2012/S54ix/03 ... ematic.png

Front:
Image

Back:
Image

Composite:
Image

comments/suggestions? I'm pretty happy with the layout but I've never used software like this before.

the bottom part I'm going to use as a breakout board between the two cluster harnesses. The main board has to fit in a certain amount of space, so it will be cut along the dashed line (the small holes will make it easier to cut). I just didn't want to waste any space as these boards are expensive. :)
By Mee_n_Mac
#140848
A comment or two and some questions on your schematic. First what are all the transistors supposed to do ? It just looks a little odd to me. And the op-amp circuit that has resistors in the hundreds of ohms range ... hmmm ... not so good. Generally you want the resistors to be in the Kohms to 10's of Kohms range. I'd also recommend some ceramic "bypass" caps across the op-amp power supply pins, as close to the op-amp as you can get them. They may not be needed with the cluster supplying a regulated 5V but it's good practice to avoid any digital noise the cluster may stick on the supply.
By hassmaschine
#140851
Mee_n_Mac wrote:A comment or two and some questions on your schematic. First what are all the transistors supposed to do ? It just looks a little odd to me. And the op-amp circuit that has resistors in the hundreds of ohms range ... hmmm ... not so good. Generally you want the resistors to be in the Kohms to 10's of Kohms range. I'd also recommend some ceramic "bypass" caps across the op-amp power supply pins, as close to the op-amp as you can get them. They may not be needed with the cluster supplying a regulated 5V but it's good practice to avoid any digital noise the cluster may stick on the supply.
The transistors are basically acting as relays to turn on the indicator lights (left turn signal, right turn signal, high beam, fog light, and two ABS indicators). Since I'm not using the light control computer that goes with this cluster, i need to turn them on manually. The signals on my car are active high (12v), while the signal lights on this cluster are active low (ground). I've tested it already and they work flawlessly. :D

For the dimmer, I could just use 10k, 10k, 13k, and 14k, right? I'm not actually very worried about the dimmer circuit - it doesn't need to be super accurate. I just want some control over the brightness and for it to be linked to my stock dimmer switch. Otherwise I was just going to hook it straight up to 12v with a resistor.

as far as noise - the gauge is *heavily* dampened. I suppose a cap wouldn't hurt, but I don't know that it would make any difference for my needs. I might want one on the dimmer since it's using a noisier supply, I don't want noise showing up as blinky LED backlights. :p

any suggestions on a cap size? I probably have a bunch laying around actually.
By Mee_n_Mac
#140857
hassmaschine wrote:The transistors are basically acting as relays to turn on the indicator lights (left turn signal, right turn signal, high beam, fog light, and two ABS indicators). Since I'm not using the light control computer that goes with this cluster, i need to turn them on manually. The signals on my car are active high (12v), while the signal lights on this cluster are active low (ground). I've tested it already and they work flawlessly. :D
Are the indicators some type of incandescent light bulb or LEDs ? If they are the former you could forgo the resistors from 5V to the collectors and perhaps even the diodes, and just attach the bulbs to the 2N2222 collectors. It'll save space, parts and electricity. If the indicators are LEDs then your circuit may work but eventually I predict LED failures as there doesn't seem to be any current limiting resistor(s).
hassmaschine wrote:For the dimmer, I could just use 10k, 10k, 13k, and 14k, right? I'm not actually very worried about the dimmer circuit - it doesn't need to be super accurate. I just want some control over the brightness and for it to be linked to my stock dimmer switch. Otherwise I was just going to hook it straight up to 12v with a resistor.
Dimmer ? What dimmer ? :mrgreen: Is this the op-amp circuit with 100's of ohms ? If so yes, 10K - 14K in place of 100 - 140 ohms is good.
hassmaschine wrote:any suggestions on a cap size? I probably have a bunch laying around actually.
100 nF is typical.