Opamp wild readings, help please.

Thread Starter

Andrew P

Joined Mar 7, 2018
5
Hello and first let thank anyone who is looking at this and wants to help tackle my opamp problem. Below is an drawing with a opa228P opamp along with my Arduino code. 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 of them all, luckily most of the gauges are from 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 even tho the vin remains the same on. So, I added a for loop to try and average them out but the swings are still pretty large. Also as you can see in the maping I left some deadzone to help calm down when at (0). Are there any issues with my setup? Do I have to add or remove something in order calm down the readings? Any help in this matter would be greatly appreciated. Please let me know if you need any more info and thank you for your help.

20180307_103451.jpg

Code:
//***********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;

Andrew
 

ericgibbs

Joined Jan 29, 2010
21,439
hi Andrew,
Welcome to AAC,
Is the incoming Vin noise free.? have you checked using an oscilloscope.
If it noisy you could add R/C filtering.
E

EDIT:

This is a LTSpice sim of your circuit, looks OK. I am using a rail to rail OPA.
I guess you know of the signal inversion.?

Update:

As Bob points out the OPA228 is not suitable, that's why I used a rail to rail OPA
Look at the MCP6001 series OPA's
 

Attachments

Last edited:

BobTPH

Joined Jun 5, 2013
11,514
Powered by a single 5V supply, the input and output range of that opamp is 2 to 3V.

You need an opamp with rail-to-rail inputs and outputs, or you need a bipolar supply of at least 7V.

Bob
 

Thread Starter

Andrew P

Joined Mar 7, 2018
5
Thank you Bob and Eric for the fast response and even better a solution to try. I will report back once I have tried the new series of opamp. No changes are need other than the opamp.

Wow, thank you guys, I have been struggling with this for some time.

Andrew
 

OBW0549

Joined Mar 2, 2015
3,566
Scratch last message since it is surface mount and the PCBs I have made would cause some McGivering. Would the below through hole opamp work? It can operate at a lower power, is rail to rail and best of all it has the same pinout as the OPA228 so it should fit nicely into the PCB.

https://www.digikey.ca/product-detail/en/microchip-technology/MCP6041-I-P/MCP6041-I-P-ND/413363
It might or it might not; that op amp is extremely slow, with a gain-bandwidth product of only 14 kHz. But with the very low gain of your application circuit it might be sufficient if the range of your signal frequencies doesn't exceed a couple of hundred Hz.
 
Top