SAMV71 Xplained Ultra Software Package 1.4

adc.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2011, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 /**
00031  *  \file
00032  *
00033  *  \section Purpose
00034  *
00035  *  Interface for configuration the Analog-to-Digital Converter (ADC) peripheral.
00036  *
00037  *  \section Usage
00038  *
00039  *  -# Configurate the pins for ADC.
00040  *  -# Initialize the ADC with ADC_Initialize().
00041  *  -# Set ADC clock and timing with ADC_SetClock() and ADC_SetTiming().
00042  *  -# Select the active channel using ADC_EnableChannel().
00043  *  -# Start the conversion with ADC_StartConversion().
00044  *  -# Wait the end of the conversion by polling status with ADC_GetStatus().
00045  *  -# Finally, get the converted data using ADC_GetConvertedData() or 
00046  * ADC_GetLastConvertedData().
00047  *
00048 */
00049 #ifndef _ADC_
00050 #define _ADC_
00051 
00052 /*----------------------------------------------------------------------------
00053  *        Headers
00054  *----------------------------------------------------------------------------*/
00055 #include <assert.h>
00056 #include <stdint.h>
00057 
00058 /*------------------------------------------------------------------------------
00059  *         Definitions
00060  *------------------------------------------------------------------------------*/
00061 
00062 /* Max. ADC Clock Frequency (Hz) */
00063 #define ADC_CLOCK_MAX   20000000
00064 
00065 /* Max. normal ADC startup time (us) */
00066 #define ADC_STARTUP_NORMAL_MAX     40
00067 /* Max. fast ADC startup time (us) */
00068 #define ADC_STARTUP_FAST_MAX       12
00069 
00070 /* Definitions for ADC channels */
00071 #define ADC_CHANNEL_0  0
00072 #define ADC_CHANNEL_1  1
00073 #define ADC_CHANNEL_2  2
00074 #define ADC_CHANNEL_3  3
00075 #define ADC_CHANNEL_4  4
00076 #define ADC_CHANNEL_5  5
00077 #define ADC_CHANNEL_6  6
00078 #define ADC_CHANNEL_7  7
00079 #define ADC_CHANNEL_8  8
00080 #define ADC_CHANNEL_9  9
00081 #define ADC_CHANNEL_10 10
00082 #define ADC_CHANNEL_11 11
00083 #define ADC_CHANNEL_12 12
00084 #define ADC_CHANNEL_13 13
00085 #define ADC_CHANNEL_14 14
00086 #define ADC_CHANNEL_15 15
00087 
00088 #ifdef __cplusplus
00089  extern "C" {
00090 #endif
00091 
00092 /*------------------------------------------------------------------------------
00093  *         Macros function of register access
00094  *------------------------------------------------------------------------------*/
00095 
00096 #define ADC_GetModeReg( pAdc )                ((pAdc)->ADC_MR)
00097 
00098 #define ADC_StartConversion( pAdc )           ((pAdc)->ADC_CR = ADC_CR_START)
00099 
00100 #define ADC_SetCalibMode(pAdc)                ((pAdc)->ADC_CR |= ADC_CR_AUTOCAL)
00101 
00102 #define ADC_EnableChannel( pAdc, dwChannel )    {\
00103             (pAdc)->ADC_CHER = (1 << (dwChannel));\
00104         }
00105 
00106 #define ADC_DisableChannel(pAdc, dwChannel)  {\
00107             (pAdc)->ADC_CHDR = (1 << (dwChannel));\
00108         }
00109 
00110 #define ADC_EnableIt(pAdc, dwMode)            {\
00111             (pAdc)->ADC_IER = (dwMode);\
00112         }
00113 
00114 #define ADC_DisableIt(pAdc, dwMode)           {\
00115             (pAdc)->ADC_IDR = (dwMode);\
00116         }
00117 
00118 #define ADC_SetChannelGain(pAdc,dwMode)       {\
00119             (pAdc)->ADC_CGR = dwMode;\
00120         }
00121 
00122 #define ADC_SetChannelOffset(pAdc,dwMode)     {\
00123             (pAdc)->ADC_COR = dwMode;\
00124         }
00125 
00126 #define ADC_EnableDataReadyIt(pAdc)         ((pAdc)->ADC_IER = ADC_IER_DRDY)
00127 
00128 #define ADC_GetStatus(pAdc)                 ((pAdc)->ADC_ISR)
00129 
00130 #define ADC_GetCompareMode(pAdc)            (((pAdc)->ADC_EMR)& (ADC_EMR_CMPMODE_Msk))
00131 
00132 #define ADC_GetChannelStatus(pAdc)          ((pAdc)->ADC_CHSR)
00133 
00134 #define ADC_GetInterruptMaskStatus(pAdc)    ((pAdc)->ADC_IMR)
00135 
00136 #define ADC_GetLastConvertedData(pAdc)      ((pAdc)->ADC_LCDR)
00137 
00138 /*------------------------------------------------------------------------------
00139  *         Exported functions
00140  *------------------------------------------------------------------------------*/
00141 extern void ADC_Initialize( Adc* pAdc, uint32_t dwId );
00142 extern uint32_t ADC_SetClock( Adc* pAdc, uint32_t dwPres, uint32_t dwMck );
00143 extern void ADC_SetTiming( Adc* pAdc, uint32_t dwStartup, uint32_t dwTracking, 
00144         uint32_t dwSettling );
00145 extern void ADC_SetTrigger( Adc* pAdc, uint32_t dwTrgSel );
00146 extern void ADC_SetTriggerMode(Adc *pAdc, uint32_t dwMode);
00147 extern void ADC_SetLowResolution( Adc* pAdc, uint32_t bEnDis );
00148 extern void ADC_SetSleepMode( Adc *pAdc, uint8_t bEnDis );
00149 extern void ADC_SetFastWakeup( Adc *pAdc, uint8_t bEnDis );
00150 extern void ADC_SetSequenceMode( Adc *pAdc, uint8_t bEnDis );
00151 extern void ADC_SetSequence( Adc *pAdc, uint32_t dwSEQ1, uint32_t dwSEQ2 );
00152 extern void ADC_SetSequenceByList( Adc *pAdc, uint8_t ucChList[], uint8_t ucNumCh );
00153 extern void ADC_SetAnalogChange( Adc *pAdc, uint8_t bEnDis );
00154 extern void ADC_SetTagEnable( Adc *pAdc, uint8_t bEnDis );
00155 extern void ADC_SetCompareChannel( Adc* pAdc, uint32_t dwChannel ) ;
00156 extern void ADC_SetCompareMode( Adc* pAdc, uint32_t dwMode ) ;
00157 extern void ADC_SetComparisonWindow( Adc* pAdc, uint32_t dwHi_Lo ) ;
00158 extern uint8_t ADC_CheckConfiguration( Adc* pAdc, uint32_t dwMcK ) ;
00159 extern uint32_t ADC_GetConvertedData( Adc* pAdc, uint32_t dwChannel ) ;
00160 extern void ADC_SetTsAverage(Adc* pADC, uint32_t dwAvg2Conv);
00161 extern uint32_t ADC_GetTsXPosition(Adc *pADC);
00162 extern uint32_t ADC_GetTsYPosition(Adc *pADC);
00163 extern uint32_t ADC_GetTsPressure(Adc *pADC);
00164 extern void ADC_SetTsDebounce(Adc *pADC, uint32_t dwTime);
00165 extern void ADC_SetTsPenDetect(Adc* pADC, uint8_t bEnDis);
00166 extern void ADC_SetStartupTime( Adc *pAdc, uint32_t dwUs );
00167 extern void ADC_SetTrackingTime( Adc *pAdc, uint32_t dwNs );
00168 extern void ADC_SetTriggerPeriod(Adc *pAdc, uint32_t dwPeriod);
00169 extern void ADC_SetTsMode(Adc* pADC, uint32_t dwMode);
00170 extern void ADC_TsCalibration( Adc *pAdc );
00171 
00172 
00173 #ifdef __cplusplus
00174 }
00175 #endif
00176 
00177 #endif /* #ifndef _ADC_ */
00178 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines