HEM Data Support: Helpful Hints
Navigation

Decoding The IOtech DaqBook High Speed Digital Inputs Using Waveform Analyzer

This example illustrates how to use the Analysis element to decode the high speed digital inputs on connector P3 of the IOtech DaqBooks. These high speed inputs are acquired as A/D channel 272 so that the A/D’s pacing clock can be used. This provides much better performance than the software paced Digital Input elements (software pacers have a maximum resolution of approximately 55ms).

The output of channel 272 is an integer representation of 16-bit digital word, where the bits are composed of the digital input values. To determine the individual bit values, we will use some of the Waveform Analyzer’s functions.

To implement this math, we will create a generic decoding function using the define keyword, then we will call the function for each bit we are interested in. The results of our function produce a value of 1 when the digital bit is high, and a value of 0 when the digital bit is low.

The decoding process is fairly simple. When the bits are read and converted to a digital word, each bit corresponds to a power of 2. If we divide the input value by 2 raised to the bit we are looking for, the decimal portion of the result is either 0 (when the bit is active) or 0.5 (when the bit is not active). We use the frac function in the Analysis element to retrieve only the decimal portion of the division. To convert the decimal portion to a 1 or 0, we use the round function which converts a value to the nearest integer.

To decode the bit we are after we simply call the function with the bit number as the argument. On connector P3, the bits are labeled SDI0 to SDI15, so we can account for the 0-based numbering system by adding a value of 1 to the bit value in the definition.

The Analysis function table looks like the following, assuming the DaqBook is element letter A (channel A272 in the definition). Remember that the (bit+1) factor accounts for the 0-based request for the bit decoding. (Only the first eight channels are shown, but you get the idea).

# Run Comments Equation Definition Label Units
1 define decode(bit)=round(frac(A272/(2^(bit+1))))
2 S0 = decode(0) Bit 0 Logic
3 S1 = decode(1) Bit 1 Logic
4 S2 = decode(2) Bit 2 Logic
5 S3 = decode(3) Bit 3 Logic
6 S4 = decode(4) Bit 4 Logic
7 S5 = decode(5) Bit 5 Logic
8 S6 = decode(6) Bit 6 Logic
9 S7 = decode(7) Bit 7 Logic
10 S8 = decode(8) Bit 8 Logic