180 of 323
ZBasic System Library 170 ZX Microcontroller Family 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 table below indicates the available channels and the corresponding DAC hardware used. See the description of DAC() for additional details on the DAC channels. Supported DAC Channels ZX Models DACB DACA ZX-24x Chan 1, Pin 8 Chan 2, Pin 9 ZX-32a4 Chan 1, Pin 6 (B.2) Chan 2, Pin 7 (B.3) ZX-128a1 Chan 1, Pin 7 (B.2) Chan 2, Pin 8 (B.3) Chan 3, Pin 97 (A.2) Chan 4, Pin 98 (A.3) ZX-24xu Chan 1, Pin 26 (B.2) Chan 2, Pin 25 (B.3) Note, particularly, that the ATxmega can produce two analog outputs from a single DAC. In the table above, channels 1 and 2 are the two outputs from one DAC and channels 3 and 4 are the two outputs from the second DAC (if available). In order to use the second channel on a given DAC, the first channel must have been opened in dual output mode (see the table below). Also note that using both outputs from a DAC will result in analog levels with significantly more noise due to the sample-and-hold and automatic refresh circuitry employed. For this reason, it is generally recommended to use single output per DAC. 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.