Manual Conversion of A/D Values

To properly use the values returned from Analog Input channels, the application must convert the returned 16-bit value to a voltage. The function SM_AtoDConversion() has been provided to assist the programmer and eliminate error. At times, it may be desirable to manually convert the 16-bit values to voltages. The following is a brief tutorial on how to do so.

Analog to Digital Conversion in Positive Voltage Ranges

When an analog input has been configured to convert positive voltage ranges [0, Maximum VDC], the 16-bit values read from the device will correspond to the range 0 to MAX ADC ((2^ADC Resolution) - 1). The formula for converting the returned values to voltage is shown below:

  {voltage} = ({value} / {2^ADC_RES - 1}) * {MAX_VDC}

For example, a returned value of 1319 (0x527) on a SeaI/O 470 module (12-bit ADC) configured for a 0-10V range equals a voltage input of 3.22V.

  {voltage} = (1319 / 4095) * (10 V)

  {voltage} = 3.22 V

Differential Voltage Range

When an analog input has been configured to convert bi-polar voltage ranges [-Maximum VDC, Maximum VDC], the most significant ADC bit (dependent on ADC resolution) determines whether the returned values is either positive (zero) or negative (one). The remaining bits provide the magnitude of the value. In other words, if the returned value is less than or equal to half the Maxiumum ADC value (i.e. 2^(ADC Resolution - 1)), then the resulting voltage is positive, otherwise it is negative. To calculate the voltage, continue the same as described above with 1 less bit of ADC resolution.

  If the {value} is less than or equal to {MAX_ADC / 2},

  {voltage} = {value} / {{2^ADC_RES} / 2} * {MAX_VDC}

  Else

  {voltage} = ({value} - {2^ADC_RES}) / {2^ADC_RES / 2} * {MAX_VDC}

For example, a returned value of 659 (0x293) on a SeaI/O 470 with a voltage range of +/-10V is less than 2048, so the calculated voltage is positive. Using the first formula above, the returned value results in a calculated voltage of 3.22V.

  {voltage} = 659 / 2048 * 10V

  {voltage} = 3.22V

If the polarity at the input is reversed, the returned value from SM_ReadInputRegisters() is 3434 (0xD6A). Since the returned value is greater than 2048, the calculated voltage must be negative and therefore the second formula is used.

  {voltage} = (3434 - 4096) / 2048 * 10V

  {voltage} = -3.23V

Current Loop Mode

In current loop mode, the returned value is the voltage drop measured across a built-in precision resistor. To calculate the current first use the appropriate formula above to determine the voltage, then use Ohm's law (I = V/R) to get the current by dividing by the resistor value. For example, if we use the 3.23V from the SeaI/O 470 shown above, the current would be calculated as follows:

  {current} = {voltage} / {resistance}

  {current} = 3.22V / 249 Ohms

  {current} = 0.01293 A = 12.93 mA
 
 
Generated on Mon Oct 3 2022.