ADLINK CM1-86DX2 User Manual
Page 69

Using the Module
63
CM1-86DX2
outb
(
adcChannel, ADC_AUX_CHS
);
//
###################################################################
#############
/
*##################################################################
##############
5. Mask Interrupt generation, set IIT to 1 data in FIFO, power on ADC,
# set ScanMode (bit 1 = 0: single, 1: auto scan), start conversion (bit 0 = 1)
# --> ADC_CTRL_REG <-- ADC_START_ONE_SHOT or ADC_START_AUTOSCAN
########################################################################
########*/
outb
(
ADC_START_ONE_SHOT, ADC_CTRL_REG
);
//
###################################################################
#############
/
*##################################################################
##############
# 6. wait for ADC_STATUS bit 0 == 1
########################################################################
########*/
while( !(
inb
(
ADC_STATUS
) &
ADC_READY_MASK
) ) {;}
//
###################################################################
#############
/
*##################################################################
##############
# 7. if ADC_STATUS bit 0 ==1 then read ADC_DATA as long as ADC_DATA[15:13] matches
# the selected ADC channel
# 8. save ADC_DATA[10:0] & ADC_VAL_MASK as ADC data.
########################################################################
########*/
capturedAdcRaw = inw
(
ADC_DATA
);
capturedAdcChannel =
(
capturedAdcRaw
>>
13
) &
ADC_CH_MASK
;
capturedAdcData =
(
capturedAdcRaw & ADC_VAL_MASK );
capturedAdcValue = (
(double)
capturedAdcData
*
3.3
/
2048
) - (
OFFSET/1000
);
}
printf(
" Captured channel = 0x%02x\n", capturedAdcChannel
);
printf(
" Captured Data = 0x%04x\n", capturedAdcData
);
printf(
" Resulting value = %.3f\n\n", capturedAdcValue
);
return
0
;
}
//
###################################################################
#############
// END
Please note that this source code example is provided for a system running Linux. For
other operating systems it may be necessary to adapt the source code regarding include
files or headers and the syntax of I/O out commands because Linux is using outb(value,
address) instead of outb(address, value).