Author Topic: PIC ADC wrong value  (Read 3851 times)

0 Members and 1 Guest are viewing this topic.

Offline raphaeldavidfTopic starter

  • Contributor
  • Posts: 35
PIC ADC wrong value
« on: August 10, 2015, 10:43:04 pm »
Hi guys,

I'm having a little trouble with the adc in my pic16f676. I'm trying to read the voltage of a li-on battery and it kinda works: when the battery has no load everything is right and I get the right value, but when I plug a load in the battery the number is of by quite a bit. I'm also measuring the battery current with a resistor, using the ADC, and it works ok. At first I thought  that the problem was the wires and jumper cables connecting everything, so I measured the resistance of all the cables and tried to compensate via software, using the current.

Here it is an example of my reading, with the compensation:
(MULTIMETER / PIC ADC)
3.59V  / 3.3V
3.59V  / 3.4V

Thanks a lot! ;)





 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Re: PIC ADC wrong value
« Reply #1 on: August 10, 2015, 11:04:11 pm »
Could you sketch-out a diagram of how the appropriate parts - it would make it easier to understand what is happening.
 

Offline Maxlor

  • Frequent Contributor
  • **
  • Posts: 565
  • Country: ch
Re: PIC ADC wrong value
« Reply #2 on: August 10, 2015, 11:04:18 pm »
A schematic of your circuit would help.
 

Offline raphaeldavidfTopic starter

  • Contributor
  • Posts: 35
Re: PIC ADC wrong value
« Reply #3 on: August 11, 2015, 12:01:05 am »
Could you sketch-out a diagram of how the appropriate parts - it would make it easier to understand what is happening.

A schematic of your circuit would help.

Sorry the poor schematic, made in a hurry ;D

The pic in the schematic is wrong, the right one is the pic16f676, but the number of pins is right.

Pins 12 and 13: ADC
Pin 11: turn transistor on
sense resistor: 1ohm

thanks to you both for the help   ;D
 

Offline tomlut

  • Regular Contributor
  • *
  • Posts: 57
  • Country: au
Re: PIC ADC wrong value
« Reply #4 on: August 11, 2015, 01:14:17 am »
Are you waiting the required settling time after selecting the ADC input? A small amount of time is required for the sampling capacitor to charge. You have a nice low impedance connection to the battery so it shouldn't take very long. Check the data sheet for the calculation (section 7.2).

Are you using the battery for your Vcc supply? Is Vcc used as your ADC reference? Is it sagging under load?

Also moving the load to the high side (collector) will ensure the transistor can turn on fully. Not required if your Vcc is 5v, but if it is 3.3v you might not be in the CE saturation region.
« Last Edit: August 11, 2015, 01:18:36 am by tomlut »
No I won't fix your TV for a carton of beer.
 

Offline raphaeldavidfTopic starter

  • Contributor
  • Posts: 35
Re: PIC ADC wrong value
« Reply #5 on: August 11, 2015, 01:27:06 am »
Hey tomlut, thanks for the tips ;D


Are you waiting the required settling time after selecting the ADC input? A small amount of time is required for the sampling capacitor to charge. You have a nice low impedance connection to the battery so it shouldn't take very long. Check the data sheet for the calculation (section 7.2).

I'm waiting 1us, and 1us for channel changing. I'll try increasing the time to see if it makes any difference.

Are you using the battery for your Vcc supply? Is Vcc used as your ADC reference? Is it sagging under load?
I'm using a power supply(5V), and the Vcc is the ADC ref. I didn't quite get what did u mean by sagging. Is it about the battery voltage drop when the transistor turn on?

Also moving the load to the high side (collector) will ensure the transistor can turn on fully. Not required if your Vcc is 5v, but if it is 3.3v you might not be in the CE saturation region.
My Vcc is 5V
 

Offline tomlut

  • Regular Contributor
  • *
  • Posts: 57
  • Country: au
Re: PIC ADC wrong value
« Reply #6 on: August 11, 2015, 01:37:05 am »
Yes by sagging I meant the drop in battery voltage under load.

Your readings will only be as accurate as your ADC reference. If the reference (Vcc) is changing as you switch the load you may get strange readings. Monitor the Vcc rail with an oscilloscope to make sure it's nice and stable. As you are not using the battery for your Vcc this is probably not the problem but worth checking.

Also disregard the my other point about moving the load. 5v will switch it nicely.

No I won't fix your TV for a carton of beer.
 

Offline raphaeldavidfTopic starter

  • Contributor
  • Posts: 35
Re: PIC ADC wrong value
« Reply #7 on: August 11, 2015, 06:44:25 am »
Yes by sagging I meant the drop in battery voltage under load.

Your readings will only be as accurate as your ADC reference. If the reference (Vcc) is changing as you switch the load you may get strange readings. Monitor the Vcc rail with an oscilloscope to make sure it's nice and stable. As you are not using the battery for your Vcc this is probably not the problem but worth checking.

Also disregard the my other point about moving the load. 5v will switch it nicely.

Checked the Vcc and it is pretty stable.

I think I know the problem now: bad connection with the battery + resistance of the wires. Solved the problem by using a neodymium magnet to ensure a strong connection and used a software calibration to compensate. Now the error is low enough.

The software calibration used is a linear equation, and i got the parameters by subtracting the value measured by the ADC from the value from my multimeter, then plot the Voltage(Vadc - Vmultimeter) vs current graph, and traced the linear trend.

Thank you tomlut for all the help and tips ;D
 
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf