Go Down

Topic: Differential amplifier behaving badly (Read 5035 times) previous topic - next topic



I would like to control the speed of a slot-track car with PWM. This part is working (more or less), but I would also like to measure the current going to the motor of the car (ultimately, detect with the Arduino when the current suddenly drops, meaning that the car has started moving). I found this link http://robots.freehostia.com/SpeedControl/SpeedControllersBody.html#10 which uses a shunt near the power supply and a differential amplifier to amplify the voltage across the shunt. The output of the amplifier can then be read by the Arduino's analog input. In theory, it's all well.

In practice however, my circuit has a very high output offset, which makes it completely useless. I thus made the following experiment:


This represents the case where the voltage across the shunt is null, meaning that the car is stopped. Instead of a shunt, I just short-circuited the two inputs of the differential amplifier (point 4 on the schematics), and I measured the output voltage (point 3). When point 4 is connected to 0V, the output is 1.3mV, which is expected (real op amps have a small offset) and acceptable. When point 4 is connected to 5V however, the output is 650mV, which is not what I expect and makes my circuit completely useless (in the speed controller circuit in the link above, one input of the shunt is connected to the 12V of the power supply, so when the car is not moving, a situation equivalent to that with point 4 connected to 5V will actually occur). Details of the experiment and measurements can be found at http://users.jyu.fi/~mweber/blog/Bricolage/infernal_op_amp.html.

The big question is thus: what did I do wrong? The speed controller circuit in the link above works, so I assume the design to be sound. The op amp is almost the same (LM324A in my case, LM324 above), the only difference I can see is in the way the op amp is supplied. The schematics above doesn't mention anything about that, and my op amp is powered between 0V and 5V. The last hypothesis is that I didn't wire the chip correctly (but I tested my circuit it by feeding the differential amplifier with voltages above 1 V, and the output was what I expected).

Any suggestion ?


You can't run the op-amp off 5V if you are feeding differential signals sitting up at 12V into it. In general the power rails must always be higher that the maximum input voltage.
What you are seeing looks to be perfectly normal, in fact I would expect to see your op-amp sitting up close to the rail, (it isn't going to get any higher).


Sorry for not being clear enough: the original design uses 12V, but in my experiments, I use 5V for both the supply and for the signals. No 5V/12V mixing there.

What to you mean with "op-amp sitting up close to the rail"? The 0.65V output is nowhere near the 5V of the supply, and the values at the op amp's V+ and V- are around 2.5V, which isn't anywhere near 5V either. Did I miss something?


It is a bit confusing as to what you measured originally. You just said that the DC offset was way too high but no mention of what it was. The amp is not a rail to rail device so you can't go putting inputs at the rails, be it 0v, 5v or 12v and expect it to behave. So I don't think you tests grounding point 4 tell you much. See what happens if you set point 4 from the 3v3 supply from the arduino.
I would use a +15v supply when trying to measure your 12v signals. Also look at the data sheet for the common mode rejection ratio as that will also make things worse.

Remember the DC offset gets amplified by the gain you have set.


Let me clarify, then (all what folows is in the second link of my original post, so no surprise there):

  • The op amp is supplied with +5V and 0V (LM324 is  single supply op amp, so it should work)

  • V+ is in the middle of a voltage divider (10K+10K between 5V and 0V), so V+ is at about 2.5 V (measured 2.52 V). (This is below the specified limit of Vss-1.5V, so it should be OK)

  • V- is also in the middle of a voltage divider (10K+10K between 5V and Vout), and the measured value is 2.83 V

  • The theoretical gain of the differential amplifier (the op amp and the four 10K resistors) is about 1, so the DC offset shouldn't be amplified by much.

  • (V+ - V-) = -0.32 V and Vout is measured at 0.65 V

The last point is wrong, because it renders the differential amplifier useless for measuring any voltage below 0.32 V. I just remarked earlier today that V- > V+, which is probably the reason why this doesn't work, I suppose we need to have V+ > V-.

Now, the original design of the speed controller is like that:

There is a LM324 used as a differential amplifier (with a gain of 480), which measures voltages of up to 0.038 V. This design seems to work (according to its author at least), but I dont understand why. The only difference it makes with my design (apart using 12V instead of my 5V) is that it doesn't specify how the op amp is powered, and the author might assume it's supplied from a dual power supply. From the datasheet of the LM324, it should be possible to make a differential amplifier with a single supply (there is such a schematic), but it doesn't tell what are its limitations (or then I don't understand them). My understanding is that it should work, but in practice it doesn't.


