Author Topic: Reading ADC when the VDD is not fixed  (Read 4582 times)

0 Members and 3 Guests are viewing this topic.

Offline arslan43711Topic starter

  • Contributor
  • Posts: 19
  • Country: pk
Reading ADC when the VDD is not fixed
« on: October 30, 2020, 05:55:55 am »
Hi, Hopefully you are doing good.

I am working on a project in which I have to measure the battery voltage(fully charged 5V and discharged voltage are 2.5V), I am using pic16f688. I have connected the battery pin to one of the analog pin. So ADC read 1023 all the time whatever the voltage is. I mean when the VDD is 3.3v it gives 1023 and when it 5v it gives 1023.  I know there is no fixed voltage reference in the pic16f688.

Is there any solution to this? or a way with which I can measure the battery voltage while the PIC is connected to the same battery.
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3485
  • Country: it
Re: Reading ADC when the VDD is not fixed
« Reply #1 on: October 30, 2020, 07:21:23 am »
Then you need an external voltage reference, measure it  and find out the value of VDD
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1659
  • Country: nl
Re: Reading ADC when the VDD is not fixed
« Reply #2 on: October 30, 2020, 08:10:37 am »
Connect VDD through a resistor to a TLV431 placed backwards as reference. Then measure this reference voltage with your VDD. Something like:


Then a lower ADC code indicates a higher supply voltage. You would need to see how you'd want to do the math on that PIC processor, or perhaps calculate the 8-bit ADC thresholds manually on which a certain low-battery situation is warranted.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Reading ADC when the VDD is not fixed
« Reply #3 on: October 30, 2020, 08:13:08 am »
Connect VDD through a resistor to a TLV431 placed backwards as reference. Then measure this reference voltage with your VDD. Something like:


Then a lower ADC code indicates a higher supply voltage. You would need to see how you'd want to do the math on that PIC processor, or perhaps calculate the 8-bit ADC thresholds manually on which a certain low-battery situation is warranted.

Remove the 100nF capacitor immediately. Unless what you intended was an oscillator.
 

Offline MosherIV

  • Super Contributor
  • ***
  • Posts: 1530
  • Country: gb
Re: Reading ADC when the VDD is not fixed
« Reply #4 on: October 30, 2020, 08:38:55 am »
Pick a better microcontroller with built in battery monitor.
 

Offline arslan43711Topic starter

  • Contributor
  • Posts: 19
  • Country: pk
Re: Reading ADC when the VDD is not fixed
« Reply #5 on: October 30, 2020, 08:55:41 am »
I am using a 1F super cap as a battery, Micro will be mostly in sleep mode(20uA current). I think the current of this reference circuit will more than my sleep current.
Anyhow maybe I will select another micro.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19681
  • Country: gb
  • 0999
Re: Reading ADC when the VDD is not fixed
« Reply #6 on: October 30, 2020, 09:05:56 am »
Connect VDD through a resistor to a TLV431 placed backwards as reference. Then measure this reference voltage with your VDD. Something like:


Then a lower ADC code indicates a higher supply voltage. You would need to see how you'd want to do the math on that PIC processor, or perhaps calculate the 8-bit ADC thresholds manually on which a certain low-battery situation is warranted.

Remove the 100nF capacitor immediately. Unless what you intended was an oscillator.
The post says TLV431, yet the schematic shows TL431. It needs to be the TLV431 and the datasheet suggests it will be stable with a 100nF capacitor and an output voltage of 1.24V. Although I agree, it's not necessary.
https://www.ti.com/lit/ds/symlink/tlv431a.pdf

I suggest a lower current. The TLV431 will work down to 80µA. R10 could easilly be 15k. If improved supply rejection is required, which I doubt, as it's a battery operated device, use two 7k5 resistors in series, for R10, with the tap connected to 0V, via a 10µF capacitor.
 
