# How to convert raw ADC value into voltage in volts in software?

Let's say I have a microcontroller with an ADC and my goal is to measure instantaneous values of the line to line voltage of the three phase grid 400 V/50 Hz.

I have a voltage instrument transformer with the following nameplate data: 400V/6V. Secondary winding of that transformer is connected directly to the 16 bit ADC which has bipolar channels +/-10V.

As far as the conversion from the raw data read from the ADC into the voltage in volts I have following idea how to do that in C++ software:

    uint16_t raw_value
float voltage

if (raw_value & 0x8000) {
// negative number in 2's complement
voltage = (static_cast<float>(raw_value) - 65536) / 32768 * 666.66;
} else {
// positive number in 2's complement
voltage = static_cast<float>(raw_value) / 32768 * 666.66;
}


As far as the value 666.66 it is a channel norm i.e. voltage at the primary side of the transformer corresponding to the full scale value of the ADC i.e. 10V. I have calculated this value based on following $$\6\,V \sim 400\,V\$$ i.e. $$\10\,V \sim 10\cdot\frac{400}{6} = 666.66\,V\$$. Basically this value specifies the maximum measurable amplitude (with given transformer and adc) of the line to line voltage.

Can someone tell me whether my approach to converting raw ADC data into voltage in volts is correct (namely in respect to the channel norm)?

• Does this answer your question? Convert ADC value to real voltage May 26, 2021 at 11:19
• Have you taken into account RMS and peak values? AC voltage is usually notes as RMS, however your ADC will read the peak. A square root of two will do. May 26, 2021 at 11:25
• @ElliotAlderson thank you for your reaction. I have also found this question but it doesn't answer to my question. May 26, 2021 at 11:26
• @Kartman thank you for your reaction. As far as I understand your comment you think that the channel norm (in my case 666.66V) shall be multiplied by $\sqrt{2}$? May 26, 2021 at 11:33
• Do you want the voltage to read as peak or RMS? How are you sampling the data? If you feed in 400Vrms, the adc and your scaling will read 400 * 1.4142 Volts. So you might want to multiply by 1/square root of 2 May 26, 2021 at 11:39