HEM Data Support: Helpful Hints
Navigation

Converting Analog Data To Digital Values Using Waveform Analyzer

This example illustrates how to use the Analysis element to convert an analog voltage to digital word. Assume we are acquiring data from one analog channel, called channel A0, which ranges from 0 to 15 volts. We want to convert the analog value to a four bit digital word for output through a Digital Out element.

Conversion Theory

To convert the analog values to a digital word, we will use some Boolean math slight-of-hand. The trick is to check the value for the Most Significant Bit first and work our way towards the Least Significant Bit. If the analog value is greater than or equal to 8 then the MSB is 1, otherwise if the analog value is less than 8 then the MSB is 0.

Now comes the tricky part. Take the value for our MSB (we’ll call it Bit_1) and use it to determine the “remainder” of our analog value. In other words, take the value of Bit_1, multiply it by 8 (the number we tested for), and subtract it from our starting value. This calculation (called Result_1) leaves values from 0 to 7.999 volts alone, but subtracts 8 from all higher values.

Now we need to perform the same comparison for the next bit, called Bit_2. If the value of Result_1 is greater than or equal to 4 then Bit_2 is 1, otherwise Bit_2 is 0. The same pattern continues for the next bit where we take the value of Bit_2, multiply it by 4, and subtract it from Result_1 to produce Result_2. Assuming all calculations so far are OK, the values will range from 0 to 3.999.

For Bit_3, we check to see if the value of Result_2 is greater than or equal to 2. If it is, then Bit_3 is 1, otherwise Bit_3 is 0. Now we need to perform one final conversion to produce Result_3, which is the value of Bit_3 multiplied by 2 and subtracted from Result_2. This produces the value for our last bit, Bit_4, which is either a 0 or a 1.

Analysis Equations

To implement this math, we will use the Boolean math functions found in Waveform Analyzer version 3.0. The summary of the conversion theory procedure into “code-like” IF..THEN statements would look like this:

If A0 >= 8 Then
Bit_1 = 1
Else
Bit_1 = 0

Result_1 = A0 – (8 * Bit_1)

If Result_1 >= 4 Then
Bit_2 = 1
Else
Bit_2 = 0
Result_2 = Result_1 – (4 * Bit_2)

If Result_2 >= 2 Then
Bit_3 = 1
Else
Bit_3 = 0
Result_3 = Result_2 – (2 * Bit_3)

If Result_3 >= 1 Then
Bit_4 = 1
Else
Bit_4 = 0

The Waveform Analyzer equations for one channel would look like the following table. The output channels for the digital bits are P1, P2, P3, and P4. Assign these output channels in your Digital Out element. Because of the interaction between calculations and to avoid any buffer conflicts, use the same element letter for each set of bits.

# Comments Equation Definition Label
1 Bit_1 P1 = ( A0 >= 8 ) Bit 1 (MSB)
2 Result_1 P10 = A0 – (8 * P1)
3 Bit_2 P2 = (P10 >= 4) Bit 2
4 Result_2 P11 = P10 – (4 * P2)
5 Bit_3 P3 = (P11 >= 2) Bit 3
6 Result_3 P12 = P11 – (2 * P3)
7 Bit_4 P4 = (P12 >= 1) Bit 4 (LSB)