ADC icon indicating copy to clipboard operation
ADC copied to clipboard

Assigning pinMode(pin, INPUT) causes slightly wrong readings?

Open Eheran1 opened this issue 8 years ago • 0 comments

I have a voltage divider here to read the voltage of a lithium ion cell: Vbatt ->33k -> pin -> 100k -> GND (100µF cap via pin -> cap -> GND, high impedance is not the issue) Ohms law says that Vbatt = (33k + 100k) / 100k * Vpin However, the pin is reading high. Both in the µC as well as when using a multimeter on pin<->GND compared to the correct Vbatt<->GND. Not much, but the reading is about 5% high. It took me way too long to find out that said pinMode causes this problem. Removing the pinMode declaration removed the issue, the ready is now <1% off the multimeter.

While trying to figure out what is going on I also found that I was unable to have ADC_0 at 16bit resolution and ADC_1 at 10bit. They were always both at 16bit. And what does the compare mean... I tryed to turn that on and off for both ADCs and it didnt change a thing. So why "always call it"? // always call the compare functions after changing the resolution! //adc->enableCompare(1.0/3.3*adc->getMaxValue(ADC_0), 0, ADC_0); // measurement will be ready if value < 1.0V //adc->enableCompareRange(1.0*adc->getMaxValue(ADC_0)/3.3, 2.0*adc->getMaxValue(ADC_0)/3.3, 0, 1, ADC_0); // ready if value lies out of [1.0,2.0] V

Eheran1 avatar Jan 11 '18 22:01 Eheran1