This shows you the differences between two versions of the page.
| — | en:avr:dac [2026/02/19 11:31] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Digital-to-analog converter ====== | ||
| + | |||
| + | Digital-to-analog converter (DAC) converts a digital signal into an analog voltage. The AVR xmega DAC output voltage can range from 0 to the reference voltage. The DAC digital input resolution is 12-bit and the throughput is up to 1 million conversions per second (MSPS) per channel. | ||
| + | |||
| + | The input value can be provided as 12-bit or 8-bit, similarly to the ADC. | ||
| + | The ATxmega128A1U controller has 2 DAC modules, each with 2 channels, for a total of 4 DAC outputs. The reference voltage can be AVcc, the internal 1.00 V, or the analog reference inputs AREFA or AREFB. | ||
| + | |||
| + | <box 100% round # | ||
| + | |||
| + | The example shows configuring one DACA channel and setting its value. DACA CH0 is connected to pin PA2 on the ATxmega128A1U controller. | ||
| + | |||
| + | <code c> | ||
| + | // Enable DACA and channel CH0 | ||
| + | DACA.CTRLA = (DAC_CH0EN_bm|DAC_ENABLE_bm); | ||
| + | // Set DACA channel CH0 to single-channel mode | ||
| + | DACA.CTRLB = (DAC_CHSEL_SINGLE_gc); | ||
| + | // Set DACA reference voltage to AVcc | ||
| + | DACA.CTRLC = (DAC_REFSEL_AVCC_gc); | ||
| + | |||
| + | // Wait until the previous conversion is finished | ||
| + | while((DACA.STATUS & DAC_CH0DRE_bm) == 0); | ||
| + | // Set DACA CH0 output to ~2V | ||
| + | DACA.CH0DATA = 2000; | ||
| + | </ | ||
| + | </ | ||