readadc10 is not linear, whats the formula ?

Screech

Member
I was testing the readadc10 command and I find it is not a linear scale, especialy at very low voltages.
The scales seems to be parabolic. Curvey at lower voltages then straightens up.


Heres how I tested it.
win 98se
Picaxe programmer 4.1.10
Download cable not connected.
Enhanced interface circuit not used.
Constant 4.8 volt supply during test.

'PROGRAM
loop:
readadc10 2,w1 'the voltage to input 2 is also monitored be a multimeter.
w2=w1*10
pulsout 1,w2 ' sends a pulse to output 1 wich is then measured by a pulse width meter.
pause 500
goto loop


The ratio of voltage going into the chip and the pulses coming out are not same.

I replaced the chip with another chip and got the same results.

Is there a formula for determining the correct adc10 values?

Thanks.
 

premelec

Senior Member
the usual problem at low values is noise and offsets. You might check for offset - take data and see if it straightens with an offset value. Also what is your source impedance to the READAC pin? Try putting a capacitor from that pin to battery negative -
Is you PULSOUT pulling the supply down at all etc....
 

BeanieBots

Moderator
The adc IS linear. As suggested by premelec, it is probably your source impedance that is causing the affect and/or your supply voltage which is also used as the adc reference. Unless your PICAXE is supplied via a good constant voltage from something like a regulator (not directly from batteries), you cannot measure voltage accurately.
 

Screech

Member
i used a 5k pot as a voltage divider from the source voltage to the readadc pin.
I also trieda 500k pot as a voltage divider too.

Don't know what you meen by offset and source impediance?

The output is going to a 10k resistor and then to an 2n2222 npn tranistor, wich turns on a timing divice, (a personal computer)powered from it's own voltage source.

I'll try a voltage reg. next time too, even tho the source voltage did not seem to be effected by the pots, and the multimeter.
I do the next test tommorow, with that capacitor too.

Thanks



Edited by - screech on 9/22/2005 8:29:18 AM
 

BeanieBots

Moderator
The 500k pot will not give predictable results when connected to a PICAXE input.
The 5k pot should be fine.

Source impedance is the resistance that the input 'sees' in series between the voltage you are trying to measure and the PICAXE input.
For example, if you connected a battery directly to the input, it would see the voltage of the battery in series with the battery's internal resistance. The internal resistance of the battery is normally very low. Probably about 1 ohm. If you put a resistor in series between the battery and the PICAXE, say 10k ohm, it would see the sum of the resitances (10,000 + 1). The input would now have a "source impedance of 10k + 1 ohms.
When you use a pot, it is a little bit more complicated because there are effectively two resistors involved. The PICAXE is only worried when the source impedance is high so let's only worry about when the pot is at its maximum impedance.
(sorry, let me explain impedance and resistance. in a DC circuit, impedance and resistance are the same thing. Capacitors and inductors change their resistance with different frequencies so you cannot specify their resistance without also specifiying the frequency. Impedance is a term used to indicate the complete set of resistances that includes all parts of a circuit including capacitors inductors and frequency).
Back to the pot.
A pot is at maximum resistance when it is at mid position. The value is 1/2 of total track resistance. So for your 5k pot, the maximum resistance will be 2k5. This is the highest value that you should use for a PICAXE input. (in practice you can use higher values up to about 20k but using a 500k pot (250k source impedance) would be too high.
Fitting a capacitor will help to eliminate any noise that may be present. It will not reduce the "DC resistance" but it will reduce the "AC impedance".

Sorry I'm not very good at explaining this but it is quite a complex subject and does require some prior knowledge and understanding. In particular ohms law. It's a bit like building a box out of wood. Very easy to do but as you start to make bigger and bigger boxes, suddenly, unexpected things start to happen such as the sides begin to bow and the top falls in. It's the same as "source impedance" gets bigger. Strange things start to happen such as non linear response just like the sides of a very large box begin to bow even though the wood used was perfectly straight.
 

Screech

Member
New tests make no difference.

I used a 12v battery supply.
I used a 5 volt voltage reg with it's cap.
I tested with a 5k pot, 50kpot and 500k pot.
Even tried a few capacitors as you mentioned on the input.

I changed the only output resistor from 10k to 100k.


B U T, They made no difference.

I still get a non linear ratio at very small adc10 values (0-30).
The error can be out by 300 percent!

All values above them seem to be linear.

My pulse meter(pc) was calibrated too.

???


Edited by - screech on 9/22/2005 9:13:21 AM
 

ylp88

Senior Member
<i>A pot is at maximum resistance when it is at mid position. The value is 1/2 of total track resistance. So for your 5k pot, the maximum resistance will be 2k5. </i>

Could you please elaborate, Beanie?

ylp88

Edited by - ylp88 on 9/22/2005 10:00:01 AM
 

ylp88

Senior Member
How have you setup your divider? Have you got either end of the pot connected to your rails and then the wiper connected to the ADC pin?

ylp88
 

BeanieBots

Moderator
ylp88, yes, I agree, that quote is mileading if taken out of context. I am refering to the source impedance seen by the PICAXE input when the pot ends are across the power rails and the wiper is connected to the PICAXE input with the pot at mid position. In this configuration it is a potential divider that gives V/2. The source impedance is pot resistance/2. ie it is equivalent to a voltage source of half power rail in series with 2k5.

Edited by - beaniebots on 9/22/2005 10:09:30 AM
 

BeanieBots

Moderator
Screech. I think the next thing to do it to eliminate parts that may be contributing.
Use debug or similar to display the value returned by the adc for each voltage. This will mean running with the download circuit connected so you MUST use the enhanced download circuit. Alternatively, send out the data on another pin and use hyperterminal or similar.
Failing that, hardcode pulsout values and check that you measure what is expected for each value in the lower range.
 

Technical

Technical Support
Staff member
No one has yet mentioned you can also buy log (not linear) scale potentiometers - this could be a likely cause of your issues...
 

premelec

Senior Member
Screech said he is monitoring the input voltage to the ADC pin with a multimeter - who's to say the multimeter doesn't have errors at this low level?.... Many lower grade multimeters have =/- % of FULL SCALE
errors +/- 1 digit.... perhaps that's the problem. A way around that is with a precision voltage divider and measure the voltage at the higher level before the voltage divider divides it by 10 or 100 or whatever.
 

BeanieBots

Moderator
And don't forget loading effects of a cheap DMM. I've seen some as low as 10k. Even a good 10M one will have a significant effect on the voltage output of a 500k pot. (1.00v on a 500k pot wiper at mid position would read as 0.97v on a perfectly calibrated 10M input DMM).
However, this would still be the voltage as seen by the PICAXE and would not explain the effect seen unless it was assumed that the voltage remained the same after the meter was removed.
Very little has been said about the measuring tools except that the &quot;pulse meter (PC) is calibrated&quot;.
This could also easily be the problem. We are talking about 10uS resolution at these levels. Unless the correct type of cable (matched impedance coax) is used for anything except a very short distance, the pulses will have sloppy edges and may well appear to be shorter than they really are.
The only way forward here is to break down each part rather than measure input and output. The pulse issue is the easiest to eliminate with some very simple hard coding of known pulse widths and see what is measured.
(what's the tollerance on a resonator? 5%?)
 

Screech

Member
LISTEN UP GUYS!

All tests were performed on the schools experimentel super kit.


The 100 nf capacitor that is required next to the picaxe in NOT large enough when reading low adc10 vales.

Adding an EXTRA 100nf made the lower values JUMP up to where they sould almost be (300% higher)(it's not a precision instrument).


I dont understand why.It's not like it's neads an extra decoupling capacitor. It didn't mater if one of the outputs LEDs were switched on or off either. The only output that was allways on was pin2(leg 5?) thru a 100k resistor.

Another thing that I found out from a microchip 12f683 datasheet is that the adc inputs impedience can be no more then 10k.

When I used more then 10k , the adc values would wander slightly up and down, because..
..there is an internal 160pf capacitor inside the chip that has to allways be charged up. It cannot be charged up in time if highr then 10k resistence is used on the adc input.

Now I just nead a picaxe that can read adc values thru a 200k or highr voltage divider network.

Thanks for you help guys.



Edited by - screech on 9/23/2005 7:40:51 AM
 

BeanieBots

Moderator
Glad you found the problem and VERY glad that you pointed out the bit about the source impedance must not be greater than 10k. (2k5 on some PICs). I've been banging that out on this forum for ages and people still keep using high impedances.
If you really must have a source that is 200k, you will need to buffer it with an op-amp or similar or live with inconsistant non-linear results.
 

Screech

Member
BeanieBots, the microchip data sheets states Maximun 10k impedience on the input.

Q1. Is that the same as using a maximum of a 10k pot as a volatge divider?

BeanieBots said &quot;If you really must have a source that is 200k, you will need to buffer it with an op-amp or similar or live with inconsistant non-linear results.&quot;

I know nothing about amps.
but are you saying i can use the voltage from the 200k voltage divider, and feed it into an op-amp? will the op-amp output the same input voltage but with more current?

Edited by - screech on 9/23/2005 7:53:42 AM
 

ylp88

Senior Member
I suppose that you have to setup the opamp in a unity gain configuration.

Connect the output of an opamp to its inverting input and connect the non-inverting input to your source. Connect the output of the opamp to the PICAXE pin (perhaps via a 100R resistor).

ylp88
 

BeanieBots

Moderator
I explained about the output impedance of a pot earlier in this thread. The source impedance of a pot when used between a low impedance source and 0v is dependant on its wiper posistion. The impedance is at its maximum when the wiper is at mid position. The actual impedance at that position is the pot track impedance divided by two.
So, to never exceed 10k impedance, your pot must not be greater than 20k.
The general formula for the impedance of a potential divider made up from Ra and Rb is given by:-
Impedance = Ra*Rb/(Ra+Rb).
This is at a maximum when Ra=Rb.

As for op-amps, that is not a simple answer.
It would be fairly simple to 'configure' one to give out the same voltage as its input but at a very much lower impedance.
In real terms that is the same as saying &quot;at higher current&quot; but to be technically correct it means that the voltage will not drop as much for the same current.
The drawback with op-amps is that require dual power rails (a positive and a negative supply). You can get &quot;single rail&quot; op-amps but I have yet to find one that really does work well when its output needs to be 0v and there is no negative rail.
 

Screech

Member
Thanks for all your help guys.
I will get an op-amp tomorrow,
and wire it up as suggested to form a voltage follower.

Thanks again :)


 

BeanieBots

Moderator
If you only have a positive supply, may I suggest using the ICL7660S charge pump to generate the negative rail. They only cost about 1GBP and are readily available. There are thousands of different op-amps available but the LM324 is a good all rounder and is supplied by Rev-Ed. (you also get four of them in one 14 pin package).
 

ylp88

Senior Member
If the voltage being measured is always positive, isn't it possible to just provide a single rail power supply? Alike clipping, the amp will only clip if the output exceeds the rails (assuming R-R output). If the follower only outputs a positive voltage, then the rails only need be positive, right? Can anyone confirm or dispute this?

ylp88

Edited by - ylp88 on 9/23/2005 12:31:57 PM
 

hippy

Ex-Staff (retired)
The problem being resolved by adding an extra decoupling capacitor indicates to me that there may be an issue with the power supply.

The decoupling capacitors also works as very small reservoir capacitors holding up the supply voltage when strain is put on it, but only for a very short time. When taking an analogue reading, this may cause the supply to drop slightly and have all sorts of consequences and quite likely as has been observed here. Adding another capacitor has perhaps given just enough extra to stop the supply collapsing, so it now all works.

I note earlier with regards to your power supply, you said; &quot;I used a 5 volt voltage reg with it's cap&quot;. That infers you only have one capacitor in the regulator circuit. Normally there should be three; a large(ish) reservoir cap before the regulator, plus two 100nF or appropriate caps between the regulator input and 0V and between the regulator output and 0V, both as close to the regulator as possible.

There should also, ideally, be a diode from the regulator output to the regulator input to handle cases where the regulator input voltage drops ( as at power-off ), and the cicruit supply voltage ( through capacitance etc ) is higher than the regulator input voltage.

It is often quite possible to get away with using a 'thrown together' regulator circuit which doesn't include all that ought to be there, but when dealing with very low voltages or needing very stable ones it is necessary to have a very well designed power supply. Many regulator circuits will have additional filtering and smoothing included. Also, note that not all regulators are equal; some are 'cheap and cheerful' while others will have much better characteristics.
 

BeanieBots

Moderator
Again the answer is not simple and varies between op-amp types. Sometimes, the internal workings of the op-amp REQUIRE a negative rail irrespective of what your inputs or outputs require. The LM324 is described as &quot;single rail&quot;. However, when the output is required to be 0v, it will get very close but cannot actually pull a load right down to exactly 0v. Just in the same way you not expect an amplifier's output to go all the way up to its power rail, (there is always some inefficiency/loss), equally, it cannot go all the way down to 0v. How bad the effect is depends largely on what it is driving. It may well be good enough if it is only driving a PICAXE input. A load of say 1k could easily leave it short by a whole volt. Simple answer, try it and see.
 

BeanieBots

Moderator
My last post crossed with Hippy's. How I'm not sure, looking at the posting times.
Anyway, the response was aimed at ylp88's questions.
Hippy is of course spot on about the decoupling cap issue which I'd dismissed by getting hung up over input impedance. When small signals are involved and accuracy is required, EVERYTHING is important. Even subtle things such as where on the 0v rail each chip is connected can have a major impact on the final result.
 

hippy

Ex-Staff (retired)
To continue with the &quot;subtle things&quot; theme, even floating inputs which pick up 'radio signals' can switch which cause a change in current draw which can affect supply voltage, and those signals may also be appearing to some extent on all other inputs and the power lines ( and 0V ) themselves. What's done between one reading and taking the next may have an effect, turning a LED on or off may cause a momentary change in supply voltage.

Edited by - hippy on 9/23/2005 4:13:13 PM
 

premelec

Senior Member
A popular topic, metrology! In regard to OP amps - Check input common mode voltage range allowed and output swing. LM324s are cheap but have limitations [e.g. output swing limited to below supply by quite a bit]. Rail to Rail is the name given to OP amps which can handle inputs and outputs over full rail to rail voltage.

Screech... you are learning, as are all of us, that there are a variety of subtlties to this work and the data sheets need to be read and understood! good luck. [I've been at it 55 years and still don't know enough!]
 

ylp88

Senior Member
I acknowledged rail to rail output (actually, R-R output, but my computer has the &quot;R-R&quot; split across two lines) but these are often more expensive than other opamps, especially because these opamps usually also have a very high slew rate, high frequency response and precision amplification.

Nevertheless, I have seen some &quot;Virtual ground&quot; power supplies which can be used to create a negative rail from a single supply. This should allow you to use the nice and cheap (but still as effective) 324s and 358s. It was somewhere is a <i>Silicon Chip </i> magazine but I am still yet to find which one it was.

ylp88
 

hippy

Ex-Staff (retired)
If the PICAXE has PWM commands then that could be used to create the negative voltage using a charge pump ( and perhaps a 555 timer could be used ) ...

http://www.piclist.com/techref/microchip/pwmvee.htm

http://www.elecdesign.com/Files/29/6221/Figure_01.gif

Here's a clever solution for -0.5V I'd never have thought of ....

http://www.discovercircuits.com/PDF-FILES/NewPDF/negsupply2.pdf
 

mattrich

New Member
Are you using an LINEAR POT or a LOGARITHMIC POT - this could be your problem????
 
Last edited by a moderator:

Screech

Member
picmatt, my pots are Linear.

I be using a 7660 chip to create the -5volts to supply the negative to the op-amp.
This chip takes a positive input and produces a negative output. It's designed to be used for op-amps.
I've been told buy an expert the op-amp to use is a TL072 JFET.

Still got to order that 7660 voltage converter (charge pump converter).

Edited by - screech on 9/24/2005 11:02:29 AM
 
Top