Xmega Application Note


dac_driver.h File Reference


Detailed Description

XMEGA DAC driver header file.

This file contains the function prototypes and enumerator definitions for various configuration parameters for the XMEGA DAC driver.

The driver is not intended for size and/or speed critical code, since most functions are just a few lines of code, and the function call overhead would decrease code performance. The driver is intended for rapid prototyping and documentation purposes for getting started with the XMEGA DAC module.

For size and/or speed critical code, it is recommended to copy the function contents directly into your application instead of making a function call.

Application note:
AVR1301: Using the XMEGA DAC
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Revision
1569
Date
2008-04-22 13:03:43 +0200 (ti, 22 apr 2008)

Copyright (c) 2008, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file dac_driver.h.

#include "avr_compiler.h"

Include dependency graph for dac_driver.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define DAC_Disable(_dac)   ( (_dac)->CTRLA &= ~DAC_ENABLE_bm )
 This macro disables the selected DAC module.
#define DAC_InternalOutput_Disable(_dac)   ( (_dac)->CTRLA &= ~DAC_IDOEN_bm )
 This macro disables internal routing of the DAC output to an internal ADC module.
#define DAC_InternalOutput_Enable(_dac)   ( (_dac)->CTRLA |= DAC_IDOEN_bm )
 Enable output to internal ADC.

Typedefs

typedef enum DAC_CH_enum DAC_CH_t
typedef enum DAC_TRIG_enum DAC_TRIG_t

Enumerations

enum  DAC_CH_enum { CH0 = 0x00, CH1 = 0x01 }
 Enumerator for DAC channels. More...
enum  DAC_TRIG_enum { DAC_TRIG_0_0 = 0x00, DAC_TRIG_0_1 = DAC_CH0TRIG_bm, DAC_TRIG_1_0 = DAC_CH1TRIG_bm, DAC_TRIG_1_1 = ( DAC_CH1TRIG_bm | DAC_CH0TRIG_bm ) }
 Enumerator for DAC event trigger. More...

Functions

bool DAC_Channel_DataEmpty (volatile DAC_t *dac, DAC_CH_t channel)
 Check if channel data register is empty.
void DAC_Channel_Write (volatile DAC_t *dac, uint16_t data, DAC_CH_t channel)
 Write data to selected channel.
void DAC_DualChannel_Enable (volatile DAC_t *dac, DAC_REFSEL_t convRef, bool leftAdjust, DAC_CONINTVAL_t sampleInterval, DAC_REFRESH_t refreshInterval)
 Enable Dual Channel.
void DAC_EventAction_Set (volatile DAC_t *dac, DAC_TRIG_t trigChannel, uint8_t eventLine)
 Configure event actions.
void DAC_SingleChannel_Enable (volatile DAC_t *dac, DAC_REFSEL_t convRef, bool leftAdjust)
 Enable Singe Channel.


Define Documentation

#define DAC_Disable ( _dac   )     ( (_dac)->CTRLA &= ~DAC_ENABLE_bm )

This macro disables the selected DAC module.

Parameters:
_dac The DAC module, either DACA or DACB.

Definition at line 86 of file dac_driver.h.

#define DAC_InternalOutput_Disable ( _dac   )     ( (_dac)->CTRLA &= ~DAC_IDOEN_bm )

This macro disables internal routing of the DAC output to an internal ADC module.

Parameters:
_dac The DAC module, either DACA or DACB.

Definition at line 105 of file dac_driver.h.

#define DAC_InternalOutput_Enable ( _dac   )     ( (_dac)->CTRLA |= DAC_IDOEN_bm )

Enable output to internal ADC.

This macro enables routing of the internal DAC output to the ADC module. This feature is useful for diagnostics and calibration purposes.

Parameters:
_dac The DAC module, either DACA or DACB.

Definition at line 97 of file dac_driver.h.


Typedef Documentation

typedef enum DAC_CH_enum DAC_CH_t

typedef enum DAC_TRIG_enum DAC_TRIG_t


Enumeration Type Documentation

Enumerator for DAC channels.

Enumerator:
CH0 
CH1 

Definition at line 65 of file dac_driver.h.

00065                          {
00066         CH0 = 0x00,
00067         CH1 = 0x01,
00068 } DAC_CH_t;

Enumerator for DAC event trigger.

Enumerator:
DAC_TRIG_0_0  Trigger on no channel.
DAC_TRIG_0_1  Trigger on channel 0.
DAC_TRIG_1_0  Trigger on channel 1.
DAC_TRIG_1_1  Trigger on both channels.

Definition at line 72 of file dac_driver.h.

00072                            {
00073         DAC_TRIG_0_0 = 0x00,                                
00074         DAC_TRIG_0_1 = DAC_CH0TRIG_bm,                      
00075         DAC_TRIG_1_0 = DAC_CH1TRIG_bm,                      
00076         DAC_TRIG_1_1 = ( DAC_CH1TRIG_bm | DAC_CH0TRIG_bm ), 
00077 } DAC_TRIG_t;


Function Documentation

bool DAC_Channel_DataEmpty ( volatile DAC_t *  dac,
DAC_CH_t  channel 
)

Check if channel data register is empty.

This function return the status of the data register empty flag for the selected channel in the given DAC module. This can be used to get the status of the register before writing a new value to it.

Parameters:
dac Pointer to DAC module register section.
channel Selected channel in the DAC module, either CH0 or CH1.
Return values:
dacStatus True if data register is empty.
dacStatus False if data register is not empty.

Definition at line 153 of file dac_driver.c.

Referenced by main().

00154 {
00155         bool dacStatus = ( dac->STATUS &
00156                          ( channel ? DAC_CH1DRE_bm : DAC_CH0DRE_bm ));
00157         return dacStatus;
00158 }

void DAC_Channel_Write ( volatile DAC_t *  dac,
uint16_t  data,
DAC_CH_t  channel 
)

Write data to selected channel.

This function writes data to the selected channel data register. The program should wait for the data register to be ready if necessary. This ensures that no intermediate values are lost with very high update rates.

Note:
The data must be in the format currently configured for the DAC, right or left adjusted.
Parameters:
dac Pointer to DAC module register section.
data Data to be converted.
channel Selected channel in the DAC module, either CH0 or CH1.

Definition at line 131 of file dac_driver.c.

References CH0.

Referenced by main().

00132 {
00133         if ( channel == CH0 ) {
00134                 dac->CH0DATA = data;
00135         } else {
00136                 dac->CH1DATA = data;
00137         }
00138 }

void DAC_DualChannel_Enable ( volatile DAC_t *  dac,
DAC_REFSEL_t  convRef,
bool  leftAdjust,
DAC_CONINTVAL_t  sampleInterval,
DAC_REFRESH_t  refreshInterval 
)

Enable Dual Channel.

This function configures the DAC to enable both channel outputs, in dual channel operation. It apply configuration parameters, save old values, clear affected bit field and set appropriate values.

Parameters:
dac Pointer to DAC module register section.
convRef Selects reference voltage for all conversions.
leftAdjust Set to true to make data registers left adjusted.
sampleInterval Interval between refreshing channel A and B.
refreshInterval Interval between refresh cycles.

Definition at line 103 of file dac_driver.c.

Referenced by main().

00108 {
00109         dac->CTRLB = ( dac->CTRLB & ~DAC_CHSEL_gm ) | DAC_CHSEL_DUAL_gc;
00110         dac->CTRLC = ( dac->CTRLC & ~( DAC_REFSEL_gm | DAC_LEFTADJ_bm ) ) |
00111                      convRef |
00112                      ( leftAdjust ? DAC_LEFTADJ_bm : 0x00 );
00113         dac->TIMCTRL = (uint8_t) sampleInterval | refreshInterval;
00114         dac->CTRLA |= DAC_CH1EN_bm | DAC_CH0EN_bm | DAC_ENABLE_bm;
00115 }

void DAC_EventAction_Set ( volatile DAC_t *  dac,
DAC_TRIG_t  trigChannel,
uint8_t  eventLine 
)

Configure event actions.

This function configures the event action for the DAC module. It clears both control bits and set required bits.

Note:
There is no checking if the event line number is valid. The value is simply truncated to fit the bit field in the corresponding register.
Parameters:
dac Pointer to DAC module register section.
trigChannel The channels to be triggered by events. Values can be DAC_TRIG_0_0, DAC_TRIG_0_1, DAC_TRIG_1_0 or DAC_TRIG_0_0.
eventLine Event line (0..7) to use for triggering conversions.

Definition at line 174 of file dac_driver.c.

References DAC_TRIG_1_1.

00177 {
00178         dac->CTRLB = ( dac->CTRLB & ~DAC_TRIG_1_1 ) | trigChannel;
00179         dac->EVCTRL = eventLine & DAC_EVSEL_gm;
00180 }

void DAC_SingleChannel_Enable ( volatile DAC_t *  dac,
DAC_REFSEL_t  convRef,
bool  leftAdjust 
)

Enable Singe Channel.

This function configures the DAC to enable channel 0 output only, in single channel operation. It apply configuration parameters, save old values, clear affected bit field and set appropriate values.

Parameters:
dac Pointer to DAC module register section.
convRef Selects reference voltage for all conversions.
leftAdjust Set to true to make data registers left adjusted.

Definition at line 79 of file dac_driver.c.

00082 {
00083         dac->CTRLB = ( dac->CTRLB & ~DAC_CHSEL_gm ) | DAC_CHSEL_SINGLE_gc;
00084         dac->CTRLC = ( dac->CTRLC & ~(DAC_REFSEL_gm | DAC_LEFTADJ_bm) ) |
00085                      convRef | ( leftAdjust ? DAC_LEFTADJ_bm : 0x00 );
00086         dac->CTRLA = ( dac->CTRLA & ~DAC_CH1EN_bm ) |
00087                      DAC_CH0EN_bm | DAC_ENABLE_bm;
00088 }

@DOC_TITLE@
Generated on Wed May 14 16:11:05 2008 for AVR1301 Using the XMEGA DAC by doxygen 1.5.5