Converting Direct Voltage Value
//GET VOLTAGE
//Vref = 3.3V
//12bit AtoD = 0 to 4095
//4095 = 3.3V
double d_temp;
d_temp = (((double)3.3 / 4095) * atod_buffer_0);
uint16_t voltage_mv;
voltage_mv = (uint16_t)((((double)3.3 / 4095) * atod_buffer_0) * 1000);
Converting Based On A Voltage Reference Reading
//int VrefAtodValue = AtoD reading for 2.5V Vref input
//int PsuVoltageAtodValue = AtoD reading for another AtoD input we want to be be accurate
//Get PSU voltage in mV (int x 1000) (e.g. 5000 = 5.000V)
uint16_t PsuVoltageMv = (((double)2.5 / VrefAtodValue) * PsuVoltageAtodValue * 1000);
Converting Voltage Value After Potential Divider Resistors
//Vref = 3.3V
//12bit AtoD = 0 to 4095
//4095 = 3.3V
//Potential divider input:- Vin -> 39K -> AtoD -> 100K -> Gnd
//Total resistance = 139
//To Gnd resistance = 100
//Result as a double:
double dTemp;
dTemp = ((((double)3.3 * ((double)139 / 100)) / 4095) * AtodBuffer0);
//Result as an int:
uint16_t voltage_mv;
voltage_mv = (uint16_t)(((((double)3.3 * ((double)139 / 100)) / 4095) * AtodBuffer0) * 1000);
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.