May 11, 2011, 05:13 pm Last Edit: May 11, 2011, 05:15 pm by pwillard Reason: 1
The op amp is supplied with +5V and 0V (LM324 is  single supply op amp, so it should work)

I think Mike and I are trying to disagree with what you believe.  The feeling that it should work in an expected way with single supply across the whole range from 0-Vcc is likely expecting too much. Also note that at all times, with your circuit, you are presenting NO difference to the OP AMP since you tied the two differential inputs together. Your results are only showing you the errors introduced by the OP AMP itself.  

The original circuit appears to be designed for dual rail operation and will allow for negative swing.  If you are not doing a negative swing on the power feed line... the circuit is simply overkill.  If you really want to use this circuit with single supply and in a rail to rail mode you might need to be using a true rail to rail IC like the TS272.

Page 10 of the 324 datasheet shows a sample current monitor circuit.  You will note that it does not employ a a variant of the differential circuit you are using but instead takes advantage of the existing differential inputs on the LM324.  The key part of the circuit is that the + input reads the supply voltage and the - input reads the drop across the resistor as load flows through it. It has a transistor in the closed loop/gain path but you can adjust this to being just a resistor in the feedback path... gain calculations apply.

There are also parts designed specifically to perform this function, like the ZXCT1009.


Do you account for  when the current has spiked as well, indicating that the motor has stalled/jammed?

I would try this approach of a non-inverting amplifier vs the approach you have now
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


Pwillard: thanks, the problem was exactly that the op amp needed a dual supply. I created a virtual ground for R3 with a voltage divider, and now the op amp is behaving as expected. The ZXCT1009 looks interestin, but I don't have the courage to play with a 3x1 mm large device. I intend to use proto board, not to make my own PCB, to keep the costs down, so fitting an SMD device of that size looks too complicated.

CrossRoads: my ultimate goal is to detect when the current suddenly drops, meaning that the car has started moving, and then reduce the PWM frequency to drive it at the desired speed. The problem with this old slot-car track is that when the car actually starts moving, the driver must immediately slow down to prevent going off the road. I want to try if software assistance can prevent this.


I once made a controller for an electric train set. Basically it was a phase locked loop (PLL) where the motor took the part of the voltage controlled oscillator. I used the voltage spikes across a current monitoring resistor to feed into the PLL.
What happens if the train was not making contacts with the circuit through the rails is that the DC feed to the PLL (the motor) goes up. But as soon as it starts to move, instantly comes down to the required speed. This achieved a realistic slow start speed for the train.
Mind you this was in the late 70s when there were no commercial electronic controls for trains.


I know nothing of PLLs (I just read a few Wikipedia pages about it), but that sounds interesting :)

How did you control the speed of the train? Variable voltage or PWM? And then, what were the two phases that were being compared by the PLL? Voltage and current of the electric motor?

On the op amp front, I'm about to give up on either measuring the current with a shunt and an amplifier, or on using the LM324 for that. I would like my system to be made mostly of software and as little hardware as possible, but the more I experiment with the LM324, the more problems I see: the motor is supplied with 12 V, so I'd need an even higher voltage for the op amp, which means using more support electronics to measure the bloody current.

Is there another way to detect that a PWM-driven motor is stalled or running, than trying to sense the current?
Alternatively, I could use a P-FET to drive the motor, use low-side current sensing and a simple non-inverting amplifier...


A PLL gets two oscillators going atnthe same rate. So the train's motor was one oscillator and I made anothern oscillator with a frequency controlling pot as my speed control. So to change then speed of the motor I simply changed the speed of the oscillator.

Bottom sided current sensing is less problematic.

Go Up