XMega DAC

In embedded systems, oftentimes it is needed to generate analog outputs from a microcontroller. Examples of such include, generating audio tones, voice, music, smooth continuous waveforms, function generators, voltage reference generators, etc. Traditionally in such cases the most common techniques applied are based on Pulse Width Modulation (PWM), resistor networks and external Digital-to-Analog Converter (DAC) chips like MCP4921. The aforementioned techniques have different individual limitations and moreover require external hardware interfacing, adding complexities and extra cost to projects.  X Mega micros are equipped with 12 bit fast DACs apart from PWM blocks and again it proves itself to be a very versatile family of microcontrollers. In this post we will have a look into this block.

A brief overview

I used ATXMega32A4U just as always and it has only one dual channel DAC designated DACB but there are other X Mega devices that have more than one DAC.
The internal block diagram of the DAC block above shows its major parts. The DAC of X Mega is perhaps one of the simplest block to understand. Apart from DMA and event system interfacing, the DAC can provide reference source for the analog comparator and ADC blocks. It also has the capability to directly drive both resistive and capacitive loads (check device datasheet for limits). Just like the ADC block, the DAC block itself needs a reference source and this reference source can be both internal (internal 1.0V reference) and external (AVCC or AVREF). As stated earlier there are two independent DAC channels in the XMega32A4U and so there are two separate analog outputs (PB2 and PB3) available from this micro.
XMega DAC
The basic formula for voltage output from the DAC is as follows:
Formula

The digital data value ranges from 0 – 4095 (0×00000x0FFF) since it is a 12 bit DAC. How fast it can operate will depend on peripheral clock’s operating frequency. Just like the clock system, the DAC output can be precisely calibrated by using gain error and offset error registers. Though calibrating the DAC ensures more accurate data output, it is seldom used. If it is needed to calibrate the DAC for sensitive operations one must do so carefully and should use standard instruments that have least possible error, otherwise it is pointless to calibrate it. You can use the X Mega ADC block for calibration purpose if you don’t have access to good measurement instruments. In my previous post I showed how to use the X Mega ADC. I, however, never calibrated the DAC block. Calibration process is well explained in the reference manual.
Shown below are pin diagrams of both the most popular X Mega A1 and A4 devices. Checkout the DAC output pin locations because these are not mentioned in the reference manual.

Registers

The simplified register map for the DAC block shows that there are only a few registers to deal with. I’m not going to detail about them as the reference manuals are already doing so.

Control registers A-C are sequentially set first. These registers are responsible for selecting reference source, channel, power mode, etc. Calibration registers have names ending with “CAL” and data input registers have names ending with “DATA”. Lastly there is event system register that select which event system channel would trigger the DAC and there is a STATUS register which flags when it is possible to write new values to a specific DAC channel.

Read More: X Mega DAC

Leave a Comment

Your email address will not be published. Required fields are marked *