2

I have a reading from an ADC that I want to convert to the equivalent voltage. The problem is that my voltage for the the PIC microcontroller is not fixed. It changes between 5V and and 3.6V.

How can I convert my ADC reading to voltage?

The only possibility that I can think of is to connect the supply voltage to another ADC pin, make an algorithm in FW to approximate the supply voltage based on this value, and then use it to convert my first reading into voltage.

JRE
  • 71,321
  • 10
  • 107
  • 188
ali.hssn
  • 39
  • 4
  • Which specific microcontroller model do you use? – Tagli Jun 01 '21 at 10:05
  • 1
    Why not just use a 3.3V reference voltage for your ADC? You can get some that use <200uA so should be suitable enough for most battery applications –  Jun 01 '21 at 10:07
  • 1
    "The only possibility that I think of is to connect supply voltage to another adc pin, ..." The problem is the ADC reference voltage. If you don't stabilise that at a known reference then all your ADC readings will fluctuate too and you can't do any internal calibration. – Transistor Jun 01 '21 at 10:17
  • @Tagli I am using PIC18F24 – ali.hssn Jun 01 '21 at 10:17
  • @Doodle you mean I should use an external voltage regulator of 3.3V? – ali.hssn Jun 01 '21 at 10:19
  • Can't you set ADPREF to VDD and measure the 1.024V FVR channel with ADPCH=0b111111 and ADFVR = 0b10? Then you can solve the reading=1024*1.024V/VDD for VDD and calculate it directly as VDD = 1024 * 1.024/reading – Dave X Jun 01 '21 at 19:50
  • See this: https://electronics.stackexchange.com/questions/201321/measuring-battery-voltage-from-microcontroller-using-adc?rq=1#comment422006_201321 -- read the Fixed Voltage Reference as a special ADC channel using battery voltage as a reference, then back-calculate VDD=VFR*1024/reading. – Dave X Jun 01 '21 at 19:56
  • Here's some code for backing out the VDD from ADC reading the FVR on an Arduino: https://arduino.stackexchange.com/a/50771/6628 – Dave X Jun 01 '21 at 20:42
  • Thank you. I will take a look. @DaveX – ali.hssn Jun 03 '21 at 08:02

1 Answers1

5

According to the datasheet, you can use internal voltage references for the ADC:

enter image description here

But the voltage is limited according to the supply:

enter image description here

devnull
  • 8,517
  • 2
  • 15
  • 39
  • Just to be sure, If I set it to 4.096, my adc reading will not change with the supply voltage? – ali.hssn Jun 01 '21 at 10:30
  • 2
    It seems you are restricted to 2.048 V or below – devnull Jun 01 '21 at 10:36
  • 1
    Thank you. It should solve the problem. – ali.hssn Jun 01 '21 at 10:38
  • Can't you set ADPREF to VDD and measure the 1.024V FVR channel with ADPCH=0b111111 and ADFVR = 0b10? Then you can solve the reading=1024*1.024V/VDD for VDD and calculate it directly as VDD = 1024 * 1.024/reading – Dave X Jun 01 '21 at 19:48