position tracker with op amp - Page 1
Forum section: electronics / beginners

author: Simon
author_rank: Unknown
timestamp: July 21, 2011, 08:47:03 pm
content: Right, here is the deal. I have a water valve with an incorporated potentiometer to feedback the valves position (open/close or partly)Now I've been asked to design a circuit to control the valve with a potentiometer, so if I turn the control pot up the valve will open more and the circuit will determine when to stop driving the motor when the feedback pot is basically sending back the same voltage as the voltage set by the control pot.So I assumed this was a comparator job. I started with two comparators both taking the same signal on the inverting and non inverting inputs but with the inputs switched. So theoretically when one is has a H output the other is L. I'm using an LM339 and naturally our good friend offset came along and there is a state where both outputs are on. This means that as I'm driving the motor that opens and closes the valve with a H-bridge one almighty BANG !So I experimented and put a fixed potential divider on the output of the control pot so that there is another control output at 99% of the value set by the control pot. So now each op amp gets a slightly different control signal and I get some window where both outputs are off.Now I'm feeling really pleased with myself until I realized that my gap between the control pot output and the secondary output off the fixed divider at 99% has to be at least the offset voltage or twice it maybe and that the lower i go the smaller the actual voltage "window", so with a 2% value on the control pot I'm back to square one ! but the position pot only goes down as far as 7.7% anyway and a trial at 4.6% seems reassuring.Have i found the simplest method of doing this or am I missing something obvious. ? Are there comparators with very good offset specs that don't cost the planet ?I could use a micro controller and program in as much hysteresis as I want, but I'd rather not or at least know i have an analogue solution up my sleeve.

author: ejeffrey
author_rank: Super Contributor
timestamp: July 21, 2011, 09:18:28 pm
content: How about using a single comparator as a direction controller, and an absolute value circuit followed by a comparator as an enable control for dead-band control. The first comparator always says 'open' if the valve is too closed and vice versa, but the second comparator disabled the bridge completely if the absolute value of the error is less than 0.1 volt or something. That should let you separately control the setpoint and the deadband

author: gregariz
author_rank: Frequent Contributor
timestamp: July 21, 2011, 09:25:40 pm
content: Hmm... double ganged potentiometers... maybe a second channel into a second comparitor with a known offset when they are 'close' that you can use as a 'close' indicator.

author: Simon
author_rank: Unknown
timestamp: July 21, 2011, 09:26:40 pm
content: ejeffrythat's an interesting possibility, so basically I'd have to work out the difference between the two pot outputs and if over a certain value let the valve operate. The only thing is it would have to work with both polarities, I'd need a differential amplifier to get the difference and then compare that to my absolute "offset"

author: Simon
author_rank: Unknown
timestamp: July 21, 2011, 09:27:45 pm
content: Quote from: gregariz on July 21, 2011, 09:25:40 pmi did think of that but assumed that the cost of a dual pot might be prohibitive but then I have not looked, might be the most robust solution

author: Simon
author_rank: Unknown
timestamp: July 21, 2011, 09:35:05 pm
content: yea, looking at prices, they are not bad, I can get a dual pot for under £2.00 although a single pot is as low as £1.00

author: gregariz
author_rank: Frequent Contributor
timestamp: July 21, 2011, 09:38:22 pm
content: Maybe you could just take your position signal from the single channel pot and split it 2 ways.... one way to your position comparator... and another way through a diode or 2 with known drop for the 'close' indicator.

author: Simon
author_rank: Unknown
timestamp: July 22, 2011, 05:21:20 am
content: I thought of that but 700mV is a lot of window on 5V range, but maybe a diode drop at low current is much less ?

author: ejeffrey
author_rank: Super Contributor
timestamp: July 22, 2011, 07:24:31 am
content: Diodes do have lower forward drop at very low current, but it is difficult to reliably operate them as such. A diode will have a few 25-40 mV forward drop when operated at a forward current equal to its reverse leakage: usually nanoamps, and very temperature dependent. In this regime, the input bias current of your op-amp/comparators will have a big affect on your offset voltage. You could use a schottky diode with its lower ~200 mV forward drop if that is low enough.Another option is to use a op-amp voltage adder to generate a second trip voltage a fixed voltage above the potentiometer's set-point. The problem here is that voltage adders are inverting circuits. You will have to invert twice to get the signal back to the same polarity as the original.

author: Simon
author_rank: Unknown
timestamp: July 22, 2011, 08:24:03 am
content: yes a voltage adder sounds more reliable and as all opamps come 2 in a DIP8 that will only add one IC, I need 50mV offset idealy over the whole range. unfortunately I seem stuck with 5v in. If i could increase it, it would make the offset less of a problem

author: tecman
author_rank: Frequent Contributor
timestamp: July 22, 2011, 02:05:38 pm
content: You are trying to build a closed loop control system.You need to do three things:Your H bridge clearly can have cross conduction. You should either add some logic or a transistor or two to prevent cross conduction. The H bridge transistors should be fast enough that a fast switching input will be slower than the transistors, so you will not kill anything with a fast input change.Next you should use an op-amp to generate the error (command-actual) and then follow that signal with some gain. The amount of gain is a calculable number, but beyond the scope of this post. Too much gain and you will oscillate, or chatter, around setpoint. Low gain will end up with greater and greater error. Put in an amp stage with 1-10 gain and a pot to adjust the amount. The output of the gain stage can drive the comparitors, or you can use op-amps as simple comparitors to drive transistors.Last is is likely you will need some compensation if you need higher accuracy. This is because when you tell the motor to stop, it will still move a bit due to inertia. Most common scheme is to add a lead term (derivative) in the signal from the error amp to the gain stage. This lead term will sum with the error and result in slightly more error, "anticipating" the final set point and cutting off the motor a bit early, and if set correctly the motor will coast into position. This is known as a PD controller.Using these schemes, accuracies better than 1% can be achieved. The greatest source of error may then be variations in load on the motor which will cause the "over run" due to inertia to vary when you cut off the power to the motor. Higher gains and more accuracy also mean that you will be more sensitive to noise, power supply variations, etc.paul

author: Simon
author_rank: Unknown
timestamp: July 22, 2011, 02:53:14 pm
content: well I have just tried my design out with a real valve. And yes there are problems as anticipated. The top end is not too bad but hard to control and the bottom end keeps oscillating, so clearly not enough hysterysis on the bottom and too much at the top.I will attempt the micro controller method. This will also allow me to identify the real top and bottom of the range as it is about 7.7-82% not the full 0-100%

author: Unknown
author_rank: Unknown
timestamp: July 22, 2011, 10:11:55 pm
content: Cloded loop control indeed, DIY is very much reinventing the wheel when eBay will be littered with sub $50 PID/PI controllers that will solve your problem.If you want to understand the operation a google search of PID or PID circuits should find lots of results. (hint: you wont want/need the "D" in your application).

author: tecman
author_rank: Frequent Contributor
timestamp: July 22, 2011, 10:41:57 pm
content: Quote from: Uncle Vernon on July 22, 2011, 10:11:55 pmActually you do not want I in the control. Simple I will always be unstable in a positioning control. D is what is needed. Since this is a discrete output control, the D can compensate for lag time associated with switching and inertia. Switching time is a non-linear delay time, which if consistent, can be compensated. Motor inertia is also well compensated for by a lead term.paul

author: Unknown
author_rank: Unknown
timestamp: July 22, 2011, 10:57:42 pm
content: Simple I? do elaborate.

author: Simon
author_rank: Unknown
timestamp: July 23, 2011, 11:25:11 am
content: the pid units on ebay are all for temperature and large units. My intention is to produce a valve controller that will be part of a vechicle heating/cooling system so a large unit with a display is out of the question

author: Unknown
author_rank: Unknown
timestamp: July 23, 2011, 12:24:00 pm
content: Quote from: Simon on July 23, 2011, 11:25:11 amWouldn't temperature be the parameter you would need to regulate with a heating/cooling system?

author: Mechatrommer
author_rank: Super Contributor
timestamp: July 23, 2011, 01:39:37 pm
content: how about failsafe? you may solve alot of your problem with a micro with adc. here's one suggestion for you... atTiny10! cost only few cents

author: tecman
author_rank: Frequent Contributor
timestamp: July 23, 2011, 01:59:31 pm
content: Quote from: Uncle Vernon on July 22, 2011, 10:57:42 pmBy simple I i refer to an integrator that is a fixed value and always on. Typical of many controllers, especially older designs. In a positioning system, an integrator can be used, but only when it is a switched term. The I can be enabled only very close to the setpoint where a number of non-linearities can effect the system. Typically within 1% or less error.If you analyze a typical positioning system, you have a position command and position feedback. The error is position, but most control devices provide a velocity output, such as a motor. This makes the control an integrating system. The position error provides a velocity output, or in other terms the error is the integral of the output. If you add another integral term in the loop, you have two cascaded integrators. Add an overall loop gain of more than 1 and you have an oscillator. 90 deg from each integrator plus 180 deg from the feedback (negative feedback which is by definition opposite of the output, or 180 deg). This is 360 deg total. Add gain and it is a classic phase shift oscillator.In most controls, near setpoint, the system becomes non-integrating. This is generally due to friction in the system. If you think about it, voltage to the motor at very low values will not cause it to spin, but only "wind up" or move slightly against friction and load. In this region an integrator will help push closer to the setpoint. So you can apply an integrator only if it is switched on in this region around setpoint.paul

author: Simon
author_rank: Unknown
timestamp: July 23, 2011, 02:08:15 pm
content: Quote from: Uncle Vernon on July 23, 2011, 12:24:00 pmyes but I have no been asked for a dispaly or anything but just the controller to be integrated with the rest of the system. The control will be a potentiometer. Sounds a bit odd but that is what I've been asked for. The engineer in charge is a bit dippy about electronics though. I'll do as told and then offer suggestions as i get more information about the whole system

author: Unknown
author_rank: Unknown
timestamp: July 24, 2011, 08:21:36 am
content: Quote from: tecman on July 23, 2011, 01:59:31 pmI see what you are getting at. Error correction applied that way is not really integral control.QuoteBut control of a heating/cooling valve isn't like a positioning system the Process Variable - Temperature is not going to change at a rate matching the valves position. More often than not, a well tuned loop will have a large P band and will increment via a slowly ramping I percentage.QuoteAgain I don't disagree I think we were assuming two different problems based on the information Simon provided. Given what Simon has written subsequently I think he is way off the mark, he only requires open loop control.

author: Unknown
author_rank: Unknown
timestamp: July 24, 2011, 08:38:15 am
content: Quote from: Simon on July 23, 2011, 02:08:15 pmNot that odd of a request at all, almost every basic automotive temperaturesystem works that way. The vehicles occupants are the feedback. It's open loop control. I'd forget the motor's pot it will just complicate your design.What configuration is the motor that you want to use single wound reversible or double wound? A spring return proportional actuator would be the simplest option, use your control pot to PWM a positioning signal.

author: Simon
author_rank: Unknown
timestamp: July 24, 2011, 08:46:12 am
content: no I need the pot in the motor to tell me the valve position or i won't knoe if it is open or closed. my control pot is to tell the system where I want the valve to be.I've opted for an mcu design and am getting better results except that I'm having overshoot problems now even though I've set a "dead window" To make it near viable the dead window has to be so large that it becomes sluggish.The motor is a simple 24V motor and you have to reverse polarity to drive it the other way, I'm using a H bridge control

author: IanB
author_rank: Super Contributor
timestamp: July 24, 2011, 09:11:41 am
content: If I understand correctly the positioning motor is either "on" or "off" in either direction and you can't regulate it's speed? But possibly you could use PWM to adjust the power fed to the motor? Overshoot is going to be a problem unless you can reduce the power to the motor as the position gets close to the set point.As has been pointed out above in the thread, the place to start would be simple proportional control action with a gain to be determined. You apply power to the motor in the right direction in proportion to the position error. Once the error is greater than a certain percentage you will likely be applying full power to the motor, but that is fine. It will just cause the motor to track as fast as it can when the error is large.With a simple proportional control scheme you will likely find that stiction causes the motor to stop entirely before it actually reaches the set point. This will limit your positioning accuracy. You can either increase the gain and risk overshoot, or introduce alittleintegral action to help wind out the positioning error. A really good positioning system might include derivative action, but that is hard to tune and I would tend to leave it out unless you know how to set it up. The main advantage of derivative action would be faster control action without overshoot and I doubt that is critical in your application.You don't want to include a dead band or hysteresis in your system as that will just reduce the positioning accuracy. But you do of course want to include a lockout system so you don't activate both forward and reverse drive at the same time. You will want to hard wire this lockout in the drive electronics as a fail safe system and not try to include it in your control logic.

author: Simon
author_rank: Unknown
timestamp: July 24, 2011, 09:22:16 am
content: yes the power control option looks like the way to move towards.I have found that the manufacturers spec of min position @ 7.7% and max position @ 82.5% is rubbish. it is actually min 20% and max 50% so I've been fine tuning the control potentiometer range with fixed resistors and this is helping. Some dead window is surely necessary as you get a +/-1 bit error at least from the ADC so I need to "filter out" small fluctuations that mean nothing ?So using power control basically I'd use the value that defines the different between control and position pot as a rough PWM power figure so that the speed drops drastically as the correct position is nearly attained.Well the PIC12F615 that I'm using has a PWM in it but direction control then becomes a problem, unfortunately there is only one channel, perhaps I can implement a second channel using logic gates so that 2 enable lines decide which side of the H bridge to run. I'll have to see if I can do it with diodes and save on an IC

author: Unknown
author_rank: Unknown
timestamp: July 24, 2011, 09:24:14 am
content: Quote from: Simon on July 24, 2011, 08:46:12 amIf you selected the actuator you selected the wrong one, you've made things a lot more complicated than they need to be.QuoteAssuming the mechanical hardware was not your choice, an MCU is probably your best choice. Using a temperature sensorwould make life even easier but I understand if that isn't an option. Hint you want to slow the action as much as possible, response of the overall cooling/heating will be much slower than any actuator.QuoteIn execution, sluggish will be a good thing!

author: Simon
author_rank: Unknown
timestamp: July 24, 2011, 09:39:26 am
content: by actuator do you mean the valve ? no not my choice, it is something we already use in other stuff with a controller but now they want a stand alone one.By sluggish I meant that it responds in too big a steps. it stops ok but then needs a large shift of the control pot to move it again and that makes it move by a large amount: I loose fine control.I have another idea, I could do a burst of manual PWM or just a single pulse after which I recheck the positions rather than wait for the whole program to re-run the loop, or I just send one short pulse and then go back and recheck positions. I could implement it on small position changes and let it run full power until the position becomes that close, I can get 1-2 uS pulses out of setting a bit high and then low.The guy running the overall project is a bit of an old fashioned type. Relays were high tech to him, infact our last air con system for our last military design used a bloody panel full of relays. Now that he wants to move into more automation and electronic control he will be giving me a lot of wrong information as I'm sure he will eventually figure out that the control pot should not be directly positioning the valve but should be a temperature control that will then control the valve to control the temperature.Another plus to using a pic: I can change things later mostly in software without starting from scratch. His request is infact a bit odd, unless he really just wants crude heat power control, I mean as the engine warms less valve opening will be required, you'd think that having put electronic control in there you'd take the person out of the control loop and let them set the temperature they want and let the system do the thinking instead of having a person keep altering the control as it gets hotter as the engine warms up

