3.2
Conversion Techniques
The PCM-A/D can be pro grammed in any lan guage sup port ing port I/O in struc tions.
The code snip pet be low is in the 'C' lan guage and dem on strates a sim ple func tion that takes
as an ar gu ment the chan nel number and re turns a 16- bit un signed value cor re spond ing to
the cur rent con ver sion value. The next sec tion de scribes a sam ple/test/cali bra tion pro gram
in cluded with the PCM-A/D board both in ex ecu ta ble and source form.
#de fine BASE_AD DRESS 0x110
un signed con vert(int chan nel_number)
{
un signed re turn_value;
/* Start the con ver sion by writ ing to the Se lect/Start con ver sion Reg is ter */
out portb(BASE_AD DRESS + 1, chan nel_number);
/* Now wait for the con ver sion to com plete */
while((in portb(BASE_AD DRESS) & 0x03) != 3)
;
/* Now read out the 2 bytes that make up the value */
re turn_value = in portb(BASE_AD DRESS + 2);
/* Shift the MSB value up 8 bits in prepa ra tion for the LSB */
re turn_value = re turn_value < 8;
/* Read the LSB value and 'OR' it into the pre pared MSB value */
re turn_value = re turn_value | in portb(BASE_AD DRESS + 1);
re turn re turn_value;
}
Page 3-4
PCM-A/D-12/16 OPERATIONS MANUAL
970513
WinSystems - "The Embedded Systems Authority"