Analog Output Code Example
VCM-DAS-3 Reference Manual
33
bipolar = 1
fullscale = 10
CASE 4 '+/-2.5V
bipolar = 1
fullscale = 2.5
CASE 5 '+7.5/-2.5V
bipolar = 2
fullscale = 7.5
END SELECT
IF bipolar = 1 THEN
'offset binary coding (symetrical ratio)
value = INT((voltage / fullscale) * 2048 + 2048)
ELSEIF bipolar = 2 THEN 'offset binary coding (asymetrical ratio)
value = INT((voltage / fullscale) * 3072 + 1024)
ELSE 'Unipolar
'straight binary coding
value = INT((voltage / fullscale) * 4096)
END IF
'Limit excursion
IF value > 4095 THEN
value = 4095
END IF
'Separate low byte from high nibble
lodac = value AND &HFF
hidac = (value AND &HF00) / 256
'Set selected DAC channel to the desired range
'(ENHANCED MODE REGISTER)
OUT BASE + &HA, ((range * 16) + channel)
'Set selected DAC channel to desired voltage
OUT BASE, lodac
OUT BASE + 2, channel
OUT BASE + 1, hidac
'A single read updates all outputs
x = INP(BASE)
'Wait for DONE or timeout before returning
done = 0
y = 0
WHILE NOT done
y = y + 1
IF y < 2000 THEN 'timeout
done = INP(BASE + &HA) AND &H01 '(ENHANCED MODE REGISTER)
ELSE
LIB_das3aout = 1
EXIT FUNCTION
END IF
WEND
LIB_das3aout = 0
END FUNCTION