(I can't figure out if this question is too electronic to be also a programming post. A person of thirst seeks among many dry wells.
Forgive me, ye gods of double-posting, but after a while and no replies on this board, my great impatience yielded to the temptation to seek elsewhere.)
I am trying to figure out how to program a 10-bit MCU A2D converter in C-language to read battery voltage(approx 14V), but I need just a little guidance on how to develop an equation to best accurately display the battery voltage from my data.
I have no problem getting the A2D result in counts nor displaying the result in decimal on my display, just need help trying to get get an idea on how to develop an equation.
Attached is a simple voltage divider schematic that I am using to measure the battery voltage and uses an npn-output optoisolator to switch on the measurement when the battery voltage is to be sampled.
I have measured the resistors, the voltage drops of the optoisolator, the measured voltages etc, and the attached shows the readings I get on my Fluke DVM.
I notice the voltage drop across the opto-isolator varies non-linearly a bit and I want to correct for that but that is not my question.
But how do I solve this seemingly simple voltage divider coding problem to get a conversion count multiplier so the voltage in counts is to be most accurately converted to decimal volts?
(I know I can just do many reprogramming attempts with guesses to zero-in on the required multiplier, but what is the science in that!)