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);
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through resources like this. We hope you find it helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support here. If you need help with a problem please use one of the many online forums.