Go Down

Topic: Skewed voltage divider readings (Read 864 times) previous topic - next topic

PerryBebbington


Quote
The OP's problem is, however, the assumption about the internal reference voltage on an 32U4 chip (Leonardo).
Unlike the 328P (Uno etc.) , this voltage is 2.56 volts, not 1.1 volts.
Ah!
I was making that mistake too! ++Karma;

danielcdev

Sorry for the delayed replies, all.

I had a horrible time last night, as my soldering iron was busy dying on me.  A Hakko 888 should be waiting for me when I get home from work.

6v6gt,
Magnificent!  I didn't even realize that.  Seems I need to read more datasheets, and pay more attention.  I'm leagues closer to an accurate reading than before!

A 12.45 volt LiPo 3S battery pack reads 12.29 volts (used to be ~10.3), the 5v reference is saying 4.61 volts and 3v3 reference is staying 3.07.

New soldering iron tonight and no distractions - I'll be back on this shortly!

Thanks for all of your replies.

danielcdev

#17
Nov 15, 2019, 12:36 am Last Edit: Nov 15, 2019, 12:39 am by danielcdev
Hey guys,

I purchased perfboard, solder and a Hakko 888.  I've soldered everything together, but still no dice.  Removed all of the analogReference calls, using 5 volt reference again.  Arduino reads 4.99v on it's own 5v reference without voltage divider, and (11 ADC) 3.60v going through the divider.

Picture of the board I've soldered is attached, and amended code posted.

Before this, I tried 10k and 220 ohm resistors on the breadboard, with the same problem.  Very funny, skewed readings.  I'm not one to give up, but this just seems to be unattainable for me.

Code: [Select]
#define ANALOG_INPUT A2
#define ANALOG_RESOLUTION 1024.0
#define VREF 5
#define R1 1000000.0
#define R2 8200.0

const float voltageDividerRatio = (R2 / (R1 + R2));

void setup() {
  Serial.begin(9600);
 
  pinMode(ANALOG_INPUT, INPUT);
}

void loop() {
  float vout = (analogRead(ANALOG_INPUT) * VREF) / ANALOG_RESOLUTION;
  float vin = vout / voltageDividerRatio;
 
  Serial.print(analogRead(ANALOG_INPUT), 3);
  Serial.print(" ");
  Serial.print(vout, 3);
  Serial.print(" ");
  Serial.print(vin, 3);
 
  Serial.println();

  delay (1000);
}

Wawa

Serial.print(vin, 3);
~135volt with three decimal places requires 135000 A/D counts.
More than 100x what you actually have.

Serial.print(vin, 1); // would be realistic
But even that is not possible without some oversampling.
Leo..

Go Up