author: Unknown
author_rank: Unknown
timestamp: July 24, 2011, 10:51:26 am
content: Quote from: Simon on July 24, 2011, 09:39:26 amValve is the bit that regulates the water, actuator is the motor that drives the valve. In most cases they are separable, your may be a fixed assembly.QuoteI'd assumed that, in this application you would usually select a spring return actuator that works much like a servo. PWM or control voltage from the pot and your done.QuoteThat is going to be your best strategy, you need to just inch the valve, so your pulses will need to be short. Even with this you will be battling some hysteresis. You are never likely to get fine control, but you should be able to achieve a reasonable degree of positioning.QuoteDon't totally dismiss that approach, in harsh environments KISS principle is best. It's take 30 years to get real reliability into automotive electronics.QuoteNot that odd, what you are proposing is "climate control" there is a hell of a lot of vehicle operating without any form of closed loop heating control and rather than the electronics a simple bowden cable positions the valve.

author: Simon
author_rank: Unknown
timestamp: July 24, 2011, 11:03:33 am
content: well I was getting things better until the thing has just decided to pack up. Haven't a clue what happened. But yes even with small pulses controlling it is a problem. I think I need at least 30-50 uS pulses or it won't move, of course once it has liquid going through it things will change.To make sure i don't burn out my mosfets I'm tying the gate of one N channel to the drain of the other one so that both sides of the bridge cannot come on together as lots of switching is causing problems with them heating up.My comments about the person running the project relate to the fact that he is a bit of a drip. He knows the theory of air con systems but his practical implementations often have a lot of problems, our last military job was redrawn a number of times and the last of over 100 units were still going out with latest mods. He has no idea about electronics and getting him to understand things is hard

author: Mechatrommer
author_rank: Super Contributor
timestamp: July 24, 2011, 12:22:44 pm
content: Quote from: Simon on July 24, 2011, 11:03:33 amfire him!

author: Simon
author_rank: Unknown
timestamp: July 24, 2011, 12:25:32 pm
content: Quote from: Mechatrommer on July 24, 2011, 12:22:44 pmwell he is above me and soon to retire i think, the next in line is an even bigger asshole.He took the valve home and tried to control it with a potentiometer on it's own, what the hell he thought he was doing i don't know

author: Simon
author_rank: Unknown
timestamp: July 24, 2011, 03:10:05 pm
content: well I have achieved some reasonable success. I'm pleased but not entirely satisfied, it all seems to lie in the detail of the pulse width duty and frequency to match the motors mechanical properties. And of course all will change when the valve door is onder 2 Bar of pressure from the coolant that will hopefully help stop some overshoot.Now i need to nail down the ADC Vref details, the max position voltage the sensing pot sends back is 3.5V (70%) so I am using an external reference for the ADC to help increase the dynamic range of the system, I may yet fiddle with the math in the program to make use of the 0-20% portion of the control pot that is unsused as the minimum position pot output is 1V (20%) so I could mathematically scale it to help make fully closed at 0 and fully open at 100% on the control pot

author: Mechatrommer
author_rank: Super Contributor
timestamp: July 24, 2011, 09:24:55 pm
content: Quote from: Simon on July 24, 2011, 12:25:32 pmnot so bad i think, he's willing diy and get his hand dirty. ask him to join mechanical forum or here

author: Simon
author_rank: Unknown
timestamp: July 25, 2011, 05:58:20 am
content: Quote from: Mechatrommer on July 24, 2011, 09:24:55 pmnot so bad i think, he's willing diy and get his hand dirty. ask him to join mechanical forum or hereI doubt he'd even be able to use a forum actually. To be honest if you have a valve with a pot in it and the manufacture has told you (He has a nice big datasheet he probably can't even understand) that you need control circuitry and you try and control it with another pot your kind of beyond hope. I mean it was only once he realized he wanted to bite off more than he could chew that he came to me (the underling working as goods in inspector) to find a solution.This is the guy that was going out to clients in singapore with an analogue oscilloscope in his hand that he did not even know how to use (and the settings were so messed up that it took me a half hour to even get something on the screen just before declaring it broken). When it was really needed he brought it to me and asked me how to use it, at that point I told him that no an old analogue scope was not going to be of use in capturing back EMF and that I'd bring my own digital scope in.