lpc17xx_adc.h (11921B)
1 /********************************************************************** 2 * $Id$ lpc17xx_adc.h 2008-07-27 3 *//** 4 * @file lpc17xx_adc.h 5 * @brief Contains the NXP ABL typedefs for C standard types. 6 * It is intended to be used in ISO C conforming development 7 * environments and checks for this insofar as it is possible 8 * to do so. 9 * @version 2.0 10 * @date 27 Jul. 2008 11 * @author NXP MCU SW Application Team 12 * 13 * Copyright(C) 2008, NXP Semiconductor 14 * All rights reserved. 15 * 16 *********************************************************************** 17 * Software that is described herein is for illustrative purposes only 18 * which provides customers with programming information regarding the 19 * products. This software is supplied "AS IS" without any warranties. 20 * NXP Semiconductors assumes no responsibility or liability for the 21 * use of the software, conveys no license or title under any patent, 22 * copyright, or mask work right to the product. NXP Semiconductors 23 * reserves the right to make changes in the software without 24 * notification. NXP Semiconductors also make no representation or 25 * warranty that such application will be suitable for the specified 26 * use without further testing or modification. 27 * Permission to use, copy, modify, and distribute this software and its 28 * documentation is hereby granted, under NXP Semiconductors' 29 * relevant copyright in the software, without fee, provided that it 30 * is used in conjunction with NXP Semiconductors microcontrollers. This 31 * copyright, permission, and disclaimer notice must appear in all copies of 32 * this code. 33 **********************************************************************/ 34 35 /* Peripheral group ----------------------------------------------------------- */ 36 /** @defgroup ADC ADC (Analog-to-Digital Converter) 37 * @ingroup LPC1700CMSIS_FwLib_Drivers 38 * @{ 39 */ 40 41 #ifndef LPC17XX_ADC_H_ 42 #define LPC17XX_ADC_H_ 43 44 /* Includes ------------------------------------------------------------------- */ 45 #include "LPC17xx.h" 46 #include "lpc_types.h" 47 48 49 #ifdef __cplusplus 50 extern "C" 51 { 52 #endif 53 54 /* Private macros ------------------------------------------------------------- */ 55 /** @defgroup ADC_Private_Macros ADC Private Macros 56 * @{ 57 */ 58 59 /* -------------------------- BIT DEFINITIONS ----------------------------------- */ 60 /*********************************************************************//** 61 * Macro defines for ADC control register 62 **********************************************************************/ 63 /** Selects which of the AD0.0:7 pins is (are) to be sampled and converted */ 64 #define ADC_CR_CH_SEL(n) ((1UL << n)) 65 /** The APB clock (PCLK) is divided by (this value plus one) 66 * to produce the clock for the A/D */ 67 #define ADC_CR_CLKDIV(n) ((n<<8)) 68 /** Repeated conversions A/D enable bit */ 69 #define ADC_CR_BURST ((1UL<<16)) 70 /** ADC convert in power down mode */ 71 #define ADC_CR_PDN ((1UL<<21)) 72 /** Start mask bits */ 73 #define ADC_CR_START_MASK ((7UL<<24)) 74 /** Select Start Mode */ 75 #define ADC_CR_START_MODE_SEL(SEL) ((SEL<<24)) 76 /** Start conversion now */ 77 #define ADC_CR_START_NOW ((1UL<<24)) 78 /** Start conversion when the edge selected by bit 27 occurs on P2.10/EINT0 */ 79 #define ADC_CR_START_EINT0 ((2UL<<24)) 80 /** Start conversion when the edge selected by bit 27 occurs on P1.27/CAP0.1 */ 81 #define ADC_CR_START_CAP01 ((3UL<<24)) 82 /** Start conversion when the edge selected by bit 27 occurs on MAT0.1 */ 83 #define ADC_CR_START_MAT01 ((4UL<<24)) 84 /** Start conversion when the edge selected by bit 27 occurs on MAT0.3 */ 85 #define ADC_CR_START_MAT03 ((5UL<<24)) 86 /** Start conversion when the edge selected by bit 27 occurs on MAT1.0 */ 87 #define ADC_CR_START_MAT10 ((6UL<<24)) 88 /** Start conversion when the edge selected by bit 27 occurs on MAT1.1 */ 89 #define ADC_CR_START_MAT11 ((7UL<<24)) 90 /** Start conversion on a falling edge on the selected CAP/MAT signal */ 91 #define ADC_CR_EDGE ((1UL<<27)) 92 93 /*********************************************************************//** 94 * Macro defines for ADC Global Data register 95 **********************************************************************/ 96 /** When DONE is 1, this field contains result value of ADC conversion */ 97 #define ADC_GDR_RESULT(n) (((n>>4)&0xFFF)) 98 /** These bits contain the channel from which the LS bits were converted */ 99 #define ADC_GDR_CH(n) (((n>>24)&0x7)) 100 /** This bit is 1 in burst mode if the results of one or 101 * more conversions was (were) lost */ 102 #define ADC_GDR_OVERRUN_FLAG ((1UL<<30)) 103 /** This bit is set to 1 when an A/D conversion completes */ 104 #define ADC_GDR_DONE_FLAG ((1UL<<31)) 105 106 /** This bits is used to mask for Channel */ 107 #define ADC_GDR_CH_MASK ((7UL<<24)) 108 /*********************************************************************//** 109 * Macro defines for ADC Interrupt register 110 **********************************************************************/ 111 /** These bits allow control over which A/D channels generate 112 * interrupts for conversion completion */ 113 #define ADC_INTEN_CH(n) ((1UL<<n)) 114 /** When 1, enables the global DONE flag in ADDR to generate an interrupt */ 115 #define ADC_INTEN_GLOBAL ((1UL<<8)) 116 117 /*********************************************************************//** 118 * Macro defines for ADC Data register 119 **********************************************************************/ 120 /** When DONE is 1, this field contains result value of ADC conversion */ 121 #define ADC_DR_RESULT(n) (((n>>4)&0xFFF)) 122 /** These bits mirror the OVERRRUN status flags that appear in the 123 * result register for each A/D channel */ 124 #define ADC_DR_OVERRUN_FLAG ((1UL<<30)) 125 /** This bit is set to 1 when an A/D conversion completes. It is cleared 126 * when this register is read */ 127 #define ADC_DR_DONE_FLAG ((1UL<<31)) 128 129 /*********************************************************************//** 130 * Macro defines for ADC Status register 131 **********************************************************************/ 132 /** These bits mirror the DONE status flags that appear in the result 133 * register for each A/D channel */ 134 #define ADC_STAT_CH_DONE_FLAG(n) ((n&0xFF)) 135 /** These bits mirror the OVERRRUN status flags that appear in the 136 * result register for each A/D channel */ 137 #define ADC_STAT_CH_OVERRUN_FLAG(n) (((n>>8)&0xFF)) 138 /** This bit is the A/D interrupt flag */ 139 #define ADC_STAT_INT_FLAG ((1UL<<16)) 140 141 /*********************************************************************//** 142 * Macro defines for ADC Trim register 143 **********************************************************************/ 144 /** Offset trim bits for ADC operation */ 145 #define ADC_ADCOFFS(n) (((n&0xF)<<4)) 146 /** Written to boot code*/ 147 #define ADC_TRIM(n) (((n&0xF)<<8)) 148 149 /* ------------------- CHECK PARAM DEFINITIONS ------------------------- */ 150 /** Check ADC parameter */ 151 #define PARAM_ADCx(n) (((uint32_t *)n)==((uint32_t *)LPC_ADC)) 152 153 /** Check ADC state parameter */ 154 #define PARAM_ADC_START_ON_EDGE_OPT(OPT) ((OPT == ADC_START_ON_RISING)||(OPT == ADC_START_ON_FALLING)) 155 156 /** Check ADC state parameter */ 157 #define PARAM_ADC_DATA_STATUS(OPT) ((OPT== ADC_DATA_BURST)||(OPT== ADC_DATA_DONE)) 158 159 /** Check ADC rate parameter */ 160 #define PARAM_ADC_RATE(rate) ((rate>0)&&(rate<=200000)) 161 162 /** Check ADC channel selection parameter */ 163 #define PARAM_ADC_CHANNEL_SELECTION(SEL) ((SEL == ADC_CHANNEL_0)||(ADC_CHANNEL_1)\ 164 ||(SEL == ADC_CHANNEL_2)|(ADC_CHANNEL_3)\ 165 ||(SEL == ADC_CHANNEL_4)||(ADC_CHANNEL_5)\ 166 ||(SEL == ADC_CHANNEL_6)||(ADC_CHANNEL_7)) 167 168 /** Check ADC start option parameter */ 169 #define PARAM_ADC_START_OPT(OPT) ((OPT == ADC_START_CONTINUOUS)||(OPT == ADC_START_NOW)\ 170 ||(OPT == ADC_START_ON_EINT0)||(OPT == ADC_START_ON_CAP01)\ 171 ||(OPT == ADC_START_ON_MAT01)||(OPT == ADC_START_ON_MAT03)\ 172 ||(OPT == ADC_START_ON_MAT10)||(OPT == ADC_START_ON_MAT11)) 173 174 /** Check ADC interrupt type parameter */ 175 #define PARAM_ADC_TYPE_INT_OPT(OPT) ((OPT == ADC_ADINTEN0)||(OPT == ADC_ADINTEN1)\ 176 ||(OPT == ADC_ADINTEN2)||(OPT == ADC_ADINTEN3)\ 177 ||(OPT == ADC_ADINTEN4)||(OPT == ADC_ADINTEN5)\ 178 ||(OPT == ADC_ADINTEN6)||(OPT == ADC_ADINTEN7)\ 179 ||(OPT == ADC_ADGINTEN)) 180 181 /** 182 * @} 183 */ 184 185 186 /* Public Types --------------------------------------------------------------- */ 187 /** @defgroup ADC_Public_Types ADC Public Types 188 * @{ 189 */ 190 191 /*********************************************************************//** 192 * @brief ADC enumeration 193 **********************************************************************/ 194 /** @brief Channel Selection */ 195 typedef enum 196 { 197 ADC_CHANNEL_0 = 0, /*!< Channel 0 */ 198 ADC_CHANNEL_1, /*!< Channel 1 */ 199 ADC_CHANNEL_2, /*!< Channel 2 */ 200 ADC_CHANNEL_3, /*!< Channel 3 */ 201 ADC_CHANNEL_4, /*!< Channel 4 */ 202 ADC_CHANNEL_5, /*!< Channel 5 */ 203 ADC_CHANNEL_6, /*!< Channel 6 */ 204 ADC_CHANNEL_7 /*!< Channel 7 */ 205 }ADC_CHANNEL_SELECTION; 206 207 /** @brief Type of start option */ 208 typedef enum 209 { 210 ADC_START_CONTINUOUS =0, /*!< Continuous mode */ 211 ADC_START_NOW, /*!< Start conversion now */ 212 ADC_START_ON_EINT0, /*!< Start conversion when the edge selected 213 * by bit 27 occurs on P2.10/EINT0 */ 214 ADC_START_ON_CAP01, /*!< Start conversion when the edge selected 215 * by bit 27 occurs on P1.27/CAP0.1 */ 216 ADC_START_ON_MAT01, /*!< Start conversion when the edge selected 217 * by bit 27 occurs on MAT0.1 */ 218 ADC_START_ON_MAT03, /*!< Start conversion when the edge selected 219 * by bit 27 occurs on MAT0.3 */ 220 ADC_START_ON_MAT10, /*!< Start conversion when the edge selected 221 * by bit 27 occurs on MAT1.0 */ 222 ADC_START_ON_MAT11 /*!< Start conversion when the edge selected 223 * by bit 27 occurs on MAT1.1 */ 224 } ADC_START_OPT; 225 226 227 /** @brief Type of edge when start conversion on the selected CAP/MAT signal */ 228 typedef enum 229 { 230 ADC_START_ON_RISING = 0, /*!< Start conversion on a rising edge 231 *on the selected CAP/MAT signal */ 232 ADC_START_ON_FALLING /*!< Start conversion on a falling edge 233 *on the selected CAP/MAT signal */ 234 } ADC_START_ON_EDGE_OPT; 235 236 /** @brief* ADC type interrupt enum */ 237 typedef enum 238 { 239 ADC_ADINTEN0 = 0, /*!< Interrupt channel 0 */ 240 ADC_ADINTEN1, /*!< Interrupt channel 1 */ 241 ADC_ADINTEN2, /*!< Interrupt channel 2 */ 242 ADC_ADINTEN3, /*!< Interrupt channel 3 */ 243 ADC_ADINTEN4, /*!< Interrupt channel 4 */ 244 ADC_ADINTEN5, /*!< Interrupt channel 5 */ 245 ADC_ADINTEN6, /*!< Interrupt channel 6 */ 246 ADC_ADINTEN7, /*!< Interrupt channel 7 */ 247 ADC_ADGINTEN /*!< Individual channel/global flag done generate an interrupt */ 248 }ADC_TYPE_INT_OPT; 249 250 /** @brief ADC Data status */ 251 typedef enum 252 { 253 ADC_DATA_BURST = 0, /*Burst bit*/ 254 ADC_DATA_DONE /*Done bit*/ 255 }ADC_DATA_STATUS; 256 257 /** 258 * @} 259 */ 260 261 262 /* Public Functions ----------------------------------------------------------- */ 263 /** @defgroup ADC_Public_Functions ADC Public Functions 264 * @{ 265 */ 266 /* Init/DeInit ADC peripheral ----------------*/ 267 void ADC_Init(LPC_ADC_TypeDef *ADCx, uint32_t rate); 268 void ADC_DeInit(LPC_ADC_TypeDef *ADCx); 269 270 /* Enable/Disable ADC functions --------------*/ 271 void ADC_BurstCmd(LPC_ADC_TypeDef *ADCx, FunctionalState NewState); 272 void ADC_PowerdownCmd(LPC_ADC_TypeDef *ADCx, FunctionalState NewState); 273 void ADC_StartCmd(LPC_ADC_TypeDef *ADCx, uint8_t start_mode); 274 void ADC_ChannelCmd (LPC_ADC_TypeDef *ADCx, uint8_t Channel, FunctionalState NewState); 275 276 /* Configure ADC functions -------------------*/ 277 void ADC_EdgeStartConfig(LPC_ADC_TypeDef *ADCx, uint8_t EdgeOption); 278 void ADC_IntConfig (LPC_ADC_TypeDef *ADCx, ADC_TYPE_INT_OPT IntType, FunctionalState NewState); 279 280 /* Get ADC information functions -------------------*/ 281 uint16_t ADC_ChannelGetData(LPC_ADC_TypeDef *ADCx, uint8_t channel); 282 FlagStatus ADC_ChannelGetStatus(LPC_ADC_TypeDef *ADCx, uint8_t channel, uint32_t StatusType); 283 uint32_t ADC_GlobalGetData(LPC_ADC_TypeDef *ADCx); 284 FlagStatus ADC_GlobalGetStatus(LPC_ADC_TypeDef *ADCx, uint32_t StatusType); 285 uint32_t ADC_GetData(uint32_t channel); 286 287 /** 288 * @} 289 */ 290 291 292 #ifdef __cplusplus 293 } 294 #endif 295 296 297 #endif /* LPC17XX_ADC_H_ */ 298 299 /** 300 * @} 301 */ 302 303 /* --------------------------------- End Of File ------------------------------ */