2 * @brief ADC Registers and control functions
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #ifndef __ADC_001_H_
\r
33 #define __ADC_001_H_
\r
35 #include "sys_config.h"
\r
42 /** @defgroup IP_ADC_001 IP: 10 or 12-bit ADC register block and driver
\r
43 * @ingroup IP_Drivers
\r
47 #if defined(CHIP_LPC177X_8X) || defined(CHIP_LPC407X_8X) || defined(CHIP_LPC1347) || defined(CHIP_LPC175X_6X)
\r
48 #define ADC_ACC_12BITS
\r
49 #define ADC_TRIM_SUPPORT
\r
51 #define ADC_ACC_10BITS
\r
55 * @brief 10 or 12-bit ADC register block structure
\r
57 typedef struct { /*!< ADCn Structure */
\r
58 __IO uint32_t CR; /*!< A/D Control Register. The AD0CR register must be written to select the operating mode before A/D conversion can occur. */
\r
59 __I uint32_t GDR; /*!< A/D Global Data Register. Contains the result of the most recent A/D conversion. */
\r
60 __I uint32_t RESERVED0;
\r
61 __IO uint32_t INTEN; /*!< A/D Interrupt Enable Register. This register contains enable bits that allow the DONE flag of each A/D channel to be included or excluded from contributing to the generation of an A/D interrupt. */
\r
62 __I uint32_t DR[8]; /*!< A/D Channel Data Register. This register contains the result of the most recent conversion completed on channel n. */
\r
63 __I uint32_t STAT; /*!< A/D Status Register. This register contains DONE and OVERRUN flags for all of the A/D channels, as well as the A/D interrupt flag. */
\r
64 #if defined(ADC_TRIM_SUPPORT)
\r
65 __IO uint32_t ADTRM;
\r
70 * @brief ADC register support bitfields and mask
\r
72 #if defined(ADC_ACC_12BITS)
\r
73 #define ADC_DR_RESULT(n) ((((n) >> 4) & 0xFFF)) /*!< Mask for getting the 12 bits ADC data read value */
\r
75 #define ADC_DR_RESULT(n) ((((n) >> 6) & 0x3FF)) /*!< Mask for getting the 10 bits ADC data read value */
\r
76 #define ADC_CR_BITACC(n) ((((n) & 0x7) << 17)) /*!< Number of ADC accuracy bits */
\r
79 #define ADC_DR_DONE(n) (((n) >> 31)) /*!< Mask for reading the ADC done status */
\r
80 #define ADC_DR_OVERRUN(n) ((((n) >> 30) & (1UL))) /*!< Mask for reading the ADC overrun status */
\r
81 #define ADC_CR_CH_SEL(n) ((1UL << (n))) /*!< Selects which of the AD0.0:7 pins is (are) to be sampled and converted */
\r
82 #define ADC_CR_CLKDIV(n) ((((n) & 0xFF) << 8)) /*!< The APB clock (PCLK) is divided by (this value plus one) to produce the clock for the A/D */
\r
83 #define ADC_CR_BURST ((1UL << 16)) /*!< Repeated conversions A/D enable bit */
\r
84 #if defined(CHIP_LPC1347)
\r
85 #define ADC_CR_LPWRMODE ((1UL << 22)) /*!<Enable the low-power ADC mode */
\r
86 #define ADC_CR_MODE10BIT ((1UL << 23)) /*!<Enable the 10-bit conversion rate mode with high conversion rate. */
\r
88 #define ADC_CR_PDN ((1UL << 21)) /*!< ADC convert is operational */
\r
90 #define ADC_CR_START_MASK ((7UL << 24)) /*!< ADC start mask bits */
\r
91 #define ADC_CR_START_MODE_SEL(SEL) ((SEL << 24)) /*!< Select Start Mode */
\r
92 #define ADC_CR_START_NOW ((1UL << 24)) /*!< Start conversion now */
\r
93 #define ADC_CR_START_CTOUT15 ((2UL << 24)) /*!< Start conversion when the edge selected by bit 27 occurs on CTOUT_15 */
\r
94 #define ADC_CR_START_CTOUT8 ((3UL << 24)) /*!< Start conversion when the edge selected by bit 27 occurs on CTOUT_8 */
\r
95 #define ADC_CR_START_ADCTRIG0 ((4UL << 24)) /*!< Start conversion when the edge selected by bit 27 occurs on ADCTRIG0 */
\r
96 #define ADC_CR_START_ADCTRIG1 ((5UL << 24)) /*!< Start conversion when the edge selected by bit 27 occurs on ADCTRIG1 */
\r
97 #define ADC_CR_START_MCOA2 ((6UL << 24)) /*!< Start conversion when the edge selected by bit 27 occurs on Motocon PWM output MCOA2 */
\r
98 #define ADC_CR_EDGE ((1UL << 27)) /*!< Start conversion on a falling edge on the selected CAP/MAT signal */
\r
99 #if defined(CHIP_LPC1347)
\r
100 #define ADC_CONFIG_MASK (ADC_CR_CLKDIV(0xFF) | ADC_CR_LPWRMODE | ADC_CR_MODE10BIT)
\r
101 #elif defined(CHIP_LPC1343)
\r
102 #define ADC_CONFIG_MASK (ADC_CR_CLKDIV(0xFF) | ADC_CR_BITACC(0x07))
\r
103 #elif defined(ADC_ACC_12BITS)
\r
104 #define ADC_CONFIG_MASK (ADC_CR_CLKDIV(0xFF) | ADC_CR_PDN)
\r
106 #define ADC_CONFIG_MASK (ADC_CR_CLKDIV(0xFF) | ADC_CR_BITACC(0x07) | ADC_CR_PDN)
\r
110 * @brief ADC status register used for IP drivers
\r
112 typedef enum IP_ADC_STATUS {
\r
113 ADC_DR_DONE_STAT, /*!< ADC data register staus */
\r
114 ADC_DR_OVERRUN_STAT,/*!< ADC data overrun staus */
\r
115 ADC_DR_ADINT_STAT /*!< ADC interrupt status */
\r
119 * @brief Initialize for ADC
\r
120 * @param pADC : The base of ADC peripheral on the chip
\r
121 * @param div : Clock divide value
\r
122 * @param bitsAcc : Number of bits of accuracy of the conversion result
\r
123 * @param flag : ADC mode flag.
\r
125 * @note bitsAcc only make sense in 10-bit converter. And, it should be ADC_3BITS ->ADC_10BITS.
\r
126 * ADC mode flag is or-ed bit values of the following flags:
\r
127 * - ADC_CR_PDN: The A/D converter is operational. If this flag isn't set, the ADC is in
\r
128 * power-down mode. This flag isn't available in LPC13xx.
\r
129 * - ADC_CR_LPWRMODE: The analog circuitry is automatically powered-down when no conversions
\r
130 * are taking place. This flag is only available in LPC1347.
\r
131 * - ADC_CR_MODE10BIT: Enable the 10-bit conversion rate mode with high conversion rate.
\r
132 * This flag is only available in LPC1347.
\r
134 void IP_ADC_Init(IP_ADC_001_T *pADC, uint8_t div, uint8_t bitsAcc, uint32_t flag);
\r
137 * @brief Shutdown ADC
\r
138 * @param pADC : The base of ADC peripheral on the chip
\r
140 * @note Reset the ADC control and INTEN Register to reset values (disabled)
\r
142 void IP_ADC_DeInit(IP_ADC_001_T *pADC);
\r
145 * @brief Set burst mode for ADC
\r
146 * @param pADC : The base of ADC peripheral on the chip
\r
147 * @param NewState : ENABLE for burst mode, or DISABLE for normal mode
\r
150 void IP_ADC_SetBurstMode(IP_ADC_001_T *pADC, FunctionalState NewState);
\r
153 * @brief Get the ADC value
\r
154 * @param pADC : The base of ADC peripheral on the chip
\r
155 * @param channel : Channel to be read value, should be 0..7
\r
156 * @param data : Data buffer to store the A/D value
\r
157 * @return Status : SUCCESS or ERROR
\r
159 Status IP_ADC_Get_Val(IP_ADC_001_T *pADC, uint8_t channel, uint16_t *data);
\r
162 * @brief Get ADC Channel status from ADC data register
\r
163 * @param pADC : The base of ADC peripheral on the chip
\r
164 * @param channel : Channel number, should be 0..7
\r
165 * @param StatusType : Register to read, ADC_DR_DONE_STAT, ADC_DR_OVERRUN_STAT, or ADC_DR_ADINT_STAT
\r
166 * @return Channel status, SET or RESET
\r
168 FlagStatus IP_ADC_GetStatus(IP_ADC_001_T *pADC, uint8_t channel, uint32_t StatusType);
\r
171 * @brief Set the edge start condition
\r
172 * @param pADC : The base of ADC peripheral on the chip
\r
173 * @param edge_mode : 0 = rising, !0 = falling
\r
176 void IP_ADC_EdgeStartConfig(IP_ADC_001_T *pADC, uint8_t edge_mode);
\r
179 * @brief Enable/Disable ADC channel number
\r
180 * @param pADC : The base of ADC peripheral on the chip
\r
181 * @param channel : Channel number
\r
182 * @param NewState : New state, ENABLE or DISABLE
\r
185 void IP_ADC_SetChannelNumber(IP_ADC_001_T *pADC, uint8_t channel, FunctionalState NewState);
\r
188 * @brief Set start mode for ADC
\r
189 * @param pADC : The base of ADC peripheral on the chip
\r
190 * @param start_mode : Start mode choose one of modes in 'ADC_START_*' enumeration type definitions
\r
193 void IP_ADC_SetStartMode(IP_ADC_001_T *pADC, uint8_t start_mode);
\r
196 * @brief Enable/Disable interrupt for ADC channel
\r
197 * @param pADC : The base of ADC peripheral on the chip
\r
198 * @param channel : Channel assert the interrupt
\r
199 * @param NewState : New state, ENABLE or DISABLE
\r
202 void IP_ADC_Int_Enable(IP_ADC_001_T *pADC, uint8_t channel, FunctionalState NewState);
\r
212 #endif /* __ADC_001_H_ */
\r