My project runs off a single LiPo battery, which is connected to my ATMEGA328P's A6 pin with a 100Meg / 330 Meg voltage divider.
a=analogRead(A6) batteryvolts = map( a, 0, 1023, 0, 3300) / .767; // R1=100K; R2=330K
And this all worked fine on my handmade boards.
Now I have an assembly company building these boards. And the voltage divider is now implemented with surface mount resistors, where formerly I hand-soldered in a pair of normal resistors.(Same resistance of course.)
Now the behavior is different in two ways:
The reading is 4x lower. It's as if it were using a 12-bit range (0-4096) instead of a 10-bit range (0-1024). But the chip used is still an ATMEGA328P, which doesn't have a 12-bit range (does it?). The markings on the ATMEGA328 chip are exactly the same as on my handmade boards. Is there some kind of setup is have to do? fuses? configuration? bootloader?
The readings are erratic. sometimes the reading is very low like 20 or 30, where (with a fully charged LiPo battery) it should be about 230. I am indeed doing the trick of discarding the first reading and waiting 10 ms before the second reading, which I then use. I've tried upping the delay to 500 ms, no joy.)
Does anybody have advice for me? Thanks in advance.