opamp wild readings, help please

Hello Arduino community and first let thank anyone who is looking at this and wants to help tackle my opamp problem. Attached is an drawing with a opa228P opamp and my Arduino code below. I have an ancient drive that has an old analog display. What I am trying to do is use an Arduino attached to the gauges to do an analogread, luckily most of the gauges are 0 – 10 volts which makes it easy using a voltage divider for the Arduino to analogread it. The problem is one of the gauges reads from -2000 to plus 2000 and with a volt meter at -2000 it reads -10V and at 2000 it reads +10V so I understand I need to use an opamp so the Arduino can read it. I am pretty sure I am using the correct resistors in order to output 0 – 5 volts for the Arduino to read and then map accordingly with if statements like backdriveRPM=map(backdriveRPMvolts, 525, 1023, -1, -2000); and backdriveRPM = map(backdriveRPMvolts, 495, 0, 1, 2000);

For the most part I have it working and when sampling it trends correctly but I am getting some crazy swings. So, I added a for loop to try and average them out but the swings are still pretty large. I have also added a dead zone in the mapping to see if that can help when at rest (0). Are there any issues with my drawing? Do I have to add or remove something in order calm down the readings? Any help in this matter would be greatly apricated. Please let me know if you need any more info and thank you for your help.

//***********Back Drive RPM*************
  for (int i = 0; i < numberOfSamples; i++) 
  {
    currentSample = analogRead(backdriveRPMpin);
    currentValue += currentSample;
  //  delay(timeGap);
  delay (10);
  }
    backdriveRPMvolts = (currentValue / numberOfSamples);
    currentValue = 0;
    currentSample = 0; 

    if (backdriveRPMvolts > 525)
    {
     backdriveRPM = map(backdriveRPMvolts, 525, 1023, -1, -2000);
    }

    if (backdriveRPMvolts < 495)
    {
     backdriveRPM = map(backdriveRPMvolts, 495, 0, 1, 2000);
    }
    if ( backdriveRPMvolts == 0)
    {       
      return;

PanelLogger11ShareVer104.ino (13.4 KB)

have an ancient drive that has an old analog display.

Sorry, a what?

I am pretty sure I am using the correct resistors in order to output 0 - 5 volts for the Arduino to read

What does your voltmeter say?

Are there any issues with my drawing?[

yeah... I don't wee a drawing. :wink:

Your code is incomplete so it's hard to know what's going on. But, I suggest you use the serial monitor to "look at" your variables. If you don't know how to do that, start with the [u]Analog Read Serial[/u] to look at your raw ADC readings. Then, "print" your mapped variables and/or any other variables until you see where something's getting fouled-up.

And, you might need to simplify your code and write some little test programs to test & debug the inputs & outputs separately.

DVDdoug,

Thank you for the fast response, I have corrected my post and you should see a picture now, I have also attached the whole code.

The drive I am talking about runs a large 150hp electrical motor. What I am doing is tying into the vin on each gauge.

I will be testing the readpin a10 on the arduino when I get home from work. I will report back confirmation.

Thanks again, should have more for you in a couple of hours.

Andrew

Probably, you don't need OPA after all, 3 resistors divider is easier option.
What important is safety, if it's industrial motor check for galvanic isolation.

That circuit cannot do what you want, and the op amp is probably oscillating because you have not included power supply decoupling. Decoupling capacitors on the voltage divider at +In, and on V+ and V- are absolutely required. Use 100 nF to ground, connecting as close to the IC pins as possible.

With that op amp, the voltage swing at the output is (V-)+2 to (V+)-2, which leaves you about 1 V swing total when you power it with 0 and 5V. If your gauges are intended to take 0 to 10V, you will need to power that circuit from a 12V supply.

And, since 0 V output is not possible with V- connected to ground, you need a negative voltage supply as well. There are "rail to rail" op amps where the output voltage will swing to ground.

datasheet for OPA227/228 here: http://www.ti.com/lit/ds/symlink/opa227.pdf

First let me thank all of you for your help and input.

jremington, you are correct I just discovered that the opamp I was using would need a minimum of 7v bipolar supply.

I am looking at this rail to rail lower power opamp. Please let me know your thoughts. I would like to keep with a though hole option because I printed a bunch of PCBs sometime ago. At that time I did add the ability for an opamp, but until now I did need to.

I have also attached a LTSpice sim of the circuit showing it should work, but you know sims. I will forsure take your advise on the 100 nf decoupling capacitors.

Please let me know your thoughts on that linked opamp above. Thanks again.

Andrew

The MCP6041 is intended only for high impedance loads (typically 50K Ohms) and can't supply more that a few microamps output current. It is also extremely slow.

Your gauges are likely to be very low impedance (I would not be surprised if they were a few hundred Ohms), in which case that op amp won't work at all. Measure the gauge terminal resistance and post the value.

jremington, I would guess you are correct. I am not near the gauge to measure the Ohms but I am positive you are correct.

between MCP6021 and MCP6271 opams whcich would you see ideal for this application.

Thank you so much you have been a big help.

Andrew

I reread your first post and decided I don't understand your intent.

What should the Arduino do?

What is the op amp supposed to do?

Did you read reply #3?

MaterT already told in post#3 that you don't need an opamp to read negative or positive voltages.
Just three resitors of the right values can convert "-10volt to +10volt" to a positive voltage for the Yún.

So why do you want that opamp?
Leo..

Would the 3 resistor divider be linear like the opamp? One would have to then compensate with software which I would like to avoid if possible should it be non linear.

Well that and I have been trying to figure out where the formulas are so I can calculate which resistors to use for -10v/10v to 0 to 5 volts. That simulator is very handy and I have been trying find the correct resistors.

Thanks you everyone for your help thus far.

Andrew

Disregard last I was able to find the correct resistors a 5k and (2) 10K. I will try the divider circuit. Thanks

AndrewLParsons:
Would the 3 resistor divider be linear like the opamp?

Yes.
Leo..

Hi,
When you measure the voltages on the meters you want to monitor, are you measuring across the meter terminals?
If so, are you sure that one, possibly the negative terminal of the meters are all connected together and connected to the "motor drive" gnd reference?

If you are not sure, please do two measurments, gnd to meter negative and gnd to meter positive and see if you measure any potential.

Thanks.. Tom... :slight_smile:

Wawa:
Yes.
Leo..

AndrewLParsons:
Would the 3 resistor divider be linear like the opamp?

Resistors are about the most linear components that exist if you don't have self-heating issues.

Ohm's law basically - resistors have a constant V/I ratio at a given temperature and pressure.