The following users thanked this post: hans

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Reading ADC when the VDD is not fixed
« Reply #7 on: October 30, 2020, 09:35:15 am »
I do not think the improved rejection is needed for the ADC in a PIC.

Why doesn't the PIC have an internal reference?

//I'd definitely swap for a different MCU type, likely even from different vendor, that has an adequate low power internal reference implemented//.

20uA sleep current is quite a lot and you won't get much lifetime from a 1F supercap. They are as expensive as a coin cell battery, but the battery has couple orders of magnitude more capacity.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13840
  • Country: gb
    • Mike's Electric Stuff
Re: Reading ADC when the VDD is not fixed
« Reply #8 on: October 30, 2020, 09:49:43 am »
I am using a 1F super cap as a battery, Micro will be mostly in sleep mode(20uA current). I think the current of this reference circuit will more than my sleep current.
Anyhow maybe I will select another micro.
Power the reference from an I/O pin, so you only turn it on briefly to measure the battery voltage.
there are some PICs with internal references
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 
The following users thanked this post: hans, Doctorandus_P

Offline fcb

  • Super Contributor
  • ***
  • Posts: 2125
  • Country: gb
  • Test instrument designer/G1YWC
    • Electron Plus
Re: Reading ADC when the VDD is not fixed
« Reply #9 on: October 30, 2020, 10:23:30 am »
Caution if you use a capacitor across the TL431.   We've found that certain brands (can't remember which) will oscillate when they have a capacitor across them. Any noise from the TL431 is going to be well under an LSB (10/12bit).

Also, if you follow Mikes suggestion - definatley don't put a capacitor across the TL431 - it will slow up your reference and require more power.  Also, while the datasheet specifies 1mA through a typical TL431 - they will work well with lower currents. YMMV.
https://electron.plus Power Analysers, VI Signature Testers, Voltage References, Picoammeters, Curve Tracers.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13840
  • Country: gb
    • Mike's Electric Stuff
Re: Reading ADC when the VDD is not fixed
« Reply #10 on: October 30, 2020, 10:25:10 am »
For battery detection, a simple diode would probably be fine as a reference
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Reading ADC when the VDD is not fixed
« Reply #11 on: October 30, 2020, 10:27:49 am »
Caution if you use a capacitor across the TL431.   We've found that certain brands (can't remember which) will oscillate when they have a capacitor across them. Any noise from the TL431 is going to be well under an LSB (10/12bit).

Also, if you follow Mikes suggestion - definatley don't put a capacitor across the TL431 - it will slow up your reference and require more power.  Also, while the datasheet specifies 1mA through a typical TL431 - they will work well with lower currents. YMMV.

If the datasheet specifies 1 mA minimum current, they need 1 mA minimum current and will NOT work under 1 mA. They may, but as well may not. It is stupid idea to build designs like this, when there are legitimate low current "431" based references, that operate well under 100 uA.

Stability regions with parallel capacitive loads are also defined in every datasheet. No need to "find certain brands" by experimenting.
 
The following users thanked this post: newbrain

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11701
  • Country: my
  • reassessing directives...
Re: Reading ADC when the VDD is not fixed
« Reply #12 on: October 30, 2020, 11:41:48 am »
use 2.5V regulator such as jelly bean AMS1117-2.5V (or buck) to power mcu and use voltage divider to sense battery voltage, you'll save one (Vref input) mcu pin, and mcu will use lower power.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Reading ADC when the VDD is not fixed
« Reply #13 on: October 30, 2020, 12:22:19 pm »
use 2.5V regulator such as jelly bean AMS1117-2.5V (or buck) to power mcu and use voltage divider to sense battery voltage, you'll save one (Vref input) mcu pin, and mcu will use lower power.

And drain the battery by the quiescent current consumption of the LDO. Let alone the switcher. :palm:
« Last Edit: October 30, 2020, 12:24:24 pm by Yansi »
 

Online wraper

  • Supporter
  • ****
  • Posts: 17314
  • Country: lv
