Page 202 of 346 Start Back Next End ZBasic System Library 190 ZBasic Microcontrollers OpenDAC Type Subroutine Invocation OpenDAC(channel, mode) OpenDAC(channel, mode, stat) Parameter Method Type Description channel ByVal Byte The channel to use for DAC generation. mode ByVal integral The desired DAC mode (see discussion below). stat ByRef Boolean The variable to receive the status code. Discussion This subroutine prepares a DAC channel for generating an analog voltage level. The pins on which an analog level may be generated depends on the target device. See the Resource Usage sub-section Digital-to-Analog Converters for details on the available analog output pins. DAC Mode Constituent Values Function Hex Value Bit Mask Dual Output &H8000 1x xx xx xx xx xx xx xx Single Output &H0000 0x xx xx xx xx xx xx xx Automatic Refresh &H4000 x1 xx xx xx xx xx xx xx Manual Refresh &H0000 x0 xx xx xx xx xx xx xx Internal 1-volt Reference &H0000 xx xx xx xx xx xx xx 00 AVcc Reference &H0001 xx xx xx xx xx xx xx 01 PortA Aref Reference &H0002 xx xx xx xx xx xx xx 10 PortB Aref Reference &H0003 xx xx xx xx xx xx xx 11 It is important to note that the mode parameter value is only used for the first OpenDAC() call for each channel pair. That is to say, if one channel of a pair is already open the OpenDAC() is called, the mode parameter is ignored. For dual output mode, the DAC values must be updated at least every 30uS. This will be done automatically if the Automatic Refresh bit is set in the mode parameter. Otherwise, your application will need to ensure that the DAC values are updated frequently enough to prevent drooping if the DAC output. The analog value output by the DAC will be approximately equal to the 12-bit digital value set for each channel (see the DAC() subroutine) divided by 4095 and multiplied by the reference voltage. The choice of four reference voltages available is made by the least significant two bits of the mode parameter value. For the PortA and PortB Aref Reference, the table below indicates the pin to which the desired reference voltage should be applied. DAC Reference Voltage Pins ZBasic Target Aref A Aref B ZX-24x 20, A.0 7, B.0 ZX-32a4 40, A.0 4. B.0 ZX-128a1 95, A.0 5, B.0 ZX-24xu 36, A.0 28, B.0 xmegaA4 40, A.0 4. B.0 xmegaD4 40, A.0 - xmegaA3, xmegaA3B, xmegaD3 62, A.0 6. B.0 xmegaA1 95, A.0 5, B.0