Author Topic: Voltage Divider non Linear issues  (Read 11763 times)

0 Members and 1 Guest are viewing this topic.

Offline richcj10Topic starter

  • Supporter
  • ****
  • Posts: 202
  • Country: us
Voltage Divider non Linear issues
« on: March 24, 2013, 06:47:41 pm »
Hi,

I have a PIC18LF46K22 and a voltage divider and when I use this piece of code:
Code: [Select]

  result =  ((ADC_Get_Sample(1) / 1024.0) * 3.3 )/ 0.3197278911564626


I have a good return value at love voltages (EX: 4.2V I get 4.2) but not at high voltages (EX: 8V I get 6.1V).
This is a battery powered device so I need as low power as I can get. Attached is the Circuit.  Any Ideas?
 

alm

  • Guest
Re: Voltage Divider non Linear issues
« Reply #1 on: March 24, 2013, 06:54:04 pm »
6.1 V * 0.3197278911564626 = 1.95V. My psychic debugging skills tell me that you use the internal voltage reference that is set to 2.048 V. Either use Vdd for reference (less accurate that the internal reference, especially if directly powered from battery) or change the division ratio so the voltage to the ADC input remains below 2 V for the input range you care about.
 

Offline richcj10Topic starter

  • Supporter
  • ****
  • Posts: 202
  • Country: us
Re: Voltage Divider non Linear issues
« Reply #2 on: March 24, 2013, 07:01:26 pm »
I was using a library provided for a compiler. I just noticed the note:
Quote

  Note : This function doesn't work with the external voltage reference source, only with the internal voltage reference.


I will try again....

Thanks,

Rick
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: Voltage Divider non Linear issues
« Reply #3 on: March 24, 2013, 08:08:41 pm »
6.1 V * 0.3197278911564626 = 1.95V. My psychic debugging skills tell me that you use the internal voltage reference that is set to 2.048 V.

The calculation requires a 3.3v reference (presumably VDD) and correct results at lower voltages indicate that is what is being used.

Assuming my psychic interpretation of the grotty fragment of schematic is correct the problem is the soggy 3v zener across the divider.

If you want to save a little battery don't use 3 floating point calculations to measure it while 1 and preferably none will do.
 

Offline richcj10Topic starter

  • Supporter
  • ****
  • Posts: 202
  • Country: us
Re: Voltage Divider non Linear issues
« Reply #4 on: March 24, 2013, 08:42:00 pm »
I think if I change R42 to 6K and R30 to 1.4K I will get under the 2v and 1.3mA
The Zener don't affect anything.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: Voltage Divider non Linear issues
« Reply #5 on: March 24, 2013, 08:46:08 pm »
If you want to save a little battery don't use 3 floating point calculations to measure it while 1 and preferably none will do.

I was just going to say this. Try changing your code so there's no floating point stuff in it and see how much smaller it magically becomes.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline richcj10Topic starter

  • Supporter
  • ****
  • Posts: 202
  • Country: us
Re: Voltage Divider non Linear issues
« Reply #6 on: March 24, 2013, 08:48:50 pm »
If you want to save a little battery don't use 3 floating point calculations to measure it while 1 and preferably none will do.

I was just going to say this. Try changing your code so there's no floating point stuff in it and see how much smaller it magically becomes.

I agree. I am prototyping the code so it is easy to change a value. I will optimize when it is time to be done. 
 

Offline richcj10Topic starter

  • Supporter
  • ****
  • Posts: 202
  • Country: us
Re: Voltage Divider non Linear issues
« Reply #7 on: March 26, 2013, 04:51:28 am »
Updated code:

Code: [Select]

sub function vinread() as float
'  Soft_UART_Write("V")
'  Soft_UART_Write("I")
'  Soft_UART_Write(10)
'  Soft_UART_Write(13)
  bc1v = bc2v
  bc2v = bc3v
  bc3v = bc4v
  bc4v = bc5v
  bc5v = bc6v
  bc6v = bc7v
  bc7v = bc8v
  bc8v = ADC_Get_Sample(0)
  vinavg = (bc1v+bc2v+bc3v+bc4v+bc5v+bc6v+bc7v+bc8v)/8
  result = ((vinavg / 1024.0) * 2.048 )/ 0.2108922363847045
end sub


I changed the Resistors to 6.81k (R1) and 1.82k (R2).
I am still getting really bad non-linear issues.
Any ideas?

thanks,

Rick
 

alm

  • Guest
Re: Voltage Divider non Linear issues
« Reply #8 on: March 26, 2013, 08:45:30 am »
If you measure the voltage at the ADC input pin, is it what you expect? What is the actual value of bc8v you get from the ADC?
 

Offline amspire

  • Super Contributor
  • ***
  • Posts: 3810
  • Country: au
Re: Voltage Divider non Linear issues
« Reply #9 on: March 26, 2013, 09:50:23 am »
Have you tried removing the capacitor and zener?

If the capacitor is reversed, it will have leakage that might increase with voltage.

If the zener is the wrong value, or if it has a big voltage drop below 1mA (low voltage zeners have soft limiting curves), it can cause non-linearity.
 

Offline richcj10Topic starter

  • Supporter
  • ****
  • Posts: 202
  • Country: us
Re: Voltage Divider non Linear issues
« Reply #10 on: March 30, 2013, 11:57:18 pm »
I just tested it w/o the cap and zener, no affect. WTF?
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2958
  • Country: au
Re: Voltage Divider non Linear issues
« Reply #11 on: March 31, 2013, 12:35:57 am »
Did you measure the voltage at the actual micro pin as asked?  This may shed light on what is happening.
 

Offline richcj10Topic starter

  • Supporter
  • ****
  • Posts: 202
  • Country: us
Re: Voltage Divider non Linear issues
« Reply #12 on: March 31, 2013, 12:43:23 am »
at 8v in i get 1.69v. This seams right.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 30350
  • Country: nl
    • NCT Developments
Re: Voltage Divider non Linear issues
« Reply #13 on: March 31, 2013, 12:50:43 am »
The zener will have too much leakage in these sort of constructions. Better use a MOV or TVS at the circuit's input (with a small series resistor). Besides that you'll probably need a >1nf capacitor at the uC's input pin to supply the current drawn by the sample & hold inside the uC. Without the capacitor you can probably see the sampling pulses with a scope .
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline poorchava

  • Super Contributor
  • ***
  • Posts: 1673
  • Country: pl
  • Troll Cave Electronics!
Re: Voltage Divider non Linear issues
« Reply #14 on: March 31, 2013, 12:51:28 am »
Look at datasheet for the microcontroller, page 464. Total ADC error is +\- 3LSB. It's kind of less shitty than other Microchip MCUs can be, but still shitty.
I love the smell of FR4 in the morning!
 

Offline richcj10Topic starter

  • Supporter
  • ****
  • Posts: 202
  • Country: us
Re: Voltage Divider non Linear issues
« Reply #15 on: March 31, 2013, 02:52:27 am »
The zener will have too much leakage in these sort of constructions. Better use a MOV or TVS at the circuit's input (with a small series resistor). Besides that you'll probably need a >1nf capacitor at the uC's input pin to supply the current drawn by the sample & hold inside the uC. Without the capacitor you can probably see the sampling pulses with a scope .

zener has been removed. It at this moment not affecting any mesurments taken
« Last Edit: March 31, 2013, 02:57:31 am by richcj10 »
 

Offline VanitarNordic

  • Frequent Contributor
  • **
  • Posts: 283
  • Country: 00
Re: Voltage Divider non Linear issues
« Reply #16 on: March 31, 2013, 07:37:42 am »
You have to make one linear equation between input voltage and ADC. I put multi-turn potentiometer to adjust and acquire the value. You may use the Zener just to protect the PIN.
 

Offline Bloch

  • Supporter
  • ****
  • Posts: 456
  • Country: dk
Re: Voltage Divider non Linear issues
« Reply #17 on: March 31, 2013, 08:13:48 am »
Try look up the input impedance in the pic.


if it is like Pic12f675 then that can be a problem for the divider.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 30350
  • Country: nl
    • NCT Developments
Re: Voltage Divider non Linear issues
« Reply #18 on: March 31, 2013, 02:21:54 pm »
You have to make one linear equation between input voltage and ADC. I put multi-turn potentiometer to adjust and acquire the value. You may use the Zener just to protect the PIN.
This a bad idea. A generic zener has a leakage current of several hundred uA and needs close to 1mA to reach its zener voltage. Do the math with these currents to get the divider accurate within 1%.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline codeboy2k

  • Super Contributor
  • ***
  • Posts: 1836
  • Country: ca
Re: Voltage Divider non Linear issues
« Reply #19 on: March 31, 2013, 03:26:24 pm »
most ADC's have a relatively low input impedance, and draw non-negligible current when charging the S-H cap.  This charging current may be too much for your divider, and it droops, so you read low. 

Usually you need to buffer any input to an ADC, for this exact reason.  You should find a spare op-amp in your design, or add one in, and simply buffer the ADC input with an op-amp voltage follower.

If you use a 3.3V op-amp and tune the divider to keep your max voltage around 2V, then you can use the internal reference and don't need a 3.3V zener anymore at the ADC input, which is a bad idea anyways due to the leakage currents.

 

Offline richcj10Topic starter

  • Supporter
  • ****
  • Posts: 202
  • Country: us
Re: Voltage Divider non Linear issues
« Reply #20 on: March 31, 2013, 05:15:01 pm »
Let me scope it out and see what is happening.
I use voltage dividers with AVR's all the time w/o issue. Go figure....
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 30350
  • Country: nl
    • NCT Developments
Re: Voltage Divider non Linear issues
« Reply #21 on: April 01, 2013, 02:41:57 pm »
Microchip's A/D D/A chips are pretty crappy compared to the competition so its no surprise.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2958
  • Country: au
Re: Voltage Divider non Linear issues
« Reply #22 on: April 01, 2013, 08:50:47 pm »
If the voltage at the micro pin is correct (scaled), then the code must be bad.  Could it be that you're only using the lower 8 bits of the result?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->