Re: Reading ADC when the VDD is not fixed
« Reply #14 on: October 30, 2020, 12:34:40 pm »
use 2.5V regulator such as jelly bean AMS1117-2.5V (or buck) to power mcu and use voltage divider to sense battery voltage, you'll save one (Vref input) mcu pin, and mcu will use lower power.

And drain the battery by the quiescent current consumption of the LDO. Let alone the switcher. :palm:
Just use some LDO with low questient current or voltage reference IC like MAX6120. You can power it from MCU I/O pin only when actually making measurement to reduce consumption. There are no other way than using external reference without changing MCU.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Reading ADC when the VDD is not fixed
« Reply #15 on: October 30, 2020, 12:53:46 pm »
I think that changing the MCU would likely be the wisest choice here.  >:D

Switching an external reference on/off using a GPIO pin would be the second best one could do to keep the MCU type.
 

Offline arslan43711Topic starter

  • Contributor
  • Posts: 19
  • Country: pk
Re: Reading ADC when the VDD is not fixed
« Reply #16 on: October 30, 2020, 12:56:35 pm »
I have decided to change the micro to pic16f18324 it has the same pinout so no need to change the PCB and PPS for peripherals. And it has inter voltage reference.
 
The following users thanked this post: Yansi, JPortici

Offline fcb

  • Super Contributor
  • ***
  • Posts: 2125
  • Country: gb
  • Test instrument designer/G1YWC
    • Electron Plus
Re: Reading ADC when the VDD is not fixed
« Reply #17 on: October 30, 2020, 01:41:59 pm »
Caution if you use a capacitor across the TL431.   We've found that certain brands (can't remember which) will oscillate when they have a capacitor across them. Any noise from the TL431 is going to be well under an LSB (10/12bit).

Also, if you follow Mikes suggestion - definatley don't put a capacitor across the TL431 - it will slow up your reference and require more power.  Also, while the datasheet specifies 1mA through a typical TL431 - they will work well with lower currents. YMMV.

If the datasheet specifies 1 mA minimum current, they need 1 mA minimum current and will NOT work under 1 mA. They may, but as well may not. It is stupid idea to build designs like this, when there are legitimate low current "431" based references, that operate well under 100 uA.

Stability regions with parallel capacitive loads are also defined in every datasheet. No need to "find certain brands" by experimenting.
Disagree that it's "stupid" - low current 431's are rarer, more expensive - the NCP431 (Farnell: 2534159) is around $0.10 in 100's, a generic 431 is around $0.014 (LCSC: C181103).

Whilst low current 431's can be made to use 40uA, the dutycycle required in the OP's use case is likely to be so low that it's contribution to overall current consumption of even a 1mA TL431 would be measured in a few nA.  The 100nF suggested is very much in the non-stable zone (ti datasheet: SLVS543P, fig18), 4.7nF or less, or 10uF or more.  But I would argue that it isn't necessary with 10/12 bit converters.

I wasn't suggesting that someone tries different brands of TL431 - what circuit might work with brand of TL431 might not work with another - I have very real experience with this.

 
https://electron.plus Power Analysers, VI Signature Testers, Voltage References, Picoammeters, Curve Tracers.
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3485
  • Country: it
Re: Reading ADC when the VDD is not fixed
« Reply #18 on: October 30, 2020, 03:17:19 pm »
Why doesn't the PIC have an internal reference?

because the 16F688 is ancient (released in 2003 or maybe earlier)
luckily he was able to get a newer part (luckily relative to the fact that the OP is from pakistan)
 

Online wraper

  • Supporter
  • ****
  • Posts: 17314
  • Country: lv
Re: Reading ADC when the VDD is not fixed
« Reply #19 on: October 30, 2020, 03:31:20 pm »
The post says TLV431, yet the schematic shows TL431. It needs to be the TLV431 and the datasheet suggests it will be stable with a 100nF capacitor and an output voltage of 1.24V. Although I agree, it's not necessary.
https://www.ti.com/lit/ds/symlink/tlv431a.pdf

