View Full Version : Op-Amp Design
LukeZ
May 19, 2005, 04:09 PM
I’m in the process of trying to design an op-amp circuit to interface a pressure sensor to my PIC. I’m new to op-amps but I found this seemingly useful application note (http://focus.ti.com/lit/an/sloa030a/sloa030a.pdf) on the TI website.
I’m going to simplify my problem a bit for the sake of discussion. Let’s assume my sensor outputs a linear 0 to 5 volts for the range of pressures from sea level to 50,000 feet. This voltage range is compatible with my A/D converter, so I could hook it straight up. However, my A/D is 10 bit, so this would mean I’d have a resolution of only about 50 feet per bit. Let’s say I want more.
Specifically, let’s say I’d like a resolution of 1 foot for altitudes up to 1,000 feet. Beyond that and up to 20,000 feet, let’s say I want a resolution of 20 feet. Above 20,000 a resolution of 50 feet is fine.
For now I’m just interested in figuring out “Range 1” (0 to 1,000 feet, 1 foot resolution). After I get that worked out I’ll have to learn how I’m going to adjust the op-amp circuit for other ranges.
Let’s assume I determined that my sensor puts out 1 to 2 volts for 0 to 1,000 feet. I know this doesn’t actually fit the assumptions but it makes the math easier.
Using the app note as a guide, I figured I could treat my sensor as if it actually only had a range of 1 to 2 volts. I would use 1 to 2 volts as my Vin and determine a straight line formula for my desired Vout.
This is the formula I would derive:
Vout = 5*Vin – 5
You can see that if you plug in 1 volt for Vin, Vout equals 0: the A/D’s lowest reading. If you put in 2 volts for Vin, Vout equals 5 volts, the A/D’s highest possible reading. So for the range of 1 to 2 volts on the sensor, my A/D would be seeing a full range of 0 to 5 volts. This would give me 10 bits of resolution over just the small range of sensor output that I’m interested in.
So now for the questions. ;)
Of course the sensor can actually go lower than 1 volt and higher than 2. Plugging those outside numbers into the equation gives bogus results for Vout. For example, if I was at 50,000 feet the sensor would put out 5 volts, and according to the formula above this would mean a Vout of 20 volts- since the voltage supply is only 5 volts this would not be possible. I’d think all this would do is mean that my A/D sees 1,001 feet the same as it sees 50,000 feet: they would both equal 5 volts. Still, I don’t know if this might not be good op-amp design. Is this something I should concern myself about?
Of course as I mentioned earlier what I really plan to do is have my uC change the op-amp circuit after it clears 1,000 feet, to lower the gain. Haven’t gotten to this stage yet but you can see the idea.
Am I even on the right track here? :confused:
Oh, for curiosity’s sake, the actual pressure sensor I’m using is an MPX4115AP (http://rocky.digikey.com/WebLib/Motorola/Web%20Data/MPX4115A,%20MPXA4115A%20SERIES.pdf). In fact it outputs 0.2 volts to 4.8 volts linearly from 15 kPa to 115 kPa.
Luke
chrisgood
May 19, 2005, 04:18 PM
Use a non-inverting voltage amplifier.
This page shows how to get 4 foot resolution from the MPX4115A with a amplifier gain of 16.
http://www.chrisgood.com/uav/avionics/sensors_slide0031.htm
Chris
LukeZ
May 19, 2005, 05:23 PM
Right. I understand how to create an op-amp that will give a specified gain.
My question is, from a desire to understand the circuits better, are there any issues to be aware of outside of the 'limits' of the gain equation. In your example, above 4,000 feet what is the result- both for the op-amp circuit itself (trying to drive a Vout greater than Vss), and for the AD converter (I assume it just sees a constant, pegged 5 volts or whatever +Vref is)?
If sensor values that would cause the op-amp output to attempt to go above Vss or below Vdd simply result in a pegging out at either Vss or Vdd, with no adverse affect, then fine.
But I'll wait to hear some others weigh in on the first question before I go on to the next...
Luke
chrisgood
May 19, 2005, 05:35 PM
The op-amp is driven by a Vcc of 5 volts. It can't output a higher voltage than the drive voltage. You would end up seeing everything from 4000 feet and up (or whatever exactly your supplied Vcc corresponds to) as the max altitude.
Chris
FenceMagnet
May 20, 2005, 10:19 AM
Please don't forget that the pressure/altitude relationship is far from linear.... thought at "model" altitudes, the curve isn't "horendous"... it's actualyy pretty close!
Altitude (feet) Pressure (inHg) %Deviation from an EndPoint Straight Line
0 29.9213 0
100 29.8133 .0050
200 29.7056 .0089
300 29.5983 .0115
400 29.4913 .0130
500 29.3846 .0135
600 29.2782 .0130
700 29.1721 .0114
800 29.0663 .0087
900 28.9608 .0051
1000 28.8557 0
:cool:
chrisgood
May 20, 2005, 11:41 AM
This is the equation to get pressure altitude based on static pressure and altimeter. This came from the standard altimeter equation from Air Force Flight Test Center AFFTC-TN-59-22 "Flight Test Engineering Handbook", part II.
101325 pascals = 14.696 psi [= 1 standard atmosphere = 760 mm Hg = 29.92 in Hg]
PressureAltitude =
(1.0 - pow((staticpressure_pascals/altimeter_pascals),0.19026))/6.87535e-6;
Chris
FenceMagnet
May 20, 2005, 01:44 PM
the numbers I quoted were from the "U.S. Standard Atmosphere" published in 1962 by NASA and defines the ICAO Standard atmosphere to 20 KM.... believe it or not, it has 100' increments from -16,500 to 120,000 feet! :D
:cool:
LukeZ
May 20, 2005, 02:39 PM
Ok, right. I've got the formula for pressure versus altitude and other such things as air density. When I said linear I meant the voltage output from the sensor is linear with pressure.
Back to op-amps, here's question 2. I know the op-amp circuit I'd like to make and I simply have to choose the resistors that give me the appropriate gain. That's not a problem. However, I also need the output impedence to be no greater than 2.5k ohm, as per the specs on my A/D. In the TI Application note I referenced earlier a mention was made of being able to achieve the desired impedence through the selection of resistor values, but they did not elaborate. For example, it said something like if you need a gain of 2 you could use resistor values of 100 ohm and 50 ohm, or you could use 500k and 250k- both would have a ratio of 2 but the impedence could be quite different.
I have done a bit of searching on this but not come up with much. Are there any formulas for the determination of impedence? Or perhaps this is something that would be detailed in the spec sheet for whatever op-amp chip I decide to go with (I have not done so yet)?
Luke
Warske
May 20, 2005, 09:19 PM
the impedence could be quite differentThe input impedance would be different, not the output impedance.
The simplifying assumptions for op-amp design are:
(1) open loop gain = infinity
(2) open loop input impedance = infinity
If (1) were true, your output impedance would be zero. This is a good approximation. In practice, your output impedance is typically in the fractions of ohms.
Actual closed loop output impedance depends on open loop output impedance, open loop gain, and closed loop gain. The effect of changing the resistors as in your example is negligible.
Warske
william541
May 21, 2005, 12:57 AM
Luke,
Warske is correct, the output impedance of most all Op-Amps is very low and will not have any trouble driving your A-D input. One thing to remember about Op-amps is most of them do not like to drive large capacitive loads. Often you will place a resistor of a 100 ohms or so in series with the output to prevent oscillations. Your A-D input should not pose this problem and you can probably do a direct connection.
As others have said, the Op-amp will not drive above or below their supply rails. In fact you have to watch out for gain compression near the rails. Ordinary op-amps can drive to within about 500 mV of the supply rail with out serious gain compression. Rail-Rail amps can get to within 50-100mV or better of the rails without gain compression. Keep this in mind when you select your A-D reference. If your Op-amp can't drive to your Vref, then the upper bits of your A-D are useless. There is not much you can do about the lower end unless you run a neg supply rail for the op-amp, or can set the A-D - ref to a neg voltage. If you are running a single supply, a rail-rail amp would be your best bet to get close to 0.
To change your ranges, you could use a programmable gain amplifier or simply use an analog switch to change the gain of an amplifier. Or easier yet, set the gain of your first amplifier to cover the highest pressure span. run this to one A-D channel and also cascade this output to another amp with more gain for your medium range and connect it to another A-D input. Then cascade it as many times until you have all your ranges covered. Your program would then look for the first A-D input that was not maxed out (ie 1024 on a 10-bit). As long as your op-amp supply voltage is not above the A-D converter supply voltage, then you should never overdrive any of the A-D inputs. Take a close look at your A-D specs and make sure they can handle up to the supply voltage on the inputs, as some picky A-Ds have lower limits that can make it a bugger to design for.
One more option would be to change your A-D ref a lower A-D ref would give you higher gain. Noise in the digital part of the system may give you some trouble when using a very low A-D ref however.
Good luck on your project! Bill
LukeZ
May 21, 2005, 03:51 PM
Warske and Bill, thanks for the input on the impedance issue. I see from my reading that as you say, according to the ideal op-amp assumptions, output impedance is zero. Since as you suggested Bill I will be using a rail-to-rail op amp, whose performance comes quite close to the ideal assumptions, then this shouldn't be a concern. The op-amp I am looking at is the TLV2472 (http://focus.ti.com/docs/prod/folders/print/tlv2472.html) from Texas Instruments.
Bill, you went ahead and started answering my final question, which is, what are the various ways I can adjust this gain programmatically from my uC? I should mention that my microcontroller is a Microchip 18F452, and presently I intend to use its onboard A/D for this circuit. It has an 8 channel, 10 bit converter, and it can handle input voltages equal to +-Vsupply so far as I can tell. Since I want to use the A/D for several other sensors as well, I probably can't go the route of cascading the op amp output to multiple A/D inputs because I only have 8 to work with. But I could go this route if I used a seperate A/D chip.
I've been looking at some digital potentiometers from Analog Devices, such as the AD5263 (http://www.analog.com/digital_potentiometers.html) that has four pots and can interface through either the SPI or I2C bus. I think I might need to adjust up to four resistors so this should work - kind of expensive though at $7 from DigiKey. It also only comes in a TSSOP package which may be beyond my soldering skills but I guess we'll find out. It looks like SparkFun has some reasonably-priced SSOP to DIP adapters.
I wonder if this is getting more complex than it really needs to be... I suppose I could get a single channel, 12 bit ADC chip - that would give me something like 10 foot resolution over the entire range of the sensor's output - no op amp needed and no extra coding to adjust the gain...
zagisrule!
May 21, 2005, 05:41 PM
It is easy to implement the voltage amplifier with a gain of 25 or so - therefore 2' increments per bit.
Problem with this is that you have a certain altitude limit before the op-amp is at it's rail and the PIC ADC is at the reference voltage.
It is possible to implement a negative DC offset though in the amplifier stage - so if you are flying from an elevation of say 1000', you can adjust DC offset so that the PIC sees 0V. Every 2 feet above that you will get another bit of resolution - to 2048 feet above your start point anyway (assuming linear sensor output).
Gain can be adjusted either by digital pots or CMOS switches and discrete resistors.
If you want to do all this though, it would indeed be easier just to go with seperate ADC - even 16 bit units are relativly cheap and will work with the PIC. That is 65536 steps rather than 12 bit 4096 steps for 16 times greater resolution and then sensing within a foot.
Probably best off with the seperate ADC... :)
-Matt
jh2rc97
May 21, 2005, 05:59 PM
Microchip has a filter design tool. It has been awhile, but I believe that it worked fairly well. For what you are doing I would set it for a low pass filter with a gain set for the scaling that you need. I will give it a run and see if it works.
jh2rc97
May 21, 2005, 06:11 PM
Well it didn't work like I remember it. Pencil and paper are the best way to work out the equations.
william541
May 22, 2005, 02:28 PM
Luke,
In looking at the pressure sensor you selected, I would be a bit cautious about trying to directly connect the output of this sensor to the input of the A-D. This sensor has a whopping 100uA of drive current, which may necessitate the use of a buffer amp between the sensor and your A-D.
One other possible solution occurred to me. If you can only use one A-D input you could use a differential amp with the pressure sensor connected to the inverting side. The non-inverting side could be connected to a low pass filtered PWM output of the micro (use another op-amp section to actively filter the PWM). This gives you a digitally adjusted DC reference voltage. The micro can adjust the PWM in known steps to always keep the differential amp within normal range. If the A-D conversion ever got to withing 100 bits or so of 0 or 1024, then it would know to switch ranges automatically.
Since your pressure sensor will have maximum output at or below sea level you can just simply range select and amplify the signal all at the same time with a differential amp. The PWM output of the micro would allow you to adjust the range anywhere you wanted it. The gain of the differential amp would be set to give you the desired feet/bit resolution and never needs changed.
To do this, the micro (PWM source) and pressure sensor power supplies need to track each other, depending on your system noise they could be the same supply decoupled with ferrite beads. In addition, your A-D ref voltage also needs to track the sensor supply voltage as your sensor output is ratiometric with its VCC. This throws another wrench in the works if you need an absolute value A-D ref for other measurements such as voltage or current. You would need to be able to select between a bandgap reference and your ratiometric reference. It's not as bad as it sounds. -Bill-
LukeZ
May 22, 2005, 03:19 PM
Well Bill I can always count on you to come up with novel solutions; whether or not I can actually implement them is another matter! ;)
But I think I understand at least the basic theory of what you're saying. It seems to have the advantage of only using a few op-amps, probably all of which could be on the same chip. I understand how I could vary the PWM signal but I'm not clear on how a PWM signal can be filtered with an op-amp to produce a steady (not pulsed), DC voltage. But basically we're creating a DAC here, right?
It looks like no matter what I do I'm going to be using an op-amp even if only to buffer the output of the signal. So that's one extra chip right there. Using the method you suggested maybe that's about all the extra hardware I would need, but the coding requirements sound like they would be greater. Alternatively it looks like I could add an external A/D chip of sufficient resolution to not require any programmable gain tricks.
I assume that when you say I would have to select between a bandgap and ratiometric reference voltage, and that it isn't as bad as it sounds, that it could simply be accomplished through a mux controlled by one of the PIC's digital out pins? I will probably need to do this regardless of which approach I take on this particular sensor. The PIC and sensor voltage supplies will be the same, and for these ratiometric types I suppose I could set the Vref the same as well. But you're right, to measure voltage, which I will want to do, I'll need a different Vref.
Luke
william541
May 22, 2005, 04:08 PM
Luke,
Using a single chip dual op-amp like the Ti part you mentioned earlier, you can make the PWM filter and the diff amp in one package. You are correct, the low pass filtered PWM does make a D-A of sorts. The reason for the Op-Amp filter is two fold; The Amp provides a high impedance to the PWM RC filter and also provides a low impedance input to the diff amp.
I think your code would not be bad at all, once you set the PWM frequency, your done with that. Then all you have to do is change the duty cycle value to change ranges. Since the PWM is done in hardware, the processor overhead is very minimal. Having the gain set so you always have the same ft/bit resolution would also make your code easier, you don't have to play games with different resolutions, they are all the same. The code just adds an offset every time a new range is selected.
for example if you choose a 2' resolution, you could easily resolve 1500' in each range. This would require 750 bits in the A-D and give you > 100 bit buffer at the top and bottom of the full A-D range. This would let the processor know when its time to switch ranges and also keeps the Op-Amp away from the rails so you don't experiance gain compression and are in the most linear range of the amplifier.
On switching between references, some micros even have an internal bandgap reference. This allows you to switch from internal to external references easily. I'm not sure if the PIC you have has this feature or not. In any event you can use a mux to switch between reference voltages.
I could draw up a simple diagram if that would be helpful for this discussion. -Bill-
LukeZ
May 22, 2005, 05:30 PM
Ok Bill, I'm going to give this a try, it sounds like a pretty decent approach, and it will give me the chance to learn something new. I see what you're saying now with the RC circuit: I figured it would take all kinds of gizmodry to change PWM to analog voltage but it looks like it will only take one resistor and one cap.
Since the A/D will be measuring a differential input but I'll really want the absolute voltage, I guess what I do is determine what voltage my specified "range" is at, probably as a function of my duty cycle, then add to that the differential voltage measured, for the total. Is that right?
Even a simple diagram probably would help a newbie like me.
I think I might go with a quad op-amp so I can put my airspeed sensor (MPX5010 (http://www.freescale.com/files/sensors/doc/data_sheet/MPX5010.pdf)) on the same board. It has basically the same voltage outputs as the altitude sensor, but I won't need any gain on it because with a 10 bit A/D I'll have more than enough resolution for its range (<300 mph). But because it has the same issue with large current as the altitude sensor, I can use one of the other op-amps to buffer the signal to the A/D. TI makes a quad version of the chip I mentioned earlier, the TLV2474 (http://focus.ti.com/docs/prod/folders/print/tlv2474.html). It's rail to rail and works for the voltage I need.
Luke
william541
May 22, 2005, 05:54 PM
Luke,
Here is a diagram of what I was thinking about. The PWM filter values are just a guess, not atual. The output will be single ended and the ft/bit will be based on your A-D ref and the gain of the diff amp.
In your code, you assign a value for your PWM to get say a 98% duty cycle or what ever the highest it will let you go. This will filter out to a DC voltage that is close to your VCC. This would be your 0 to 1500' range. In the code, you would add an offset of 0 to the value of the converted A-D altitude. As you go higher in altitude, the sensors output will go lower and you can then turn the duty cycle down to the next range. On this range, you would then use say a 1500' offset and add this to the value of the A-D altitude.
R7 is included in case you need some DC gain. At or below sea level you would need about 4.8 VDC out of your PWM filter. If you can't quite get there, then R7 can be used to provide a bit of gain to bring it up.
Hope this helps! Bill
P.S. As a foot note, I really like the dual op amps as it is easier to route and you can usually get the discrete components up close to the part. It's personal preference though, a quad would work as well.
Warske
May 22, 2005, 08:00 PM
But because it has the same issue with large current as the altitude sensor, I can use one of the other op-amps to buffer the signal to the A/D. There is no issue. You do not need an op-amp. :)
From the spec sheet you referenced: "The MPX5010/MPXV5010G series piezoresistive transducers are state-of- the-art monolithic silicon pressure sensors designed for a wide range of applications, but particularly those employing a microcontroller or microprocessor with A/D inputs."
This is true for your other pressure sensor as well. The 0.1 mA max current is from an out of date spec sheet. The newer spec sheet shows the typical application is driving an A/D directly. Max current is not the same as output impedance.
Warske
LukeZ
May 22, 2005, 08:11 PM
Ok Bill, I've been doing some pencil pushing.
It makes more sense to think of pressure ranges than altitude ranges, because that's what the sensor is measuring, and also that's the variable with a linear relationship to sensor voltage. The sensor measures 115 to 15 kPa, and I figure that 10 bits of ADC resolution per 6 kPa would be enough for my needs. At sea level 6 kPa equates to roughly 1,500 feet of altitude. At 40,000 feet 6 kPa translates to more like 6,000 feet. So my resolution will still decrease with altitude, but that's ok.
Anyway, sticking to pressure. A change of 6 kPa results in a change of about 0.25 volts on the sensor output. Therefore I take it that 0.25 volts is the difference we want to amplify in our diff op amp. At sea level say we start off at 4.8 volts from the sensor (V2) and something slightly above that from our PWM filter (V1). As we rise in altitude the pressure decreases, and sensor voltage decreases with pressure. When the sensor reading gets close to 0.25 volts below the starting voltage (to about 4.55v), we decrease the duty cycle of the PWM signal, which reduces our V1. However I won't want to decrease V1 by as much, say 0.20 volts. Otherwise I'd think the result is that I could possibly "overshoot" and V1 might become less than V2 and the subsequent reading would be of no use.
I suppose the formula in the code will be something like the following, assuming:
Vsensor – actual voltage output of the pressure sensor
Nrange – number of times I’ve dropped V1
Vrange – voltage decrease of each V1 drop
Dgain – the diff op amp gain
Vadc – voltage the AD converter reads from the diff op-amp
If so, then:
Vsensor = Vsupply – (Vrange * (Nrange – 1)) - (Vadc/Dgain)
...and from Vsensor I can calculate pressure using the relationship specified in the sensor spec sheet.
However, I’m trying to figure our whether or not this circuit might sacrifice accuracy for precision.
- In the formula above, Dgain we could know pretty well since we set it with our choice of resistors in the differential op-amp circuit.
- Nrange, the number of times we “drop V1”, we know precisely.
- The two values which are problematic are Vrange and potentially Vsupply, though if the latter is an issue it would be so no matter which approach we took.
Vrange however I don’t know about. I don’t have precision test equipment but what I guess you’d have to do is run some tests to see what effect a given change in duty cycle has on the output of V1. If we treated Vrange as a constant in the code, then a slight error in the calculation of that constant would multiply itself the higher one gained in altitude. For example, by the time you reach 15,000 feet you’ve dropped V1 about ten times. If Vrange is off even by 1/100th of a volt, multiplied by 10 that’s a 10th of a volt, and that’s nearly a 1,000 foot discrepancy in altitude.
I’d have to be able to calculate Vrange to several significant digits, and I’d have to be able to assume that it was constant over the entire duty cycle: in other words, I’d want to know that a decrease in duty cycle from 95% to 90% decreased V1 by the same amount that a decrease from 15% to 10% would- though I don’t see why this latter wouldn’t apply. However, the original calculation of the Vrange constant I see as a challenge.
Thoughts?
william541
May 22, 2005, 11:00 PM
I think I see where you are going Luke, once you have your A-D ref and gain set, the Micro will now know how much pressure is associated with each bit. When the micro changes ranges, it will know how many bits of pressure are associated with this particular range step. It then adds this to the number of bits from the A-D conversion and now knows the pressure of the sensor.
In your code, divide your A-D span up into sections. The upper and lower 50 bits are used as trigger points to switch to a new PWM range, the code never expects to see an A-D reading below 50 bits or above 974 bits in any range (except the lowest and highest ranges). When you switch ranges, the target of the new range should place the signal in the 100-924 bit area, so there is an overlap between ranges. This also creates hysterisus in the code so that the PWM is not constantly changing when a signal is near a range border.
As an example, say the A-D reading on range 1 was 974, since this is the trip point, it changes the PWM output to range 2. Range two is associated with decimal 974, which is hard coded and paired with the PWM value for this range. Now that we are in range 2, the overlap places us at decimal 100. So now (A-D reading - 100) + 974 = our current pressure. Now lets say the output of the A-D climbs some more and reaches 974 again, switch to range 3 and land at decimal 100 again. Now (A-D reading - 100) + 1848 = our current pressure. Hard code these range change pressure and PWM values, it will make your life much easier and more flexible.
Depending on the PWM frequency and the filter components, I think you will find the DC output is fairly linear with duty cycle change. Run the figures in a spreadsheet using optimal VCC etc. Then with the proto up and running, input the actual VCC into the spreadsheet and it should tell you the required V1 filter voltage for every range. Adjust the PWM value until you get this V1 voltage on a DMM then hard code the PWM compare value and its associated bits of pressure. You may have to do some number crunching to make sure your PWM has a fine enough resolution to accurately calibrate the output for each range. You may get by with an 8-bit compare value, but a 16 bit would be even better. You can also work this backwards if you have fixed (V1) steps, massage the spans for every range, each range does not have to have the same span or start and stop points. All kinds of tricks can be played to make it work with the hardware you have and still maintain accuracy. A spreadsheet is your best tool at this point.
Since the output of the sensor (V2), the filtered PWM (V1) and the A-D Vref are ratiometric with the supply. These same hard coded values should work on all boards even with VCC supply fluctuations. Did this address your concerns or am I still missing something? -Bill-
william541
May 23, 2005, 12:54 AM
To help confuse the project a bit more, I thought of one other thing that may make the altitude calculations easier. We already know there is not a linear relationship between altitude and pressure. Since you would have to do some curve fitting anyways, why not use the fact that there are several ranges and make each range bit worth a certain change in altitude. Each range would not need the same altitude scaling factor (Not to be confused with the fixed pressure scaling factor). After all a curve can be represented by a bunch of straight lines with different slopes.
if (Range = 1) then
Offset = 0 (A-D offset, where 0 starts for this range)
Base = 0 (the base altitude for this range)
Scale = 1 (feet/bit for this range)
PWM = 255 (PWM compare value for this range)
elsif (Range = 2) then
Offset = 100
Base = 974 (974 *1)
Scale = 1.25
PWM = 212
elsif (Range = 3) then
Offset = 100
Base = 2066 (874 *1.25) + 974
Scale = 1.5
PWM = 201
elsif (Range = 4) then
Offset = 100
Base = 3377 (874 *1.5) + 2066
Scale = 2
PWM = 195
elsif (Range = 5) then
Offset = 100
Base = 5125 (874 *2) + 3377
Scale = 2.5
PWM = 187
:
:
:
end if;
Altitude = Base + ((ADC - Offset)* Scale)
The numbers presented are bogus but they represent the idea. I think this is how I would approach the project. -Bill-
FenceMagnet
May 23, 2005, 07:34 AM
piecewise linear approximation.... I designed an air data computer that used an AD7712 24 bit A-D converter (actually 3 of them since we also did airspeed and one was always off-line self-calibrating) and was accurate to 10' at sea level and 500 feet at 120,000 feet (rocket powered target drone). We used an ICSensors 1220-005A, a 5 PSIA unit. Using the lower range unit gave us more signal for better noise immunity, and the increased non-linearity was of no concern since we used curve-fitting anyway... surprisingly accurate (repeatable) for a $15 part.... of course, we characterised each one over temp and pressure....
:cool:
LukeZ
May 25, 2005, 02:26 PM
Well, I have some parts on order: in addition to the rail-to-rail op-amp, I have a couple A/D chips with 12 bit or higher resolution. So either way I should be set. I'll post back when I have some progress. In fact, I may do a seperate build thread.
Luke
LukeZ
Sep 22, 2005, 12:20 AM
Well, it's been a while but I thought I'd revise this thread with a question, and it has to do with Op-Amps what's more, which is good since that's the title of the thread.
In the intervening months since my last post I've worked up a simple altimeter circuit using the Freescale MPX4115A pressure sensor and a Linear Technology 12 bit A/D. It works fine and has been tested down to the lower limit of the pressure sensor, which is about 15 kPa. Resolution is about 7 feet at sea level and increases with altitude since I've done no curve-fitting as of yet. I whipped up a PCB with the sensor (also an airspeed sensor) that has an SPI interface to my PIC - you can see the details of this circuit as well as a tutorial I wrote on altitude measurements at my website, www.kansasflyer.org (http://www.kansasflyer.org/index.asp?nav=Avi&sec=Alti&tab=Intro).
However, I am now going to re-design the circuit for higher precision, using Bill's excellent suggestion, which quite elegantly allows for curve fitting built in with the voltage ranges I'd have to do anyways. I really want higher precision without sacrificing altitude range - the goal is to still be able to measure pressures down to 15 kPa, while at the same time maintaining a resolution nearer to 1 or 2 feet, at least for altitudes up to about 15,000 feet. This latter is so I can use my device for a fairly steady altitude hold as opposed to simply an altitude measurer; otherwise I should be quite content with my current resolution. Finally I also want to stick with my 12 bit A/D. There you have it for the criteria...
I do not have a whole lot of experience with differential op-amps, but I understand that they take some smaller voltage difference and amplify it such that it scales to a wider range given by the gain (in my case I will want it to scale to 0-5 volts). The difference will be controlled by the PWM output of the PIC in conjuction with the sensor output. Now here is my question: is there any non-linearity involved with the absolute scale of this voltage difference?
For example, say the diff-amp is set to read up to a maximum of 1 voltage difference between V1 and V2. No difference will equal Vout of 0, 1 voltage difference will equal Vout of 5 volts, that is the gain. Now, does the diff-amp care if that 1 volt is the difference between 2 and 3 volts, as opposed to the difference between 4 and 5 volts? More precisely I suppose, does this scale at all affect the gain of the op-amp?
I suppose if so this too could be compensated for by curve-fitting... but I am curious.
Luke
FenceMagnet
Sep 22, 2005, 09:26 AM
non-linear? no.... BUT, you have to be careful to keep the input signal within the common-mode range of the op-amps which is determined by the op-amp's design and the power supply voltage. Operating on the rails in a diff-amp is not a good idea...
:cool:
vintage1
Sep 22, 2005, 06:33 PM
non-linear? no.... BUT, you have to be careful to keep the input signal within the common-mode range of the op-amps which is determined by the op-amp's design and the power supply voltage. Operating on the rails in a diff-amp is not a good idea...
:cool:
Some of the FET input ones and one or two bipolars can operate to ONE of the rails...see common mode range voltages on the spec sheets to make sure what can and can't be done in this area...
...I've done a fair amount of non-linear op amp design using various techniques to approximate curves...its non trivial to get it all temperature stable and repeatable and accurate. But it CAN be done..
LukeZ
Sep 25, 2005, 04:10 PM
FenceMagnet, thanks for the tip. According to my spec sheet the common mode voltage range for my op-amp is 0 to Vdd (it's a rail-to-rail amp). I can scale my output to range from 0.2 to 4.8 volts or something similar to keep it away from the rails though, that's a good idea.
Now here is another question, to do with my PWM output - are there any guidelines to think of when selecting the PWM frequency? I think I understand PWM in theory but have no experience with it in practice.
In my PIC the duty cycle is set with a 10 bit number, so theoretically I have 1096 steps to play with. However, the actual resolution of the PWM waveform is determined by the PWM frequency I select, or so I understand from the datasheet.
I'm not sure how much resolution of the PWM waveform I'll need or even how to determine how much I'll need.
According to the PIC datasheet, it appears that PWM waveform resolution is inversely related to PWM frequency - a lower frequency results in a higher resolution. I'd think I'd want the highest resolution possible, and also that lower PWM frequencies couldn't be a bad thing either - less noise in the system perhaps? But I'm just shooting in the dark here to be honest...
Luke
william541
Sep 25, 2005, 08:31 PM
LukeZ,
Congrats on getting your hardware up and running!
As far as your PWM is concerned. Since you are probably going to filter the PWM output to a DC level, go with as high a frequency as you can and still maintain your 1023 steps of resolution. This will make it much easier to filter to DC. Since we are talking very low current drive required from the PWM, noise should not be an issue for you.
When using the diff amp pictured above, your CMRR will be mainly effected by the resistor matching. Use 1% resistors. I have found better performance by making the input impedance as high as possible. An easy way to do this is by making two of the resistors in the circuit 1 Meg ohm and then calculate the other R value to give you the desired gain. With the diff amp pictured above, you can have the inputs above or below your supply rail due to the divider networks on the inverting and non-inverting inputs of the amp (within limits of course).
If you find yourself fighting CMRR problems (like dealing with high common mode voltage and high gain requirements), then you can go with an instrumentation amplifier which already has laser trimmed resistors inside and offers high CMRR. I don't think your circuit will be dealing with a very high gain, but testing will tell if you may need to go this route.
The rail limits you mentioned earlier (.2 to 4.8) should work well with any rail-rail op-amp without worrying about gain compression. What I would watch out for is the PWM from your micro will be supply sensitive. I.e. if the supply voltage to your micro varies, so too will the filtered PWM DC value. One way to get around this is to make the pressure sensor, micro and A-D reference ratiometric (i.e run from the same main DC supply). This way when the supply varies for what ever reason, everybody moves together and your A-D values will be virtually unchanged. To do it this way, the sensor needs to have an output that is ratiometric to its supply (most analog sensors are like this).
If you don't have the option of making everything ratiometric, then there are a few options you can use to regulate the PWM peaks so that the resultant DC output is "supply independant". But now you need to tightly regulate your sensor and A-D reference or you will have trouble with drift.
It's great to read your progress, keep up the good work! -Bill-
Edit: I just had to add some comments on your web site.... Great job on the altitude theory and equasions, that should help a lot of folks out and is a good read. You must be a pro at web design, good looking and well laid out. I just had to book mark it for future reference!
LukeZ
Sep 26, 2005, 12:00 AM
Bill, thanks for the encouragement - and I'm glad you posted. Getting as far as I have has been in good part due to your help and advice.
The highest frequency PWM I can achieve while retaining 10 bits of resolution is 19.5 kHz. My PIC is running at 20 MHz for what it's worth - I don't know if I should be looking out for harmonics or anything. For comparison dropping down to 9 bits brings the frequency up to 39 kHz - of course the resolution doesn't have to be an even integer, I can set it anywhere inbetween as well.
That makes good sense about using the 1M ohm resistors for high impedance. You're right, I don't need much gain - from my calculations a gain of 10 or 11 will fit my requirements. Also, from what I understand of common mode voltage I don't think I will be having a very high one, though perhaps relative to input voltage it could be. For example, my input voltage at sea level will be something like 4.5 volts: this then will essentially be my common mode voltage between V1 and V2. Although it's only a few volts, relative to my input range (each step I figure will be about 0.4 volts) it is ten times the amount. So whether that would be considered high common mode voltage or not I don't know - it seemed to me high CMV was more like on the order of thousands of times greater... Am I off the mark here?
In fact I would be happy to use an instrumentation amplifier as they are inexpensive enough and the gain is easy to set without matching resistors - however, the ones I've looked at typically accept input voltages down to the lower rail but not very close to Vss, as Vintage pointed out. The ones I've seen want to keep input voltage up to 1.5 volts away from Vss. That won't work well with the sensor I have, which goes quite close to Vss at sea level, and I suppose it would require me to use yet another op-amp to level shift the signal before it goes into the instrumentation amp. At that point I've negated any simplicity acquired from using the instrumentation amp... So, unless I find a better instrumentation amp, or unless it really does look like my common mode voltage is too high, then I'll try to make do with the simpler circuit you posted.
Bill, I will indeed be using a common supply for the sensor, op-amps, and the PIC. And in fact my sensor output is ratiometric with supply voltage, so that should not be an issue.
In an earlier post you mentioned that the resistor and capacitor values for the PWM-to-analog voltage circuit you posted were not exact, just guesses - how critical are those do you think? I'm going to do some playing around but my testing equipment is not all that precise and I may not really be able to tell much difference between "better" and "best".
I'm getting ready to place yet another order from DigiKey... I always put it off as long as I can because no sooner do I click the submit button do I remember I need another 5 cent resistor. I'm trying to get all the likely components for this circuit together so I don't have to order a second time. I guess I should get one of those "assortment packs" of resistors so I'll have every value I need. They just seem so expensive, especially at the 1% level...
Luke
william541
Sep 27, 2005, 01:08 AM
Hi Luke,
With a low gain of 10-11, I don’t think you will have much problem with common mode errors. If your gain was up around 100 or better, then I think you would start to see the effects even with a common mode range of 0-5VDC. If you find you need to use an instrumentation/ difference amplifier, have a look at the Ti/Burr-Brown INA132 for single supply operation. This amplifier running off of a 5V supply has a common mode input range of 0 to 8V. Personally, I would build the prototype without the instrumentation amp and then determine if you really need one after proofing the design out.
Running the PWM at about 20 KHz, I think a good start point would be R5, R6, R8 value of 100K; C4 of 0.47uF; C5 of .001- .01uF, R7 not placed. The lower you run the PWM, the slower the settling time of your filter due to the changes in your RC time constants. With the values above, you should be able to start conversions within about 250 mS after changing the PWM value. Depends on how big a step your duty cycle takes between ranges.
Just out of curiosity, how many bits of noise are you seeing with your 12-bit A-D? If your V-ref is 5V, that puts you around 1.2mV/bit which takes a pretty quiet system to make use of.
I know what you mean about ordering from Digikey, the $25 minimum can get you some times. Mouser is a good place to order with no minimums. But one thing about Digikey is that they carry just about everything!
Looking forward to your progress updates, keep up the good work!
-Bill-
LukeZ
Sep 27, 2005, 11:04 PM
Alrighty then, I think I'm at the stage now where I just need to start doing and quit worrying! ;) I'm waiting for a breadboard I ordered to arrive before I start playing with this circuit... should be here tomorrow. I have several boards already but they're full of other stuff and I don't want to take them apart.
If you don't mind Bill, how might I find out about the sorts of calculations that you used to derive the resistor and capacitor values? I understand perhaps some of it for you is just head knowledge at this point, if you've done this for a long time. I tried coming up with an estimate close to the 250 ms settling time for the RC circuit that you gave, but couldn't figure out how to do it. I've been looking at AllAboutCircuits for some formulas on this stuff, this page (http://www.allaboutcircuits.com/vol_1/chpt_16/4.html) has some info on RC circuits - but not that I was able to logically tie to what we're doing here.
One of the frustrating things about being self taught, it seems to me, is that I've missed a lot of probably elementary pieces of knowledge which would have been covered in a more formal setting. I wish I knew all the formulas and tricks so I could derive my own circuits from the knowledge in my head - but thus far at least it requires more of a grand research project at every little step of the way... At any rate it's been interesting.
Bits of noise? I'm not sure how I'd even go about noticing. :o I do know that I've filtered the sensor in hardware as per an application note (http://www.freescale.com/files/sensors/doc/app_note/AN1646.pdf) that Freescale put out. I also do software filtering through the use of a running average of I think about 20 samples. Having taken those precautions, the app note indicates I should have noise output of less than 1mv. Of course that's close to 1 bit of resolution. In fact I'd say about 1 bit of noise is probably what I've seen - pressure readings typically fluctuate 1 bit above or below the initial reading when I turn the sensor on. I can't tell if this is fluctuation in the actual air pressure but probably more than likely it's the effect of noise.
Luke
MatC
Sep 28, 2005, 12:24 AM
Luke: great work so far :)
As regards non-linearities in the opamps, it's generally not a concern for low gains. As you know (but someone might not, so will repeat for clarity) opamps work by taking the difference of their input, and then multiplying by a big number (around 10 million for basic opamps working at audio frequencies or below).
This means that there can't be much non-linearity at all: if the feedback loop is linear then any non-linearity from the opamp would show up as a difference at the inputs and be corrected for (I guess to roughly within 1 part in a few million at DC).
I'd suggest putting the feedback resistors onto the negative input to avoid any extra loading on the pressure sensor. Big values are good because they limit opamp input stage heating (probably not a problem for your application). Small values are good because they limit noise. I'd think something of order 10k would be a good compromise. Some more low-pass filtering on the opamp output may help to keep opamp noise down.
All good news so far... the bad news is input offset. This presents itself as a voltage offset at one of the opamp inputs. It's temperature dependent, time dependent, part dependent, and far worse on the lovely fet-input opamps that look so good in theory. Check the data sheets :)
Easy enough to correct this however... in software, or as an opamp adjust. Just don't forget about it :) If you're calibrating at ground level you're probably fine, but it might just affect your calculations in a non-linear way with height.
And on the subject of calibrations... I'd think it easiest to measure the temp with a sensor, and do all calibrations in software where you can easily tweak it in a way that won't have side effects. Is your power supply voltage level very well calibrated/regulated?
Good luck!
MatC
Sep 28, 2005, 12:33 AM
<edit: removed because it's a repeat of the above>
william541
Sep 28, 2005, 01:28 AM
Hi Luke,
Well join the club... I'm self-taught as well although I did have some formal training in the service some 18 years ago. In the case of this filter, you are basically taking the 20KHz squared waveform and low pass filtering it down to a DC level where the ripple is about 5mV or less. To be honest, I didn't run any calculations on the filter section but rather bread boarded the first RC section and looked at the response time and ripple on the scope. Empirical results if you will... It is going to be a balance of how clean do you want the DC level and how fast do you want the DC level to change to a new value. Without knowing the timing and ripple requirements for the project, you have to start somewhere. I'll do some digging around this weekend and see if I can come up with some calculations that may be of some help on this part of the circuit. Then too maybe someone else on the forum will step in with a calc or two.
I don't think there is an engineer or hardware designer out there that does not go through the research phase when tackling a new circuit design that he/she has not done for a while if at all. So don't feel frustrated, you are in good company!
I have always like the saying "The more you know, the more you know you don't know!" So does this mean we are all getting dumber? -Bill-
LukeZ
Sep 28, 2005, 01:29 AM
MatC: Yes, I'll be putting the feedback resistor on the inverting input of the op-amp, as per Bill's schematic. In an earlier post he mentioned he sometimes had better performance by making the input impedance into the gain amp as high as possible, and did so using 1 Megohm resistors - quite a bit higher than your suggested 10k. However, I've ordered four sets of 1% resistors that will give me the gain I need at 1M, 100k, 10k and another at about 8k. So I can experiment and see which scale works best. I also ordered a bunch of high resolution trim pots to adjust.
Your explanation of the linearity issue makes good sense.
About calibration, I think this is what Vintage was getting at in his earlier post. This seems like a nightmare! :(
In my reading I came across a discussion once of what I think you mean by input offset - they said that if you tied the inverting and non-inverting inputs of an op-amp both to ground, so that the difference between them was theoretically nill, then any output that showed up from the op-amp was its input 'error' or input offset as you say. Am I getting this right? It would seem easy to compensate for this in hardware, but not if as you say it is temperature and time (?) dependent, or otherwise regularly variable. In that case then I'd have to use software.
All the same, although my strong point is programming (I do it for a living) and my weaker point is the hardware, I still prefer to fix things in hardware where possible. Just to make the programming job easier, I guess.
I suppose I'll worry about the calibration when I even get this thing working. I will in fact have a temperature sensor nearby so software calibration by temp would be feasible.
As for my power supply, for now it's just my prototyping supply (converted PC power supply). I have it filtered all over my proto board and a PC supply is probably pretty clean anyhows. For my final application the power supply design has yet to be chosen - though I suspect since extra heat will be nothing but a benefit, that I'll end up using a simple 7805 circuit. I'll also need to add a precision voltage reference at some point for my voltage measurements, but I don't foresee the supply being precision.
Luke
MatC
Sep 28, 2005, 12:41 PM
william: a good start for RC filtering is the time constant : Tau=RC. This is the time it takes the capacitor to charge to 66%. Just multiply the R and C values (in ohms and farads respectively) to get the time in seconds. It's a good place to start (forgive me if you know this already).
Luke: not quite. The voltage offise shows up as a voltage difference at the input, like a battery in series with one of the inputs. If you connect both inputs together the output will just saturate to one rail.
Ideal opamp: Output = (PosInput - NegInput + InputError) * Gain.
Input error is generally small, but Gain is roughly 10^7, causing the output to saturate. Check the specs of the opamp in question. Don't worry overly about the time dependent factor, it won't change much over time. Temperature on the other hand is a worry, but easy enough to test: put the whole thing in the fridge and see how much it changes :)
To give you some idea, input offset can be as bad as 0.1v for very bad fet opamps, but is normally a _lot_ smaller for decent non-fet opamps.
PC Power supply is probably pretty good, but remember it's meant for digital electronics and it's a switching PSU, so might be a bit noisy. Measure, test, and if it's bad just put a resistor in series with the power supply... or better: use the 7805 from the 12v rail.
william541
Sep 28, 2005, 03:24 PM
Luke,
If you are looking for a possible power supply solution, National's Simple Switchers work very well. I have used an LM2675M in 5 different products which are mixed signal designs. Out of 12,000+ units shipped, we have never had a problem with these supplys and the efficiency is better than 80%.
LM2675M 260KHz switcher, 1A output, 8-40VDC input, SO-8 package
LM2676S 260KHz switcher, 3A output, 8-40VDC input, TO263 package
Use Nationals webBench power design features, makes it very painless. One suggestion though, only use torroid type inductors or shielded potcore inductors for the switching supply. This will keep the EMI and RFI to a minimum. Coiltronics, , Coilcraft, JW Miller, TDK, Panasonic, API Delevan and Pulse are good sources for the inductor required.
I'm sure you already know this, but when using a single supply for both the analog and digital circuits, decouple the analog circuits with an inductor or ferrite bead and install a large filter capacitor on the output side of the inductor/bead feeding the analog circuits.
Another thing to keep in mind when you layout the board is to watch the ground current paths and keep the analog and digital paths separated. An easy way to do this is to place the single power supply in the center of the board on one edge. Then place all the digital stuff on one end (with the main oscillator on the outside edge of the board) and the analog stuff on the other end of the board. The mixed signal components go in the middle with analog and digital signals facing their respective sides of the board.
Just a suggestion, sounds like you have things well in hand... -Bill-
vintage1
Sep 28, 2005, 03:50 PM
dont worry about calibration and offset compensation.
Most opamps are fairly good over quoted temp range and the overall feedback stabilises them even more.
To adjust input offset just stick a pot between inpouts - large value - and run the slider to rail or 0v via a resistor. That allows you to trim out any variations in the final circuit. Some opamps have a pair of pins to connect a suitable pot too, as well.
Gain is easy - another pot in the feedback circuitry to trim out minor resistor valeu variations.
The art of getting rid of HF noise is easy enough - opamps make great active filters. Sadly I sold my 'active filter cookbook' book, but there should be net resources to allow you to construct just aboout any frequency curve you want... fancy a 6th order Bessel ? :D
The biggest problem is to get what is essentially a very linear set of components to behave non linearly.
The only non linear components we have to do this with are semiconductiors, and they are vile in terms of tolerance and temperature variation.
If at all possible use high res ADC and do the non linear bit in software.
Others have mentioned issues of ground planes, digital noise decoupling etc.
I think there is adequate expertise to review any PCB designs and debug them if you post here.
Good luck.
willfly
Sep 29, 2005, 04:08 PM
OK, another contribution from me based on partial reading. This seems very similar to what I am trying to do with a altitude telemetery except for higher range. I used MPX5010 DP sensors (target range 1500 AGL), blocking the high port on take off. Programmable gain Instrumentation amplifiers do the job well. I am using LT1167, in which the gain is set by a single R, will switch over to digital gain select device later on. PIC uC can have a maximum full scale span of 2V. So far the altitude measurements are working fine, just not getting RF link right.
Clarifying your first post, the PIC uC cannot have a span less then 2V. At the end of datasheet in electrical char: Vref- (max) = Vref+ - 2V. This means you can setup ADC in PIC to read 0 at 1V, and 1023 at 3V.
MatC
Sep 29, 2005, 04:14 PM
> To adjust input offset just stick a pot between inpouts - large value - and run the slider to rail or 0v via a resistor. That allows you to trim out any variations in the final circuit.
I agree with most of your post, but not sure this bit is exactly right. Input offset manifests as a roughly constant voltage applied to one input, the circuit above will load up both inputs with additional resistance (different on each side), and only give the correct balance for one input voltage. If your circuit needs this level of correction, it might be best to choose an opamp with the additional correction pins (or correct the offset in software, which I know Luke is loathe to do :D).
LukeZ
Sep 29, 2005, 04:56 PM
Input error is generally small, but Gain is roughly 10^7, causing the output to saturate. Check the specs of the opamp in question...
To give you some idea, input offset can be as bad as 0.1v for very bad fet opamps, but is normally a _lot_ smaller for decent non-fet opamps.The op-amp I'm playing with now, the TLV2472 from TI, indicates a input offset voltage of 250 microvolts typical (.000250 volts). I might be getting this wrong, but at a gain of 10, say, the error would still be only .001 volts on the output (does it work that way?), which for my 12 bit ADC, would equal right about 1 bit of error. This doesn't sound too horrendous...
If you are looking for a possible power supply solution, National's Simple Switchers work very well.Bill, those are some good suggestions on power supplies. I'll check those out. There will be quite a few other components in the final UAV that I still haven't even worked out yet, so it's hard to know what my power needs will be. As far as any boards I make, I'll definitely take Vintage's suggestion and post them here for comment before I have them run off. I can already tell that the design for my first altimeter board that is posted on my website could have been laid out much better.
To adjust input offset just stick a pot between inpouts - large value - and run the slider to rail or 0v via a resistor. That allows you to trim out any variations in the final circuit. Some opamps have a pair of pins to connect a suitable pot too, as well.I agree with most of your post, but not sure this bit is exactly right.Hmm... not sure there's a consensus on input offset voltage correction yet! :rolleyes:
I am using LT1167, in which the gain is set by a single R, will switch over to digital gain select device later on.Willfly, I checked out that chip and it looks good - except that again the input voltage range is rather restrictive: -Vs + 1.9 to +Vs -1.2. With a single source supply of 5 volts that leaves less than 2 volts to work with! Again maybe I'm missing something here, but my sensor output is going to range from close to ground to quite close to the upper rail. Even though the input voltage "difference" will never exceed a small range because of the "following" PWM output, still the whole scale of input into the op-amp is at some point or another going to approach the rails much closer than that allowance lets me. So it seems that to use this device I'd need to do some level shifting of my sensor output, which right there adds another component. But let me know if I'm not understanding this input voltage range issue correctly...
I'd certainly be interested in any more details of your design you want to share...
Clarifying your first post, the PIC uC cannot have a span less then 2V. At the end of datasheet in electrical char: Vref- (max) = Vref+ - 2V. This means you can setup ADC in PIC to read 0 at 1V, and 1023 at 3V.Yes, that may be - but I'm using an external ADC so my PIC's AD won't come into play (I'm using the LTC1291 (http://www.linear.com/pc/downloadDocument.do?navId=H0,C1,C1155,C1001,C1158, P1446,D1075)). But even if it did, although my differential voltage range will be something on the order of about 0.4 volts, the op-amp is going to scale this to 0-5 volts, which is what the ADC will see. Probably I didn't understand what you're trying to tell me. :o
Well, I hope to have some time this weekend to do some prototyping. Hopefully I'll have some actual results to post soon...
Luke
MatC
Sep 29, 2005, 05:14 PM
> I might be getting this wrong, but at a gain of 10, say, the error would still be only .001 volts on the output (does it work that way?)
Yes, except 0.000250 * 10 = 0.0025v. Easily corrected in software :D
LukeZ
Sep 29, 2005, 05:47 PM
Oops, yes, you're right. Maybe Bill's right, the more I know the dumber I get. ;)
Course, that's only the typical amount. Seems like it will vary considerably over my range of common mode voltages...
vintage1
Sep 30, 2005, 03:31 AM
Oops, yes, you're right. Maybe Bill's right, the more I know the dumber I get. ;)
Course, that's only the typical amount. Seems like it will vary considerably over my range of common mode voltages...
The answer is not to use the chip in a mode where the common mode range is needed.
IF you design with input resistors between signal source and - say - negative input, and hold the positive at a fixed level (see saw) you will get far far better accuracy, the only dowsnide is that the noise figure goes up.
However when designing this way for audio inputs, I got only about 6-8dB worse figures than the non-inverting approach. And it completely avoids having to use large common mode signals. Essnetially you are using te chip as a current amplifier, and its also easier to trim offsets out.
Since response time is not required to be huge, you can roll the noise out with a low pass filter.
If you are aiming for microvolt sensitivity, watch out for LF noise though - flicker noise in bipolar chips is an issue. I think FET input stuff is OK though - its been too long...
william541
Oct 01, 2005, 12:10 AM
I spent a bit of time and built up a couple different PWM filters and tested them. I tried the one we had been discussing and though it did work, I made it simpler and used common inexpensive 0.1uF bypass capacitors in the final design. I also tried a traditional Sallen-Key filter, which had much faster settling time but is plagued with ringing issues during the fast PWM transitions. A second filter section would be required to kill the ring frequency.
The final circuit is easy to build and seems to perform fairly well. (pictured below). I ran the 20 KHz PWM from 6% to 92% duty cycle and plotted the voltage output of the filter (see graph). It is very linear with a sharp knee above 91% duty cycle. The op-Amp used was a TLC2274 rail-rail unit that was hanging around the bench. Based on the measurements of this op-amp, it looks as if it would be best to stop at about 4.5V for the top end.
The filter recovery time is also shown below. The upper trace triggers the PWM between 0% and 50% duty cycle (0 to 2.5 volts out). The filter settles out in about 250mS. Smaller PWM changes would settle out more quickly.
The last picture shows the spectral response of the LP filter. The filter was swept from 100 Hz up to 30 KHz. Everything above 3.5KHz is down 50db or more and provides pretty clean DC when run with the 20KHz PWM.
-Bill-
LukeZ
Oct 01, 2005, 09:02 PM
Well, I've been fiddling with the PWM to DC out and my results are quite close to yours, Bill. I have 10 bits of resolution on the PWM duty cycle and I measured voltage out for individual bits between 0-25 and 1000-1023, to get an idea of performance close to the rails. The rest of the range I measured in 20 bit increments.
For this experiment I used a TLV2471 rail-to-rail op-amp, and indeed it is quite nearly rail to rail. It begins to saturate at around 93% duty cycle, with full saturation by about 97%.
One thing I can see already is that I am going to need a more accurate DMM - the one I have only cost me 5 bucks at Harbor Freight and it doesn't have nearly the resolution I'm going to need. Except for very small voltages I have to use the 20 volt setting on the meter, and that means I can only read down to 1/hundredth of a volt, whereas I'd like another significant digit or two. Not to mention I have no idea how accurate my meter is.
I've been thinking I need to get a scope, too. Only I don't hardly know a thing about them. Can they be used as a high-accuracy voltmeter as well?
I've been thinking that since my DC circuit won't be able to output voltages close to the positive rail, it might make sense for the PWM/DC out to be lower than the sensor output - in a sense it would lead the sensor voltage rather than follow it, as altitude increases. This would work even for very high altitudes because my sensor bottoms out at 0.2 volts, whereas my PWM circuit can still go below that without saturating. Not to mention that I'm hardly ever likely to fly at 45,000 feet, but will quite frequently fly close to sea level, where the sensor voltage will be close to Vsupply.
The question then is, do I need to switch the inputs on my diff-amp? In your schematic earlier, Bill, the sensor goes into the inverting input and the PWM-DC out goes into the non-inverting. Will this still work even if the inverting input is always higher than the non?
Luke
Pic:
william541
Oct 01, 2005, 10:14 PM
Luke you certainly can swap the inputs if you want the sensor voltage to lead the PWM DC reference. Since the op-amp is running from a single ground referenced supply, you would want to keep the Op-Amps + input always more positive than the - input.
A simple way to look at any op amp is that the output will always drive to a level that forces the - input to exactly match the + input using the negative feedback path.
On your test equipment, get the best DMM you can afford. Personally I recommend a FLUKE meter. The model I use at home is a hand-held model 187 (about $400). There is a wide range to choose from, but just get the best quality one you can afford. O-scopes are indispensable at the bench as well. A very nice one can set you back $2,500 to $3,000. Here too, go with a quality brand like Tektronix and you won't regret it. I would suggest getting one with a bandwidth of >= 100 MHz, with 200 MHz being preferable. The wave captures above are from a Tektronix TDS2024. I wish I had this unit at home... but at least I have access to it at work. At home I use an older model 455 and it is starting to show its age with triggering problems.
To answer your question, yes, some o-scopes can measure DC voltages very accurately. However I cannot tell you how many times I use both the scope and DMM at the same time, so I would suggest separate instruments with the DMM coming first. FLUKE does make some nice scope-meters though. One of these may suite your needs as well.
Your PWM plot rolls off at the top like I expected mine to, I did not have time to look into why it shot up like it did. Maybe it was operator error on the pulse generator, wonder who could have done that?
-Bill-
LukeZ
Oct 05, 2005, 12:27 AM
I checked out the specs on some FLUKE meters and the 187 looks like just the thing I need. They're selling on eBay for around $250... geez. That's still a lot of dough. Guess I'd have to put off that brushless I've been wanting. Hmm...
Have you or anyone else had any experience with these scopes that you run on your PC, either through an ISA card or an external device plugged into the serial/USB port? I saw one (http://www.parallax.com/detail.asp?product_id=28014) on the Parallax website once. From what I can tell I guess they're kind of poor-man's versions. Bandwidth on the Parallax o-scope is only 200kHz.
Well, I have a question about interfacing my sensor with the diff-amp. As I mentioned before Freescale has an application note dedicated to noise filtering (http://www.kansasflyer.org/Documents/FreescaleNoiseFiltering.pdf) of their pressure sensors. I've pasted a picture from the document below. Basically they recommend a low-pass hardware filter on the sensor output. In their diagram then the output goes directly into the A/D, which is how I've done it with Version 1 of this project.
Now things will be different though, and I'm not sure how to implement this. Won't the 750 ohm resistor affect my gain equation? I suppose I could just add an extra 750 ohm resistor inline with my PWM out as well, if that were the case: basically build that resistor into my gain setup. Or, should this low-pass filter go on the output of the diff-amp instead? Even if it doesn't, would a filter on the diff-amp output still be a good idea? Hmm, I guess that's a question a nice o-scope would help me determine, huh?
Slowly but surely...
Luke
Pic:
LukeZ
Oct 05, 2005, 12:31 AM
By the way Bill, what program are you using to generate your schematic images? I use Eagle for design and I like it, but their schematics always look so cluttered. It would be nice to have something simple for purposes of posting here on the forums like you've done...
Luke
william541
Oct 05, 2005, 01:37 AM
Luke on your filter, the diff amp will take care of the lowpass response. The capacitor in the op-amp feed back is what controls this filtering. You can go directly from your pressure sensor to the input resistor of the diffamp. You are correct, any extra resistance between the sensor and the op-amp will change the gain and balance. If you need even more filtering, place a capacitor right at the + input to ground if you are still going to plumb your sensor into the + input of the op amp. If you go with high resistances in the diffamp (say 1Meg & 100K), the capacitance needed will be very small, probably in the pF range. Try 33pF to 47pF to begin with.
That is a good price for a 187, is it new in the box? These meters take 4 AA batteries, so they have a pretty good battery life.
Well, some of the data acquisition cards don't do too bad a job, but you are not going to see a heck of a lot with a 200 KHz bandwidth...
I use Orcad capture and layout programs, sadly they are not free to say the least... Eagle is not bad and you sure can't beat the price. If you can read the schematic, you are in good shape. When you get into larger schematics that take up 5 or more B size sheets, then it might be time to look at other software.
Take care, Bill
P.S. If you find you want to keep the simple RC filter on the output of the pressure sensor, you can use another diff amp design using two op-amps and it presents a very high impedance to each of the inputs. I use this type design when the gains are 100 or more and I need to apply an offset voltage to boot.
LukeZ
Oct 06, 2005, 12:47 AM
Bill, the auctions I saw on eBay were indeed for new-in-the-box meters. Of course who knows if they're lying or not.
I'll go with the setup I have now, and add the capacitor as you suggested. Currently I'm using 1 M / 90.9k resistors for a gain of about 11. They're 1 percent but I also have some trimpots I might break out if I need to. Again I'll be coming up against the limitations of my meter: no doubt I can trim them all I want but my meter has such low resolution I wouldn't probably know if I was getting any closer or worse.
So we'll see how this goes - if noise is an issue I might look into the other op-amp design. I think I know what you're talking about - I've seen some schematics on the web.
More to come when I get more time...
Luke
LukeZ
Oct 09, 2005, 04:17 PM
Ok, have had some time to play with this the last few days. It sure is amazing when all this gadgetry works!
I've been thinking about the comments on piecewise linear approximation as well as what you suggested earlier, Bill, about using the different "ranges" to my advantage by specifiying a certain foot per bit for each range. After having pondered this a while I think it won't entirely be necessary for my approach, and would maybe even be more complexity and less precision.
It seems to me that I don't need to do linear piecewise approximation because I am using an unabridged version of the standard atmosphere formula to calculate altitude from pressure. All the calculations are done entirely in floating point math, no corners have been cut there. Yes, this is more processor-intensive but that's what they're good at. Besides, I have all this already working just fine - so really I think I will leave it entirely independent of my efforts here. (Edit: the formula I will be using, at least in the troposphere, is Equation 3 on this page (http://www.kansasflyer.org/index.asp?nav=Avi&sec=Alti&tab=Theory&pg=4))
All I'm really trying to do is calculate Pressure with more precision than before - more specifically, I'm trying to calculate the sensor's voltage output with more precision.
If I know exactly what voltage my PWM outputs for a given duty cycle, this is easy. The PWM voltage is always going to be slightly less than the sensor voltage. The difference between the two is what I'm measuring with greater precision due to my diff-amp. Total sensor voltage is then this small difference, plus the PWM voltage:
Vsensor = Vpwm + (Vdiff / Gain)
Vpwm will vary with whatever range I'm in. I'll know what it is because I can measure it for each range and then hardcode that voltage in.
Once I have my Vsensor then I just plug it into my existing formulas, no change needed there.
Does anyone see a problem with this approach?
Luke
LukeZ
Oct 12, 2005, 01:42 AM
Well I've gotten this thing to "work" but now I foresee a lot of tweaking to make it useful. My code can successfully determine what level the PWM DC needs to be at for a given sensor voltage, and as that sensor voltage changes, the PIC changes the PWM DC from one range to another just the way it's supposed to. It all works - but it's nowhere near being functional.
For one, it's so sensitive that it won't settle - no doubt I have noise in my system. I've used a lot of decoupling caps and a bead between the digital and analog Vss, but the whole thing is on a breadboard so I'm sure it's less than ideal. Breadboard or no, I'm probably going to need to provide additional filtering to the diff-amp output, or maybe even filter the sensor and PWM outputs before they even go into the diff-amp. This latter I assume would require two more op-amps, one each for the sensor and PWM:
sensor -> filter -> op-amp1 -> diff-amp
PWM -> filter -> op-amp2 -> diff-amp
I assume this because as mentioned before, if I add a filter between the sensor/PWM and the diff-amp, it will affect my gain equation.
Here's a question though, and I think MatC was kind of getting to this earlier but I probably didn't fully understand. How do I accurately determine my gain? I can measure my resistors and get them matched up and do the gain formula, but what's my real gain? I mean the gain after I account for any input offset voltage of the diff-amp? Do we just measure the voltage going in, and the voltage going out, and divide to get actual gain? (If so, I'm definitely going to need a more accurate DMM...)
Progress is being made, but I feel like I'm entering the territory of subtelty, fine detail, and tweaking, and getting farther away from my area of expertise... :rolleyes: But I'm happy I've even made it this far!!
Luke
MatC
Oct 12, 2005, 02:00 AM
Indeed, good work on getting this far :)
Calculating your gain: I can't remember the exact formula, but at low frequencies the effects that dominate will be resistor matching and input offset. You'll have to measure both I'm afraid, although the latter should be well specified in the opamp blurb. If it was me I'd be trying to get a prototype finished before working on such tweaks :)
You really need some way to measure and quantify things I'd guess, and finding super-accurate DVM's won't be cheap. Why not do comparitive tests using a PWM? With care a PWM should be incredibly accurate, and you can just use a sensitive current meter and resistor to compare/measure voltages. The only precision component needed would be a crystal for the PWM (or microcontroller), which you probably use anyway. You would need very consistent on/off output levels before the filtering. Just a thought :)
Dan Baldwin
Oct 12, 2005, 10:29 AM
Here's a question though, and I think MatC was kind of getting to this earlier but I probably didn't fully understand. How do I accurately determine my gain? I can measure my resistors and get them matched up and do the gain formula, but what's my real gain? I mean the gain after I account for any input offset voltage of the diff-amp? Do we just measure the voltage going in, and the voltage going out, and divide to get actual gain? (If so, I'm definitely going to need a more accurate DMM...)
Luke
Input offset and gain are unrelated. For most purposes you don't have to take the open loop gain of the op amp into consideration. The venerable LM324 has a typical open loop gain of 100 V/mv, or 100,000. That means that for an output of 10 volts, .1 MV of differential is needed BUT that op amp also has an input offset of 2 MV typical. That 2 MV is always there and will have to be taken into account. If your amp circuit has a closed loop gain of 10, then there will be an output offset of 20 MV if the op amp has a 2 MV input offset. You could measure this offset, and subtract or add the appropriate value in software, since the offset tends to be farly stable, or it could be nulled out in the circuit.
Dan
william541
Oct 15, 2005, 12:53 PM
Glad to hear you have it somewhat working Luke. To measure your true gain, the easiest way is to AC couple the Op-Amp output to a true RMS meter. Run a sine wave at say 500Hz (something well below your cut-off frequency), amplitude about 100 mVrms (with 2.5VDC offset) to the input of the differential amp where the sensor would normally connect. Set your PWM filtered output to about 2.5 VDC (1/2 Vcc). Then if all is set up properly (ie no clipping) then your gain would be output Vrms/input differential Vrms. The AC coupling gets rid of the DC errors in the measurement. On the diff amp, install very low value feedback capacitors, or remove them completely if necessary during the test. You do not want the roll-off of the filter affecting the sine wave gain. Knowing the true gain of the amp, you can then measure the input offset while using a dual supply (+/- supply) to the op-amp. You will be working with very small voltages so a very accurate DMM with twisted or shielded leads is required to even get close.
As others have mentioned, it is much easier to apply an offset in your firmware to account for the offset X gain error. If you put a known 100mV differential in, you would expect this same differential X theoretical gain output. Any error from the optimal value would be what you subtract in firmware.
So what kind/amplitude of noise are you seeing? Have you located the noise source(s)? You can also increase the capacitance in the Diff Amp circuit to help smooth this out. But first identify the source(s) of the noise. Working with a 12-bit A-D, your layout has to be done well and using a prototyping board patched in to your main board can cause noise pick-up problems.
Hope this helps, Bill
LukeZ
Oct 15, 2005, 03:27 PM
Thanks all for all the tips guys. It sounds like I'm going to have to break down and buy a nicer meter, whatever I do. I think again I have been making this somewhat harder than it needs to be - sounds like I can simply measure what's going in, measure what's coming out, figure out the difference from what I know it should be, and subtract that in code.
The process you laid out sounds pretty professional, Bill. I don't really have a way to create a sine wave that I know of (no o-scope). Also don't think I even have a dual supply... I can probably sneak the new DMM by the old lady, but probably not a scope. ;) So I will do that and see how far it gets me.
Calculating your gain: I can't remember the exact formula, but at low frequencies the effects that dominate will be resistor matching and input offset. You'll have to measure both I'm afraid, although the latter should be well specified in the opamp blurb.I suppose by this "blurb" you mean the graph I posted a bit earlier that showed input offset voltage vs. common mode input voltage? This is about all I can find in the datasheet on input offset. Again though, it sounds like instead of using this chart, which is difficult to extrapolate from exactly, that I can simply measure input offset at various common mode ranges and hardcode those adjustments into software (probably I'll take a measurement at each of my PWM ranges).
Noise: where to start? Again I suspect a scope would be quite helfpul in pinpointing the source - not to mention as an aid to designing a filter. I did notice that my measurements seemed to "wave" or pulse slowly up and then down. It was very rhythmic. This seemed to me that it must be a power supply issue so I stuck a 7805 between my PC power supply and the breadboard, as someone suggested earlier. This helped quite a bit. I also increased my running average to 20 samples in code from 10. This tamed the jumpiness of my readings down to about 5 or 6 bits of variance. Those were the easy things that I knew how to do. No doubt getting this thing off the breadboard and onto a PCB will help a bit as well.
Other than that I read about filters online, and it seems like a simple Butterworth would probably take care of the rest. But how to set the specifications for the filter to my particular app I have no idea, as I'm not sure I have the means to go about measuring the exact nature/frequency/amplitute of my noise problem.
Luke
Does this look noisy enough to you? :D
william541
Oct 15, 2005, 09:54 PM
Luke a couple of things you might try.
The bypass capacitors across the supply pins to the Op-Amps should only be 0.1uF ceramic types. Keep the electrolytics on the main power rails of your proto boards though.
Replace the PWM input to the low pass filter with a simple resistor divider or POT that gives you the same DC out as the PWM. Then check for noise again.
Replace the sensor input to the differential amp with a buffer amp and a POT or voltage divider so that it outputs the same DC level as the sensor did. Again check for noise. Typically I remove all the firmware filtering so I can watch the raw ADC values.
If the ADC readings are slow and rythmic, then I don't think you are dealing with noise that a second filter is going to help with. I think you were on the right track looking at your main DC supply. It could also be a case where your PWM is varying due to code issues, interrupts etc.. By bypassing the PWM input as above, you should be able to determine where the fluctuations are coming from.
Pull your ADC reference voltage from very near the pressure sensor VCC supply if you haven't already.
If you had say 2 bits of noise without the diff amp, then you might expect 20 bits of noise with the X10 gain of the diff-amp. This could be another test by just running the sensor by itself (with RC filter) into the ADC and see what the noise amplitude is.
If you need to add another filter, I would put it between the sensor and the diff amp.
Let us know how it goes!
-Bill-
Just a quick addition... Luke, forgive me if I'm not seeing the proto board picture correctly, but a few things stick out as potential problems.
It looks like the op-amp that is being used as the differential amp may not have op-amp A terminated. Any unused op-amps must have the their two inputs DC terminated or they can and do break into oscillation. This will cause large amounts of noise in adjacent sections of the package. I usually make a unity gain buffer out of the unused sections (inverting input tied to output, non-inverting input tied to ground).
It also looks like there may not be any current limiting resistors on your green LEDs that are plugged into the supply rails. These typically don't want more than 20mA of current but are usually run at 15mA or less to ensure a long life.
If the IC on the left in the foreground is your A-D, it looks like a red wire from the output of the diff-amp may be connected to a grounded capacitor?? Then a resistor from there to your A-D? If so, the op-amp may oscillate because they do not like capacitive loading on their outputs.
LukeZ
Oct 16, 2005, 03:47 PM
Bill,
Great suggestions all. You were very observant with regards to my breadboard setup - you were right about everything.
So: I did as you said, and made a unity gain buffer out of the unused section of my diff-amp. I will keep that tip in the back of my head for further reference. In that same vein, my ADC is also two channel - the unused input on that I tied to ground as well.
I replaced the 0.1uf electrolytic caps on the chips with ceramic types. Had never really known what should be used for what, so I usually ended up using electrolytics because their longer leads made it easier for breadboarding. I'll use the ceramics from now on. As you suggested though, I do keep the electrolytics on the power rails.
You were also right about the A/D - I did have an RC circuit on the input (between the diff-amp and the A/D). I was testing this as a filter, but after reading more of the A/D datasheet I took it off as it didn't seem like too great an idea. Now I just have the diff-amp feeding directly into the A/D.
Yes, you were also right about the leds. I guess I hadn't been thinking about current draw. I'm using 5 volt leds so I figured no need for a resistor. They do work fine but you're right, I'm no doubt drawing much more current than necessary.
In an earlier thread you also mentioned putting a small cap from the + input of the diff-amp to ground (this is where the sensor attaches). I did this too (33 pf, didn't have any 47 pfs to experiment with).
All this seems to have helped slightly.
Ok, so I made up two pot circuits to simulate the PWM and the Sensor (used 1K pots for both). On the sensor pot I did as you suggested and ran it through a buffer op-amp before going into the diff-amp.
If I run both pots into the diff-amp, noise appears to be entirely eliminated (on my LCD I am looking at just the raw AD output - a number between 0 and 4096). It may fluctuate between one bit but very slowly, not changing more than once every couple seconds.
When I use just a pot for the PWM and the actual sensor, or the other way around and a pot for the sensor and the actual PWM, the noise returns. It is very difficult to say which one is worse, they both seem to add about the same amount: about 3 or 4 bits of fluctuation. Combined (using the actual PWM and the actual Sensor), it is as before, about 5, 6 or 7 bits of variance, but with all the tweaking above, the jumping does seem to be slightly less chaotic.
So I'm not sure exactly where this leaves me, but I guess I'm going to need additional filtering of some sort. Perhaps I will need to alter my diff-amp design; you had alluded to using two op-amps earlier that would allow more filtering. So maybe something like that.
I have to say Bill, thanks again for all the great help. You've really stuck with this project and I truly appreciate it.
Luke
LukeZ
Oct 16, 2005, 04:17 PM
Here is another thing I have noticed that took me a long time to troubleshoot. When I start up my PIC I run an initialization routine in my code that samples the sensor for several seconds and then, given a known starting altitude, adjusts the assumed sea-level pressure so that my reading gives me the correct height. Bill I know you've read the stuff on my site so you know what I mean. During this initialization routine I had the PIC turn on an LED so I knew what it was doing (I also have it display a message on the LCD but LED indicators are nice too).
After the initialization routine my program goes into its main loop, which simply samples the sensor over and over and displays various information on the screen. Whenever it went into this main loop all of a sudden the pressure reading from the sensor appeared to drop by nearly an entire kPa. It was the difference of several hundred bits of resolution on the AD. For the life of me I couldn't figure this out.
Finally I discovered that turning on the LED during my initialization routine actually dropped my PWM voltage by several hundredths of a volt. So while it was sampling my sensor for the initialization the PWM voltage was not the same as it was during the main loop, after the LED was off. Once the LED was off the PWM went back up to the value that I normally expected it to be at for the particular range, and which I had hardcoded into my program. For what it's worth, this LED is on an entirely different port on my PIC.
After you mentioned the thing with putting a limiting resistor in seried with my LED I thought I should do that: perhaps without it my LED was drawing too much current, adversely affecting the PWM. I looked up the specs for the LED (http://rocky.digikey.com/WebLib/Lumex/Web%20Data/SSL-LX3044ID-5V.pdf) I was using and actually it says that at 5 volts forward the current draw is 12 mAh. This would imply to me no limiting resistor is needed. If I recall correctly, the formula for a limiting resistor is:
R = (Vss - Vf) / If
Since the LED forward voltage is the same as supply voltage, there shouldn't be a need. All the same, I tried a 180 ohm resistor in series, just to see. No change - turning the LED on seriously affects the PWM.
Of course the simple solution is just not to use an LED. However, I wonder what the effect might be when I add other functions to the program - such as reading PWM from a receiver and outputing PWM to control a servo. I wonder if my PWM will be sufficiently stable.
Is there a way that if I use a voltage reference of some sort that I could measure my own PWM output every so often? Now that I think about it, it seems that switching the PICs ref voltage to a different source would probably in itself alter the PWM, so my reading would again not be accurate.
Hmm... :confused:
Luke
vintage1
Oct 16, 2005, 05:31 PM
In an earlier thread you also mentioned putting a small cap from the + input of the diff-amp to ground (this is where the sensor attaches). I did this too (33 pf, didn't have any 47 pfs to experiment with).
All this seems to have helped slightly.
Ok, so I made up two pot circuits to simulate the PWM and the Sensor (used 1K pots for both). On the sensor pot I did as you suggested and ran it through a buffer op-amp before going into the diff-amp.
If I run both pots into the diff-amp, noise appears to be entirely eliminated (on my LCD I am looking at just the raw AD output - a number between 0 and 4096). It may fluctuate between one bit but very slowly, not changing more than once every couple seconds.
Can you post a bit of the circuit layout? I have had considerable experience with low noise analog design...I can't quite visualise what you are doing there - also post values of components, and how fast this circuit needs to respond, and over what voltage range the 12 bits are 'spread' ... I could at least calculate the best theoritical noise figure for you, and see whether you are close, or way off...
When I use just a pot for the PWM and the actual sensor, or the other way around and a pot for the sensor and the actual PWM, the noise returns. It is very difficult to say which one is worse, they both seem to add about the same amount: about 3 or 4 bits of fluctuation. Combined (using the actual PWM and the actual Sensor), it is as before, about 5, 6 or 7 bits of variance, but with all the tweaking above, the jumping does seem to be slightly less chaotic.
a lot depends on the bandwidth: You should at least knock that well below sampling rate as any bandwidth beyond that is useless: You MAY have issues with high value resistors generating noise,or simply digital noise getting into the front end. Again, circuit please!
So I'm not sure exactly where this leaves me, but I guess I'm going to need additional filtering of some sort. Perhaps I will need to alter my diff-amp design; you had alluded to using two op-amps earlier that would allow more filtering. So maybe something like that.
Lets see what you have. If your sample rate is well up above the response rate you need for this, simple low order low Q filtering is easy to do. But lets see the design.
Input noise on a FET opamp is around 2-4nV per root hertz bandwith...but a 47k resistor is about 5 times that on its own!
william541
Oct 16, 2005, 08:23 PM
Sounds like you are making more progress Luke. With the 12-bit A-D and 1.22mV/bit, this would only require 122uV of differential noise / bit on the input. The wire lead "antennas" of the breadboard can certainly pick up a good portion of what you are seeing. As Vintage mentioned, lower the cut-off frequency of the diff amp by replacing the two 33pF capacitors with 1000 pF units (.001uF). See if this makes any difference in the number of bits of total variation. It would also be helpful to know at what rate you are seeing the 6+ bits of change. Is it over several seconds and do you have an averaging filter still running? The averaging filter may be masking what is going on. You could also try what Vintage mentioned and lower the input impedance of the diff amp by using 10K and 100K resistors, but I don't think you will see significant noise out of the metal film resistors (at least that looks like what you have on the board).
What concerns me the most is the PWM voltage variances with the loading on the port pins. I would have thought that the ports would have been much more stable. The 20-30 mV is way too much error for what you are doing. You may need to drive a simple comparator using the extra op-amp package in your PWM filter IC. This should kill the loading issues associated with the micro port pins and still keep the output ratiometric with the supply voltage. Basically use an amplifier with a gain of 2 and let the PWM hit the rails prior to filtering.
I'll draw up something that you can easily try on your breadboard and then compare results.
Looks like you are fine on the LEDs (The formula too), I didn't realize this was the type of LED you were using.
Keep going, you are making progress! -Bill-
LukeZ
Oct 16, 2005, 09:51 PM
Can you post a bit of the circuit layout? I have had considerable experience with low noise analog design...I can't quite visualise what you are doing there - also post values of components, and how fast this circuit needs to respond, and over what voltage range the 12 bits are 'spread' ... I could at least calculate the best theoritical noise figure for you, and see whether you are close, or way off...Vintage, I'm not doing anything too different from the schematics Bill posted earlier. Post #47 shows the PWM to DC circuit; I'm using this unchanged. This creates a DC voltage that I use to "follow" the sensor voltage so that the difference between the two that goes into the diff-amp doesn't get too wide.
Post #19 shows the diff-amp circuit. I have modified it from what Bill has shown in that I switched the inputs to the diff-amp: the sensor now goes into the + input and the PWM into the inverting input. For the gain resistors I am using 1M for RB and RD, and 90.9k for RA and RC. These are 1%, 1/4 watt metal film resistors. Also I added a 33 pF cap from the + input of the diff-amp to ground. That and the 33 pF in the feedback loop are the two that Bill just mentioned I might try bumping up to 1000 pF in his last post. I didn't have any 1000pF laying around but I upped it to 470pF, and I believe that has helped.
The voltage range over which the 12 bits are spread? Should always be quite nearly Gnd to Vsupply. This is what the diff-amp is for. It multiplies by approximately 11 the small difference in voltage between the sensor and PWM-to-DC: a difference never greater than about 0.45 volts, as the PWM follows the sensor voltage up or down.
So I've done some further testing, having made these two changes: first, I upped the two diff-amp caps to 470 pF. Second, I took out the firmware filtering (actually have a switch on the PIC so I can turn it on or off). This is what I found:
If I use pots to simulate both the sensor and the PWM, the reading is ROCK solid. Not a single fluctuation over several minutes. I think the caps have helped.
Next I put the sensor online but kept the pot for PWM. Without the firmware filter what I see looks like glitches about once or twice a second that throw off the AD reading by several bits for a very short moment, but it always reverts back to its original reading afterwards. These disturbances always appear to push the AD reading up - or in other words increase the voltage. Not sure what exactly that tells us, but it seems important. I should say though: turning on the firmware filtering almost entirely removes these disturbances. This makes sense: intermitent small glitches won't be able to affect the overall average very much. Like this, I can lift my breadboard one foot off the desk and see the altitude increase by one foot, and vice versa if I lower it to the floor. Very nice!
Finally, I put the PWM-to-DC online and use a pot to simulate the sensor. The noise is much more random, sometimes going up and sometimes going down. It is also pretty much continuous, rather than sharply defined glitches as described above. There will be some intermitent moments of steadiness but they don't last long. So I think most of my noise is coming from the PWM side of things.
I just now thought I might try to shoot a short video of my LCD and post it. Since I was getting glare I turned off the lights as well as my computer screen. Strangely, the noise seemed to decrease somewhat... hmm, could my breadboard be picking up any interference from my PC monitor? It's only inches away, duh! :rolleyes:
Anyways, here's the video (http://www.kansasflyer.org/images/eZone/PWM_Video.avi) (right-click and select "Save Target As"). This video is of the AD stream (in the top right of the screen) from the circuit with a pot substituting for the sensor but the actual PWM going into the diff-amp. It gives you an idea of what the noise looks like. (If you wonder who Matdy is, that would be the cat...)
At any rate, since it looks like we'll be modifying the PWM circuit anyways, maybe we can deal with the noise at the same time? I'll wait to see your schematic, Bill.
Luke
william541
Oct 16, 2005, 10:38 PM
Ha Ha, I think you hit the nail on the head with a couple of your tests. Lets see if we can tame the PWM noise and the impulse noise in your A-D readings.
In the attached schematic I added a "PWM Shaper" which is just an amp with a gain of 2. I went this route instead of the comparator because it had fewer parts and allowed some high frequency filtering (for PIC transients). What this should do is output the PWM and force it to the rails so that the amplitude of the signal follows VCC and is not hindered by the micros inability to output the same amplitude PWM each time.
I also threw in the other differential amp we were talking about so others can see the difference, may be a bit over kill though. Anyways you can try it with several circuit combinations and see what works best for you.
Now, the impulse noise that happens every once in a while is somewhat easy to cure in code. The trick is not to use an averaging filter, but rather a Median filter. If you are not familiar with one, take 5 to 7 samples then sort them according to their magnitude (bubble sort routine), then take the value in the middle for your reading.
I think you will find that once this is placed on a circuit board that your noise and noise susceptibility will be much better.
Keep us updated! -Bill-
LukeZ
Oct 17, 2005, 01:08 AM
Bill,
This is really great. It took me a while to figure out what you were doing, but I finally got it. Since PWM is just a series of ons and offs, you take every "on" and multiply it by two - in case the PIC can't make the "on" be all the way to the positive rail, this op-amp will. Even if the PIC falters to half of Vcc we'll still have a full PWM out. So simple yet to me it seems brilliant, and as with all your suggestions, so incredibly practical. This is just the kind of thing I wouldn't find in a month's worth of searching the textbooks.
The rest of the circuit makes good sense. It's back to the job tomorrow morning but I will be experimenting with these things as I get the chance. I'm sure this will make a big difference. I'll let you know how it goes.
Thanks again!!
Luke
LukeZ
Dec 03, 2005, 10:37 PM
Well it's been quite a while but I'm back on the project. I had to do work on some unrelated circuits for the last month or so but that stuff is done now.
Bill, after reminding myself of where I was, I wired up your PWM shaper circuit as well as your hi-z diff-amp and started poking around.
If you recall we had two problems- general noise, and the other issue with the PWM DC dropping whenever a load was placed on another port pin.
Port loading - PWM/DC Change
This issue I'm afraid to say is still there even with the shaper. If I turn on an LED I still get a voltage drop - up to 50 mv. I find the drop varies considerably depending on the duty cycle - low duty cycles experience smaller voltage drops during load conditions, but I suppose as a percent of total DC out it would be about the same.
I tried increasing the gain on the shaper to 4 rather than 2 - no difference.
I've wondered if loading the ports does more than lower the peaks of the PWM, but if it affected the duty cycle or something. I tried checking the duty cycle using my Fluke but I couldn't really get it to work - it would always read either 0 or 100 essentially. I'm not sure if it's meant to measure this sort of signal or not. (I also couldn't really get the Fluke to indicate the PWM frequency either, which I thought perhaps it should be able to do. Not that I need to measure it - I'm just playing around trying to figure this beast out).
So: I'm not sure why the shaper doesn't work. It seems like it should.
I looked up comparators on the net. They look simple enough. Do you think I should try this approach instead, or should we adjust our shaper? If I made a comparator with the inverting input set close to ground with a voltage divider, say at 2 volts or something, then put the PWM into the positive input of the op-amp, would that basically be what we're going for?
Noise
Here I made some interesting notes. Noise on the PWM side of things is vastly improved with the new shaper circuit. Even without software filtering I only get occasional glitches typically of no more than 1 bit. So it looks like your RC filter on the output of the shaper really helped (I presume that's what that is). The little noise that is left is easily taken care of in software.
However, the sensor side of things creates markedly more noise than in the previous circuit (as before I'm isolating the two halves by substituting pots for one or the other). Its noise is more continuous and random than well-pronounced glitches, and spans probably 20 bits or more: several hundredths of a volt according to my A/D. My Fluke shows variation of only several millivolts on the input to the A/D, but I think it does not refresh nearly so fast as my A/D measures, at least that is the only reason I can think of for there to be a difference.
No doubt a whole lot of this noise problem would improve on a PCB, and of course I can do stuff in software. Is there any additional filtering we could easily add to the sensor side with this new circuit?
Conclusion
There is some good news in my further testing, in addition to all the good learning I'm doing - PWM noise is way down. And with even basic software noise filtering, which I can improve, the overall end result is pretty good. I'm not sure if it's good enough yet for an altitude hold circuit, but we're certainly to the point where we have a more than adequate altimeter.
Luke
LukeZ
Dec 03, 2005, 11:03 PM
I just thought I'd try to see what affect there would be if I switched out the hi-z diff amp for our original diff amp, but leave the PWM shaper and other changes in. Previously it appeared that I had very little noise on the sensor side of things using the regular diff-amp.
However, this didn't really offer any improvement or even noticeable change. I still see a lot of noise on the sensor side. Who knows - I've changed the layout on my breadboard a bit and maybe I've got a new source of interference that wasn't there before. Hard to say. Could just be a lot of static in the air today maybe. ;)
I do remember to turn my computer screen off now, however! :D
Luke
william541
Dec 11, 2005, 02:03 AM
Hi Luke,
I wondered what happened to you... sounds like you got busy doing other stuff... I know how that goes!
On your meter, it should measure those parameters just fine.
For Hz - Set meter selecter to V~ then press the [Hz % ms] button once. The frequency should be displayed.
For Duty cycle - Set meter selecter to V~ then press the [Hz % ms] button twice. The positive duty cycle should be displayed in %. You can then press the pulse polarity buttons to switch between the positive and negetive pulse displays.
If you are looking for fast transients with the DMM, you are almost forced to use the bar graph, or you can use the fast min/max function to catch them.
On your port loading issue, I'm not sure I understand where you are measuring the 50mV drop in voltage? Is your whole Vdd supply dropping 50mV? The duty cycle of the PWM should not change at all due to port pin loading. Take some voltage readings across the supply pins for each IC during the port loading, I'll bet you find the voltage drop that is causing the problem is either in the Vdd or Vss supply lines to one or more chips. Perhaps not all the chips are seeing the same droop in the supply rails.
For your sensor noise, did you happen to place the RC filter on the output of the sensor and use the diff-amp in the last posting? If so, increase the capacitance or resistance in the RC filter and/or increase the feedback capacitance in the diff-amp.
Just some thoughts, it's kind of hard to de-bug at this end without hands on...
Take care, Bill
LukeZ
Dec 11, 2005, 03:35 PM
Bill, thanks for writing back. It's good to hear from you again. Life certainly does get in the way sometimes, but I'm going to see this thing through no matter how long it takes!
You're right about my meter - I was going about it wrong. I went to Volts DC first and then was pressing the [Hz % ms] button from there, which it will allow you to do. But it makes sense that duty cycle and certainly frequency are AC components. Doing it that way my meter read things fine, and showed just what I expected. And you're also right - under load the duty cycle does not change. It might spike or drop for just a very brief moment when the load begins or ends, but under sustained load it stays at the same duty cycle as without the load.
I've made some measurements of the voltage drops I've encountered under load. Load being defined as having the PIC turn an LED on. These measurements are all DC readings on my Fluke:
- Straight out of the PIC on the PWM pin: .04 - .05 volts (40-50 mv)
- Output of the PWM "shaper": .0045 volts (4.5 mv)
- Output of PWM-to-DC op-amp: .0045 volts (4.5 mv)
Next I put my com probe on the ground rail, and measured the drop on the Vss pin of the two op-amps:
- Vss of PWM op-amp: .0035 volts (3.5 mv)
- Vss of Hi-Z diff-amp: .002 volts (2 mv)
Finally, I put my positive probe on the Vss rail and measured voltage drop on the Vdd pin of the two op-amps:
- Vdd of PWM op-amp: .002 volts (2 mv)
- Vdd 0f Hi-Z diff-amp: .002 volts (2mv)
I am using the circuit you posted most recently, which uses two, dual op-amp chips. One shapes and converts the PWM, the other is the Hi-Z diff-amp.
This doesn't look as bad as the 50 mv drop I had mentioned earlier. Partly this is because all my readings can really change from day to day and even from minute to minute. Reset the PIC and maybe this time it will look a lot better. It's just not too consistent, for whatever reason. Also, I can't recall from my last post but I may have been measuring the change on the output of the diff-amp, at which point any change in voltage has been amplified 10 times.
As for noise - I played around with different caps and such. If I increase the capacitance in the feedback loop of one half of the diff-amp, should I make the capacitance in the second feedback loop the same? I didn't know about that.
What I have now is 1000pf in the feedback loop of the sensor half of the Hi-Z diff amp. On the PWM side I upped the cap to 100pf. Both had been 33pf originally, as per your schematic. These changes seem to help out with the noise. I also played a bit with the RC filter on the output of the sensor but it did not seem to make as much difference as the cap in the feedback loop. So I've left the RC filter at 750 ohm/0.33 uf.
I'd say noise now is what I would consider very manageable. It varies but is not really much more than one or two bits out of 4000. I think that of the noise left, a good deal of it should be taken care of with a PCB layout (assuming I do it well), and all the rest can be handled in software.
Really my only issue left now is the port loading problem, and then I have some more work to do in code. My range transitions sometimes don't work very well - but I can improve the code there.
Luke
LukeZ
Dec 11, 2005, 07:43 PM
I've been thinking about this port loading issue and I wonder if it's even something I need to be seriously concerned with. Why not just only take pressure readings when the LEDs and what not are all off? In fact I won't even need a LED on this thing, but the PIC will be doing other stuff - reading other sensors and communicating with a UART on the sensor-package version, and controlling an R/C servo on the altitude-hold version. I have not tested the effect of those other activities... I need to. Still, taking an A/D reading can be done very quickly, and while that's happening I could leave everything else quiet.
Anyways, something for me to think about...
Luke
Mr.RC-CAM
Dec 11, 2005, 09:40 PM
I've been thinking about this port loading issue and I wonder if it's even something I need to be seriously concerned with.If your emulated D/A requirements involve mV precision, then you can buy yourself a lot of breathing room if you logic level buffer the PWM'd PIC outputs rather than direct drive them. The trick is to power the buffer components with a precise power source (isolated from the digital supply) and use temperature stable components.
LukeZ
Dec 12, 2005, 04:48 PM
Mr. RC-Cam, I've not heard of "Logic-level buffer" before - if you see the schematic Bill posted, we're passing the PWM through a buffer amp with a gain of two. Is that pretty much what you mean? Just that I need a precision power supply isolated from digital ground to drive this amp (and downstream components)?
Would my A/D chip be on this precision supply as well? Like most it's half digitial and half analog - it communicates over an SPI interface. I'd think if it had a seperate ground potential from the analog voltage it was reading, that would cause problems.
Luke
Mr.RC-CAM
Dec 12, 2005, 05:14 PM
Yes, the OpAmp in the schematic is acting as a relaxed signal buffer. However, it sounds like the 2X gain is not working for you. So, fully isolate it by reconfiguring the OpAmp as a comparator. All it would take would be to move the resistors.
However, if you are not using isolated analog power and gnd for your analog components, then I think you have identified a significant problem. On applications where some power supply issues can be tolerated then this is not necessary. However, if you are trying to resolve mV signal level changes then everything matters.
I'd think if it had a separate ground potential from the analog voltage it was reading, that would cause problems. On the contrary, the analog gnd should never freely share the digital gnd. You need to create two gnd busses, one analog and one digital, with both going to a single point gnd in the power supply. Along with that, you need two power busses. Sometimes you can just filter the analog run and utilize a common Vreg IC. In your case, I recommend that the analog devices use their own VReg.
Once things are working well you can always Muntz the circuit to reduce any unneeded components. So, it's often useful to over design at the start, then take away the fluff after you have established the required operating performance.
LukeZ
Dec 17, 2005, 02:42 PM
Ok Mr. RC-Cam, I tried the comparator but it really didn't help with the voltage drop issue - I suspect, however, that as you say this is because on my breadboard I'm using a common voltage supply for digital and analog components.
Really, unless there's some other obvious hardware tricks for me to play with, I think I'm probably ready to just lay out a proper PCB and see what I get. Accurately resolving a thousandth or even a ten-thousandth of a volt on a messy breadboard is just not going to work. Any reason why this shouldn't be my next step?
I've gotten started on my circuit in Eagle. I'll post my schematics and layout for review before I send anything in. However, I have a few questions:
Mr. RC-Cam, if I do go with dual supplies, do you recommend any particular supply chips? Earlier in this thread the Simple Switchers were mentioned - I don't know if they would be good for the analog side or not. Should I use a simple switcher for the digital supply and then a 7805 for the analog or something? Or probably an LDO Vreg would be better than the '05, since the battery source could potentially get close to 5 volts. This circuit will be powered by standard RC batteries - so I'm thinking the lowest we could be dealing with is 2S lipos. Close to empty they would be putting out very little above 5 volts.
Bill, I know you've had experience with this stuff too - I'm always happy to hear your advice as well.
I'm going to be doing this board in SMT components - my first. I'll be soldering it by hand. I'm sure I'll have some more questions about that, but I'll wait until I get my schematic finalized. There's other stuff I want on this board that I need to make some decisions on...
Luke
Mr.RC-CAM
Dec 17, 2005, 03:07 PM
tried the comparator but it really didn't help with the voltage drop issue - I suspect, however, that as you say this is because on my breadboard I'm using a common voltage supply for digital and analog components.Just review the ground and power paths first. They appear to be your weak link. As mentioned, you should have two distinct power circuits, one for the analog and one for the digital. They may even share the same supply (perhaps with a filter on the analog V+), but the common connections must be made with care (lowest impedance point at the supply).
Accurately resolving a thousandth or even a ten-thousandth of a volt on a messy breadboard is just not going to work. Any reason why this shouldn't be my next step? Actually, you should be able to use the breadboard for prototyping this circuit. It's just a matter of being careful how you string the wires, which is the same issue you will encounter when you route the PCB.
Mr. RC-Cam, if I do go with dual supplies, do you recommend any particular supply chips? Earlier in this thread the Simple Switchers were mentioned - I don't know if they would be good for the analog side or not. Should I use a simple switcher for the digital supply and then a 7805 for the analog or something? Or probably an LDO Vreg would be better than the '05, since the battery source could potentially get close to 5 volts.Use one or two LDO's. If you need operation close to 5VDC, then pay close attention to the LDO specs. Some need 0.5V and higher overhead, whereas others can work with less. Personally, I think a single Vreg would work if your analog power was cleaned up with an LC filter. But, it would be safer to start with two Vregs and then Muntz it later when things are working.
I'm going to be doing this board in SMT components - my first.Just my opinion, but you might want to save your first SMT board layout for a design that is working to your satisfaction. I think you will find a through-hole board to be easier to hack if you need to make circuit changes.
LukeZ
Dec 17, 2005, 05:31 PM
Mr. RC-Cam: I've taken your suggestions, at least as much as I know how. Here's what I did: I have two breadboards. I moved stuff around so I have all my analog components (sensor, op-amps, and A/D converter) on one board. The other board is the digital board. Basically it just has my PIC on it.
I'm using a PC power supply on my workbench. It feeds 12 volts to both boards. I've given each board its own 7805 vreg (and associated filtering and smoothing caps). The only connections between the two boards are the communication lines between the PIC and the A/D chip, and the PWM out from the PIC that goes into the comparator on the analog side. The common ground connection point would be somewhere inside the PC power supply.
With this setup the voltage drop issue is better, but still not perfect. If the PIC turns on an LED, the drop on the PWM pin is about 0.015 volts (1.5 mv). The comparator should take care of this, and it mostly does: the drop on the output of the comparator is 0.0008 (~.1 mv). This is pretty small, but it still equates to about a 5 or 6 bits on the A/D output. Since my resolution is pretty close to 1ft/bit, this means the altitude drops by 5 feet. For an altitude-hold circuit, this isn't going to look very nice. For just a regular ol' altimeter, it's fine.
I tried changing the reference voltage on the comparator - initially I had the voltage divider resistors equal (10k each), so the reference voltage was Vss/2. I adjusted the resistor values so the reference dropped to Vss/3. This didn't help. Still get a 0.0008 volt drop on the output.
I will say one thing - as I mentioned in a previous post, the voltages on Vss and Vdd pins of my various op-amp chips varied when the PIC turned on the LED - with the split supply, that no longer happens. They remain completely steady.
Still not sure why the comparator isn't 100 percent effective... Maybe I need to use a different kind of op-amp? I'm using the TLV2472 rail-to-rail by TI.
I'm including my current schematic as well - maybe I didn't wire the comparator correctly...
Luke
Mr.RC-CAM
Dec 17, 2005, 06:09 PM
If the PIC turns on an LED, the drop on the PWM pin is about 0.015 volts (1.5 mv). The comparator should take care of this, and it mostly does: the drop on the output of the comparator is 0.0008 (~.1 mv). Sounds like you are close. Are you sure the comparator's supply voltage is also not lower or glitchy during the LED on time? Measure it at the IC, not at the Vreg.
BTW, how is your PIC clocked? Is it Xtal, RC, or Internal Osc?
This is pretty small, but it still equates to about a 5 or 6 bits on the A/D output. Since my resolution is pretty close to 1ft/bit, this means the altitude drops by 5 feet.If you want accurate 1ft resolution, you need to aim for something better than 1 count per foot. Otherwise, system noise will be in the way.
LukeZ
Dec 17, 2005, 08:02 PM
My measurements were at the supply pins of the comparator IC - they do not fluctuate by even 0.0001 volt - that's the best resolution my Fluke gives.
I'm using a 20 mHz crystal on the PIC.
That's a good point about having a resolution higher than the target goal - but if I'm going to address the PWM drop by increasing gain, I'll need to go from my current gain of 10 to a gain of 50 if I want to "drown out" that 5 bits of noise down to 1. I'd think such a high gain would likely introduce its own additional noise - not to mention it would make the code more complex (the PWM "follows" the sensor output to keep the input to the diff-amp away from the rails. At a gain of 50 I'd have nearly as many PWM ranges to tweak...)
If possible I'd like to nip the problem at the comparator stage. Might I try daisy-chaining two comparators in series? I have an extra op-amp to work with. I'll see if that helps...
Luke
william541
Dec 17, 2005, 08:07 PM
Just had a chance to read your updates, looks like you are further ahead. I was happy to hear you have grouped all of your analog circuits together on the same board. 0.8mV change on your PWM under load is not too shabby for this type of circuit. RC-CAM is right, cleaning it up further from here is not a trivial task. You might want to try a 4.7K resistor from your pwm output to your comparator input to provide similar impedances to the op-amp inputs, but I'm not sure you will gain much if any.
Even if your supply voltage varies, this should not effect your A-D readings as long as the op-amps, sensor and A-D reference all share the same supply or at least track each other.
I was curious how much your A-D reading was fluctuating when you turn on your LED now? When you get down to the low mV and uV readings, even your DMM leads will introduce errors and it is sometimes better to use the on-board A-D to see how good or bad it really is.
Still not sure why the comparator isn't 100 percent effective... Maybe I need to use a different kind of op-amp? I'm using the TLV2472 rail-to-rail by TI.
I'm not sure your comparator is to blame here but rather the quality of the PWM output. Try the resistor mentioned earlier and see if this helps a bit. You could even load the comparator output a bit to see of that helps a bit. Right now there is very little loading on the PWM output.
As far as your layout, I always shoot for a common ground plane and control the return paths of the digital and analog signals. But sometimes it is easier to split the planes which can introduce another set of problems in certain designs. Just remember that ground currents for the most part will travel directly under the signal trace where they can (if there is copper there for it to follow). Your biggest noise source will probably be your sensor and the SPI interface. The SPI can be controlled somewhat by letting the A-D do its job while you are not yacking on the bus.
I guess I differ from some, I prefer surface mount to prototype with. For me it is much easier to cut and add. Especially if you stick with 0805 or larger parts. and stay with =>50mil pitch SM IC's where you can.
Take care, Bill
Mr.RC-CAM
Dec 17, 2005, 10:25 PM
I'm using a 20 mHz crystal on the PIC. Drat. Had you said RC or intRC, then I might have had an explanation for the behavior. The xtal is best.
I'll need to go from my current gain of 10 to a gain of 50 if I want to "drown out" that 5 bits of noise down to 1. Realistically speaking, if you have achieved 5 bits of uncertainty on a 12-bit A/D then pat yourself on the back. That would be impressive even on a 2-layer PCB.
If possible I'd like to nip the problem at the comparator stage. Might I try daisy-chaining two comparators in series?That is not expected to help. One is enough.
If the only time you experience the PWM Vdrop is when the LED is switched on, then you may be able to eliminate the issue by buffering the LED with a transistor. The LED's power and Gnd should be connected to the Vreg's common pwr/gnd. The buffer will reduce the PIC's 10-20mA I/O drive current to about 0.5mA. If the issue is due to changes in current draw within the PIC then this should help.
Even if your supply voltage varies, this should not effect your A-D readings as long as the op-amps, sensor and A-D reference all share the same supply or at least track each other.As long as the voltages at each of those devices tracks each other perfectly, then the common mode issue is solved. This may be the case in this project and the Vdrop at the PWM output may not even be a real problem.
I guess I differ from some, I prefer surface mount to prototype with. For me it is much easier to cut and add. Especially if you stick with 0805 or larger parts. and stay with =>50mil pitch SM IC's where you can.The nice thing about using through hole is that those dead bugged "3-dimensional" components are easy to add. And, SMD resistor and cap patches can still be used on the through hole board where convenient. I found that trick to be very handy.
So, here is a new question. If you watch the distribution of the data when the LED is off and the A/D input is constant, what happens to the data distribution when the LED is turned on? That is, what is the magnitude of the A/D's change in count? It would be helpful to average the data for this test.
LukeZ
Dec 18, 2005, 12:22 AM
0.8mV change on your PWM under load is not too shabby for this type of circuit.Of course, that's after the comparator...
You might want to try a 4.7K resistor from your pwm output to your comparator input to provide similar impedances to the op-amp inputs, but I'm not sure you will gain much if any.Ok, I just tried this. Hard to say if it made much difference... but it certainly didn't make it worse.
Even if your supply voltage varies, this should not effect your A-D readings as long as the op-amps, sensor and A-D reference all share the same supply or at least track each other.Actually, if this were the case then I don't think I'd see a fluctuation on the A/D. At this point it's really not the supply voltage that is fluctuating, at least not for any of the analog components. The supply pins on my op-amp chips as well as on my A/D chip remain virtually unaffected by the LED turning on. I can't say the same for my PIC, the supply there does drop when the LED turns on. In fact, measuring the supply pins on the PIC I see the voltage there is pretty noisy. But I suppose that's because that's the digital side. The voltage going to my analog ICs is completely steady and unchanging, even down to 0.1 mv, no matter what I do with the PIC. Guess that makes sense as I'm using a completely different vreg on the analog side.
I was curious how much your A-D reading was fluctuating when you turn on your LED now? When you get down to the low mV and uV readings, even your DMM leads will introduce errors and it is sometimes better to use the on-board A-D to see how good or bad it really is.So, here is a new question. If you watch the distribution of the data when the LED is off and the A/D input is constant, what happens to the data distribution when the LED is turned on? That is, what is the magnitude of the A/D's change in count? It would be helpful to average the data for this test.I might be missundertanding both of your questions - but the change on the A/D is pretty consistently 5 bits when the LED comes on. This is true whether I average the readings in software or not - it just takes longer to get there using the averaging filter. Working backwards, this makes sense with what I know about the PWM drop. Five bits on a 12 bit A/D with a Vsupply of 5 volts comes to about 0.006 volts (5v/4096)*5bits. Given that by the time it's reached the A/D the voltage has been "multiplied" by a gain of roughly 10 on the diff-amp, this means the original shift on the input of the diff amp should be around 0.0006 volts. And in fact that's right - if I measure the voltage drop on the output of the comparator, it comes to about 0.0008 volts (my gain probably isn't exactly 10).
If the only time you experience the PWM Vdrop is when the LED is switched on, then you may be able to eliminate the issue by buffering the LED with a transistor. If the issue is due to changes in current draw within the PIC then this should help.You're right - this is the only time I experience the drop, and I think you're also right, that changes in the current draw within the PIC must be the issue. In fact the LED is totally unecessary, and I probably won't even put one on my board. I had it there for debugging and noticed that when it was on it caused this problem. Of course on the final version, even without an LED, there will be other pins doing this or that that could have the same effect.
It seems to me that we have done pretty much what we could using the comparator. Probably what I could do is hi-z my other PIC output pins while taking altimeter readings, and only do work on them when the PWM isn't needed to be steady. OR, even if I did need to use another PIC pin at the same time, for communication or something, surely I wouldn't need it to source 12 mAh for a length of several seconds, which is what it's doing now with my LED. If other pins were only loaded for a very brief bit of time, my averaging filter should wash out the momentary voltage drop.
I still haven't decided on SMT vs. thru-hole. Probably I can do a bit of both...
Luke
Mr.RC-CAM
Dec 18, 2005, 12:37 AM
The easiest fix at this point is to just control what the PIC is doing while you measure the A/D input. That is, turn off all the I/O pins that are impacting your measurements. Tricks like this are common in apps that need to squeeze out every last A/D count. I do believe you will need more amp gain. Expecting one foot accuracy, where one A/D count is one foot, will just cause you disappointment.
LukeZ
Mar 10, 2006, 11:38 PM
Ok, after a long hiatus I'm working on my next PCB. Here's a quick question:
I'm going to have a couple trimpots on board that will connect directly to some analog pins on my PIC. These will just be used to adjust some gain/travel parameters for the elevator servo. So nothing real critical.
My question is, should these trimpots be hooked up to my analog supply/ground, or to the digital supply/ground? I guess the analog side is preferable in terms of stability, but I just didn't know if, given the intended use, it might not really matter much.
I hope to have a board layout posted, if not this weekend, then next. Maybe you all can give me some feedback.
Luke
Mr.RC-CAM
Mar 11, 2006, 12:52 AM
The trimpots are using the "analog" feature of the PIC, so they should use the analog suppy rails of your layout. Even though it probably will not matter in your app, it is a good habit to observe the analog vs. digital paths. Because if it should happen to matter, you will be prepared.
LukeZ
Mar 11, 2006, 02:22 AM
Thanks Mr. RC-Cam. That's what I figured.
I'm fiddling around with my board layout. I'm not real experienced in this area so I'm not sure how to go about it exactly. I'm posting a picture of my general idea.
It shows that I have two ground planes, one digital and one analog. Each plane occupies the bottom layer of my two-layer board. Positive signals are carried by traces along the top layer (represented by the red tree-branch lines).
Neither ground plane is connected to each other (is that ok?). There are two LDOs for the two supplies. They share a common voltage supply but anything downstream of the LDOs is split into digital and analog supplies.
I've decided to go with SMT parts mostly. Resistors will be 1206 size and capacitors will be at least that large. So most all of my components can go on the top layer, with through holes down to the ground planes.
I suppose that in those cases where I'll need to run signal traces on the bottom layer, they will simply carve out a small slot in the ground plane.
So, is this even the correct approach? Am I on the right track? I know my final layout might be different from this but I'm just trying to get a general idea of how to proceed.
Luke
Mr.RC-CAM
Mar 11, 2006, 02:44 AM
The routing of the power busses is just as important as the grounds. In the end, it will all matter.
I've sort of lost track of what your requirements are. FWIW, getting more than about 12 *real* bits from a A/D, that is built on a 2 layer board, is usually a challenge. And that assumes everything is perfect. If you are expecting more A/D bit performance, then I recommend a 4-layer board. In the presence of guassian noise you can certainly filter the data to increase the effective bits (but then using an expensive A/D would not be necessary).
JimDrew
Mar 11, 2006, 10:49 AM
Here is another little known fact... whenever the A/D converter is turned ON, there is always a voltage drop. When it is turned off, the power goes back up. If you turn the A/D converter on and leave it on, the current draw will remain the same the entire time and the voltage won't fluctuate. It is possible that the A/D converter is causing the voltage drop and not the LED. The I/O pins are internally buffered to prevent this type of a problem, but the A/D converter does not have any buffering. Are you turning off the A/D converter after your sample? How close does the sampling coincide with the LED output?
JimDrew
Mar 11, 2006, 10:54 AM
On the off chance that you have a faulty PIC, have you tried another one to see if the results are the same? I have seen a few times where the I/O pin(s) are flakey and cause oddities.
LukeZ
Mar 11, 2006, 03:37 PM
I've sort of lost track of what your requirements are.Ha ha! Yes, this project has dragged on for an eternity. It's nearly a year since I started this thread... :rolleyes:
But as it turns out I am not hoping for more than 12 bits of resolution from this board. My A/D is only 12 bit so I wouldn't be able to go higher than that anyhow. But realistically I can deal with 11. I have some room to work with.
I don't think I need this layout to be Pentium precise. It works pretty darn good on my breadboard already. Using two supplies really cuts down the noise on the analog side. All I really need are some general guidelines for well-laid out boards, specifically as it concerns analog/digital seperation, since I've never really done this before. But if my sketch above doesn't look outrageously wrong, then I'll probably go with that for starters. I'll post my actual Eagle board for review, before I send it off for fabrication.
JimDrew,
I had not thought about the A/D but that is a good point. In fact my A/D does have a "shutdown" mode - but I have not been using it. It's been on the entire time. I've also tried more than on PIC, both with the same effect. I'm pretty certain this is an issue related to the LED, or rather, to loading on the PIC pins. However, the easy fix is to only take A/D readings at a known state. In other words, leave the LED off when taking measurements (or leave it on always).
Luke
Mr.RC-CAM
Mar 11, 2006, 04:09 PM
All I really need are some general guidelines for well-laid out boards...A fellow could write a book on how to layout a low noise PCB (actually, there are books on the subject :) ). My best advice? Be diligent and then just consider that another PCB spin might be required. There is nothing shameful about that.
Some things to keep in mind.
1) Don't daisy chain the power/grounds. Use a buss system with sufficient trace widths to keep impedance low. From your drawing, it looks like you are doing your best to maintain this. The ground plane is very helpful and offers a low impedance ground path.
2) Keep all TTL signal paths and clocks ,that will be active during the A/D conversion, far away from the analog circuitry. Don't forget to route boths sides with care (fiberglass offers no protection from coupled noise).
3) Place your decoupling caps next to each IC. These are small values, under .1uF. Short traces with good trace widths.
4) If you have extremely sensitive analog inputs on the OpAmps, that will use microvolt input signals, then consider guard banding them. I doubt you need to worry about this, but your project details are sort of a mystery.
5) If you have a MAX232 IC anywhere in your project (perhaps you do?) then keep in mind that they are very noisy. Keep them away from the analog!
LukeZ
Mar 11, 2006, 04:44 PM
Mr. RC-Cam, thanks for the tips. My drawing wasn't very specific with regards to the power traces on the top layer, but I will do as you say and use a bus system rather than daisy-chain from one IC to the next.
I debated a Max232... but in the end decided to leave it off. I can plug one in externally if I need to.
I'm sorry the details are so mysterious! :p I'm just doing a basic altimeter circuit. The tricky part of this one is the requirement to have very fine resolution, while at the same time maintaining the ability to read the full scale of the sensor's output (0-45,000 feet), all with only a 12 bit A/D. As you might recall, the method used to accomplish these things is to dynamically scale the input into the diff-amp (Bill had this idea). The PIC creates a variable voltage that "follows" the voltage of the sensor, and both these voltages go into a diff-amp. I know what the voltage out of the PIC is, so I can add to it the voltage measured across the diff-amp to get a high resolution sensor reading. As soon as the output from the diff-amp approaches the rails, I just shift my variable voltage to put the difference between it and the sensor back into the diff-amp's most efficient range.
Probably not explaining it very well, but in any case, all this variable voltage stuff (PWM to DC using a comparator) needs to be stable, and combined with the usual requirements for clean environments for the A/D and etc, I need a good layout.
Eventually I want to use this circuit in two applications - one as a simple plug-n-play altitude hold. The other as part of a more full-featured sensor package that will communicate readings serially. This go is mostly to work out the remaining kinks in the altitude side of things (most kinks remaining are in code).
Be diligent and then just consider that another PCB spin might be required. There is nothing shameful about that.Good thing too, as I'm sure I'll be taking plenty of "spins"! ;)
Luke
Mr.RC-CAM
Mar 11, 2006, 05:38 PM
As you might recall, the method used to accomplish these things is to dynamically scale the input into the diff-amp (Bill had this idea). The PIC creates a variable voltage that "follows" the voltage of the sensor, and both these voltages go into a diff-amp.That is a not an unusual way to do this sort of thing. I've been there too. I created an altimeter about four years ago that used a 10-bit A/D. It actually offered 0.5 foot step resolution using the dynamic scaling trickery. On a technical level, it worked great. I had employed some Dallas Digital Pots for the scaling and offset amps. I thought I was being clever by using them since they eliminated any PWM noise I might have experience using PIC DAC emulation. But, (que violin music) I found that their temperature stability was a big problem and caused substantial drift during use. There is a solution to this, but I got sidetracked and have yet to update the design. Frankly, if I was to do it all over, I would use the INTERSEMA barometric sensor, which resolves a big pile of problems. Too bad it is a hard part to buy.
JimDrew
Mar 12, 2006, 10:45 AM
What PIC part are you using? As a developer for Microchip, I would like to report this problem.
Mr.RC-CAM
Mar 12, 2006, 01:09 PM
What PIC part are you using? As a developer for Microchip, I would like to report this problem.If you are pointing your question at me (?):It is not a PIC problem. It's the digital pots.
To make it clear, I used digital pots so that I did not have to employ PIC DAC emulation (via PWM). I ended up with extremely low noise analog circuitry, but suffered the temp drift from the resistor array inside the digital pots. The drift can be eliminated if constant current bias is used.
BTW, reporting silicon related problems to Microchip has never helped me. Their tech support is world class for common issues, but beyond that I just don't have any real hope that they would do much about odd problems. Just my experience.
LukeZ
Mar 12, 2006, 03:52 PM
What PIC part are you using? As a developer for Microchip, I would like to report this problem. And if you are asking the question of me, the PIC I've been using is an 18F452, 40-pin DIP package. What I see is when one pin turns on an LED, it causes voltage on the PWM pin to drop.
My LED draws about 6mAh. The PWM voltage drop is about 1.5 mv. The drop is small but in this applicaiton it is noticeable.
I'm going to switch to the 28 pin 18F2620 as soon as my new programmer comes in, so I suppose I can test it to see if it's any different.
There still could be something I'm doing wrong, that leads me to this conclusion. I'm not much more than a novice at this stuff. All the same, even if I am correctly diagnosing the problem, the fix is easy - watch what I'm doing with the pins when I need a stable PWM.
Luke
LukeZ
Mar 12, 2006, 04:09 PM
Hey, can't believe I didn't think to try this before -
Previously my PIC has been set to source the current for my LED. I just now swapped it so that the PIC sinks the LED - in other words, to turn the LED on, it puts the pin to ground (the other side of the LED is now hooked to V+). What do you know, but no noticeable effect on the PWM voltage when I do it this way. I can turn the led on and off all day and it remains pretty steady. My Fluke can actually still pick up some fluctuation on the PWM but it's not enough to show up on the other side of the A/D.
Was probably something about this in the PIC data sheet, had I read it closer...
Luke
JimDrew
Mar 16, 2006, 10:18 PM
I am not aware of any problems sourcing a voltage. I will drop a note to engineers about this. I do know that the 16F818/819, 16F628, 16F873/4/6, 16F684 do not have this problem for sure. We use PWM in many, many applications and have LED's sourcing 20ma of current with no variation in the PWM voltage. Maybe this is something related to the 18F family.
LukeZ
Mar 17, 2006, 02:10 AM
Alright, after much fighting with Eagle, I have a board and schematic for an altitude hold circuit. Eagle is actually pretty good (especially for being free), but I had to make several packages and it took me a while to figure things out.
Anyhow, a description of the circuit:
Board
- On the analog side I've implemented what has been discussed at great length here. The schematic looks pretty much like what Bill last posted. A PWM signal from the PIC is passed through a comparator, to help with any voltage drop issues. From there it is converted to a DC signal. These two functions take place in op-amp1 (dual package). This DC signal is then fed into one side of a diff-amp, along with the voltage from the altitude sensor. This is op-amp2. Output from the diff-amp goes to the A/D, a 12 bit unit that communicates via SPI with the PIC.
- On the digital side we have the processor and a few other small things. There are five headers on the board, which serve these following functions:
1. RS232 - this is the four-pin header at the top.
2. On/Off command from RC receiver - plug this into a channel on the receiver for on/off control of the circuit.
3. Elevator channel from RX - this is the elevator signal from the RX.
4. Elevator servo - this controls the elevator servo.
5. Jumper - used to set servo travel direction
- Additionally there is a pot for servo gain adjustment, a DS18S20 for on-board temp (used to compensate temperature drift on the op-amps and other components), and an indicator LED.
- Power comes into the board on the lower left-hand side. There are two LDOs, one each for the digital and analog side, for noise considerations.
Operation
Pretty self-explanatory. The unit takes the elevator signal from the RX. While in "off" mode, it simply passes this signal on to the elevator servo (so it's not truly off). When turned "on" by the spare RC channel, it first takes a pressure reading. This reading is what it will then try to adhere to. If pressure drops, dive the airplane. Pressure increases, climb.
If the user wants to hold a different altitude, they will need to turn "off" the unit, manually position the aircraft at the new required altitude, and then turn it back on.
The PIC will have a bootloader installed before soldering to the board. After that all upates are through the serial port (the user will need to use an external MAX232 circuit). Having serial would also allow telemetry to be sent to the ground through RF modem, and/or other embelishments. Particularly I suppose if the user wanted to set a predetermined altitude on the ground, he could do so through the serial port and some small utility that I could write for the PC. Alternatively I suppose it could be coded to accept input from GPS waypoints and attempt to hold the altitudes specified there. In that manner I suspect it may work with the RCAP2 if one had a Y-cable from the GPS unit.
What I Could Use
I'm not the board designer guru by any means. Any thoughts or observations about the board in particular would be useful. As for coding ideas, I appreciate those as well, but I can do that whenever: first I'd like to have a circuit to work with rather than the mess on my breadboard.
One will note that I've attempted to use ground planes on the bottom layer. These are seperated into digital and analog planes. They will actually connect at the point indicated in the picture. I just couldn't get Eagle to do it since I named the two planes something different. That is also why there is still an "airwire" present. But that's easily fixed in real life (not so on the computer...)
In a lot of pictures of PCBs that I've been looking at, it seems to me that people also put "planes" on the top layer, but I can't figure out if these areas of copper are also connected to ground, or if to positive (in that case I'd think we'd be creating a massive capacitor, but what do I know...). Should I extend the ground plane to the empty areas on the top layer as well?
I will say also that my traces don't look very straight. This isn't a flaw in Eagle, I'm probably just taking too literally some advice I read somewhere that electrical signals don't like sharp turns...
I think I did a pretty good side of keeping things as clean as possible on the analog side. Also you can see that the positive supply rail isn't daisy-chained (thanks Mr. RC-Cam), but I tried to use the "trunk-and-branch" approach to distributing power. But who knows how well I succeeded.
Anyways, any and all suggestions are more than welcome!
Luke
vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.