Download ATS-SDK - AlazarTech
Transcript
ATS-SDK Programmer’s Guide
The following code fragment demonstrates how to convert a 2-byte sample value
containing a signed 14-bit sample code to in volts.
double SampleToVoltsU14(U16 sampleValue, double inputRange_volts)
{
// Right-shift 16-bit sample word by 2 to get 14-bit sample code
int bitShift = 2;
U16 sampleCode = sampeWord >> bitShift;
// AlazarTech digitizers are calibrated as follows
int bitsPerSample = 14;
double codeZero = (1 << (bitsPerSample - 1)) - 0.5;
double codeRange = (1 << (bitsPerSample - 1)) - 0.5;
// Convert the signed code to unsigned
sampleCode = (sampleCode + 0x2000) & 0x1FFF;
// Convert sample code to volts
double sampleVolts = inputRange_volts *
((double) (sampleCode - codeZero) / codeRange);
}
return sampleVolts;
2.5.1.4
16-bit per sample
2.5.1.4.1 Getting 2-byte sample values from the buffer
The figure below displays the first 128-bytes of data in a buffer from a 16-bit digitizer
such as the ATS660, ATS9462, ATS9625, or ATS9626.
Figure 2-9 16-bit sample data
Each 16-bit sample value occupies 2 bytes in the buffer, so the figure displays 64 sample
values (128 bytes / 2 bytes per sample).
The first 2 bytes in the buffer, shown highlighted, are 0x14 and 0x80. Two-byte samples
values are stored in little-endian byte order in the buffer, so the first sample value is
0x8014.
The following code fragment demonstrates how to access each 16-bit sample value in a
buffer.
U16 *pSamples = (U16*)buffer;
for (U32 sample = 0; sample < samplesPerBuffer; sample++)
© 2003-2013 Alazar Technologies Inc.
65