I suggest a lower current. The TLV431 will work down to 80µA. R10 could easilly be 15k. If improved supply rejection is required, which I doubt, as it's a battery operated device, use two 7k5 resistors in series, for R10, with the tap connected to 0V, via a 10µF capacitor.
Sorry but for both Tl431 and TLV431 0.1 uf is in unstable zone for any current with VKA = VREF.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19681
  • Country: gb
  • 0999
Re: Reading ADC when the VDD is not fixed
« Reply #20 on: October 30, 2020, 03:37:41 pm »
The post says TLV431, yet the schematic shows TL431. It needs to be the TLV431 and the datasheet suggests it will be stable with a 100nF capacitor and an output voltage of 1.24V. Although I agree, it's not necessary.
https://www.ti.com/lit/ds/symlink/tlv431a.pdf

I suggest a lower current. The TLV431 will work down to 80µA. R10 could easilly be 15k. If improved supply rejection is required, which I doubt, as it's a battery operated device, use two 7k5 resistors in series, for R10, with the tap connected to 0V, via a 10µF capacitor.
Sorry but for both Tl431 and TLV431 0.1 uf is in unstable zone for any current with VKA = VREF.
You're right. I missread the graph on the data sheet.  :palm:

I have decided to change the micro to pic16f18324 it has the same pinout so no need to change the PCB and PPS for peripherals. And it has inter voltage reference.
That's definitely the right decision. It's normally more cost effective to use a better MCU with the features you require built-in, than to add them afterwards.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13840
  • Country: gb
    • Mike's Electric Stuff
Re: Reading ADC when the VDD is not fixed
« Reply #21 on: October 30, 2020, 04:12:27 pm »
20uA is a lot for sleep mode - I don't recall if yours is one with the low-power WDT, but you should be looking at more like 2-3uA unless you have something else drawing current
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3566
  • Country: nl
Re: Reading ADC when the VDD is not fixed
« Reply #22 on: October 31, 2020, 12:12:31 am »
Even 2uA sleep mode is a lot for "modern" microcontrollers.
Just did a quick search for:
https://html.duckduckgo.com/html?q=ultra+low+power+microcontroller

And within a few minutes I found:
https://www.st.com/content/st_com/en/products/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus/stm32-ultra-low-power-mcus/stm32l5-series.html

Which claims:
    17 nA in shutdown mode
    3 µA in stop mode with full SRAM and peripheral states retention with 5µs wake-up time
    Down to 62 µA/MHz in active mode

That is a difference of 2 orders of magnitude!

But when chasing the low current ghost you have to consider the whole design. Quiescent current of a voltage regulator or even just a leaky elco can completely dominate current consumption.
« Last Edit: October 31, 2020, 12:23:52 am by Doctorandus_P »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9914
  • Country: us
Re: Reading ADC when the VDD is not fixed
« Reply #23 on: October 31, 2020, 12:47:41 am »
Table 14-8 Parameter AD08 has a requirement that the source resistance, as seen by the ADC, be, at most, 10k Ohms.

http://ww1.microchip.com/downloads/en/devicedoc/41203d.pdf

The Comparators have an internal Vref that is ratiometric with Vcc.  I haven't thought through what this means but you might be able to get just a "Good"/"Low" indication.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 27384
  • Country: nl
    • NCT Developments
Re: Reading ADC when the VDD is not fixed
« Reply #24 on: October 31, 2020, 01:32:59 am »
I am using a 1F super cap as a battery, Micro will be mostly in sleep mode(20uA current). I think the current of this reference circuit will more than my sleep current.
Anyhow maybe I will select another micro.
Use a low power reference instead of an ancient one. For example the REF3025. Power it from an I/O pin when needed but keep the turn-on delay in time in mind. But as others noted: the PIC you selected has a very high power consumption.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf