2 * @brief LPC18xx/43xx A/D conversion driver
\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_18XX_43XX_H_
\r
33 #define __ADC_18XX_43XX_H_
\r
39 /** @defgroup ADC_18XX_43XX CHIP: LPC18xx/43xx A/D conversion driver
\r
40 * @ingroup CHIP_18XX_43XX_Drivers
\r
44 /** The channels on one ADC peripheral*/
\r
45 typedef enum CHIP_ADC_CHANNEL {
\r
46 ADC_CH0 = 0, /**< ADC channel 0 */
\r
47 ADC_CH1, /**< ADC channel 1 */
\r
48 ADC_CH2, /**< ADC channel 2 */
\r
49 ADC_CH3, /**< ADC channel 3 */
\r
50 ADC_CH4, /**< ADC channel 4 */
\r
51 ADC_CH5, /**< ADC channel 5 */
\r
52 ADC_CH6, /**< ADC channel 6 */
\r
53 ADC_CH7, /**< ADC channel 7 */
\r
54 } CHIP_ADC_CHANNEL_T;
\r
56 /** The number of bits of accuracy of the result in the LS bits of ADDR*/
\r
57 typedef enum CHIP_ADC_RESOLUTION {
\r
58 ADC_10BITS = 0, /**< ADC 10 bits */
\r
59 ADC_9BITS, /**< ADC 9 bits */
\r
60 ADC_8BITS, /**< ADC 8 bits */
\r
61 ADC_7BITS, /**< ADC 7 bits */
\r
62 ADC_6BITS, /**< ADC 6 bits */
\r
63 ADC_5BITS, /**< ADC 5 bits */
\r
64 ADC_4BITS, /**< ADC 4 bits */
\r
65 ADC_3BITS, /**< ADC 3 bits */
\r
66 } CHIP_ADC_RESOLUTION_T;
\r
68 /** Edge configuration, which controls rising or falling edge on the selected signal for the start of a conversion */
\r
69 typedef enum CHIP_ADC_EDGE_CFG {
\r
70 ADC_TRIGGERMODE_RISING = 0, /**< Trigger event: rising edge */
\r
71 ADC_TRIGGERMODE_FALLING, /**< Trigger event: falling edge */
\r
72 } CHIP_ADC_EDGE_CFG_T;
\r
74 /** Start mode, which controls the start of an A/D conversion when the BURST bit is 0. */
\r
75 typedef enum CHIP_ADC_START_MODE {
\r
77 ADC_START_NOW, /*!< Start conversion now */
\r
78 ADC_START_ON_CTOUT15, /*!< Start conversion when the edge selected by bit 27 occurs on CTOUT_15 */
\r
79 ADC_START_ON_CTOUT8, /*!< Start conversion when the edge selected by bit 27 occurs on CTOUT_8 */
\r
80 ADC_START_ON_ADCTRIG0, /*!< Start conversion when the edge selected by bit 27 occurs on ADCTRIG0 */
\r
81 ADC_START_ON_ADCTRIG1, /*!< Start conversion when the edge selected by bit 27 occurs on ADCTRIG1 */
\r
82 ADC_START_ON_MCOA2 /*!< Start conversion when the edge selected by bit 27 occurs on Motocon PWM output MCOA2 */
\r
83 } CHIP_ADC_START_MODE_T;
\r
85 /** Clock setup structure for ADC controller passed to the initialize function */
\r
87 uint32_t adcRate; /*!< ADC rate */
\r
88 uint8_t bitsAccuracy; /*!< ADC bit accuracy */
\r
89 bool burstMode; /*!< ADC Burt Mode */
\r
90 } ADC_Clock_Setup_T;
\r
93 * @brief Read the ADC value from a channel
\r
94 * @param pADC : The base of ADC peripheral on the chip
\r
95 * @param channel : ADC channel to read
\r
96 * @param data : Pointer to where to put data
\r
97 * @return SUCCESS or ERROR if no conversion is ready
\r
99 STATIC INLINE Status Chip_ADC_Read_Value(LPC_ADC_T *pADC, uint8_t channel, uint16_t *data)
\r
101 return IP_ADC_Get_Val(pADC, channel, data);
\r
105 * @brief Read the ADC channel status
\r
106 * @param pADC : The base of ADC peripheral on the chip
\r
107 * @param channel : ADC channel to read
\r
108 * @param StatusType : Status type of ADC_DR_*
\r
109 * @return SET or RESET
\r
111 STATIC INLINE FlagStatus Chip_ADC_Read_Status(LPC_ADC_T *pADC, uint8_t channel, uint32_t StatusType)
\r
113 return IP_ADC_GetStatus(pADC, channel, StatusType);
\r
117 * @brief Enable/Disable interrupt for ADC channel
\r
118 * @param pADC : The base of ADC peripheral on the chip
\r
119 * @param channel : ADC channel to read
\r
120 * @param NewState : New state, ENABLE or DISABLE
\r
121 * @return SET or RESET
\r
123 STATIC INLINE void Chip_ADC_Channel_Int_Cmd(LPC_ADC_T *pADC, uint8_t channel, FunctionalState NewState)
\r
125 IP_ADC_Int_Enable(pADC, channel, NewState);
\r
129 * @brief Enable/Disable global interrupt for ADC channel
\r
130 * @param pADC : The base of ADC peripheral on the chip
\r
131 * @param NewState : New state, ENABLE or DISABLE
\r
134 STATIC INLINE void Chip_ADC_Global_Int_Cmd(LPC_ADC_T *pADC, FunctionalState NewState)
\r
136 IP_ADC_Int_Enable(pADC, 8, NewState);
\r
140 * @brief Shutdown ADC
\r
141 * @param pADC : The base of ADC peripheral on the chip
\r
144 void Chip_ADC_DeInit(LPC_ADC_T *pADC);
\r
147 * @brief Initialize the ADC peripheral and the ADC setup structure to default value
\r
148 * @param pADC : The base of ADC peripheral on the chip
\r
149 * @param ADCSetup : ADC setup structure to be set
\r
151 * @note Default setting for ADC is 400kHz - 10bits
\r
153 void Chip_ADC_Init(LPC_ADC_T *pADC, ADC_Clock_Setup_T *ADCSetup);
\r
156 * @brief Select the mode starting the AD conversion
\r
157 * @param pADC : The base of ADC peripheral on the chip
\r
158 * @param mode : Stating mode, should be :
\r
159 * - ADC_NO_START : Must be set for Burst mode
\r
160 * - ADC_START_NOW : Start conversion now
\r
161 * - ADC_START_ON_CTOUT15 : Start conversion when the edge selected by bit 27 occurs on CTOUT_15
\r
162 * - ADC_START_ON_CTOUT8 : Start conversion when the edge selected by bit 27 occurs on CTOUT_8
\r
163 * - ADC_START_ON_ADCTRIG0 : Start conversion when the edge selected by bit 27 occurs on ADCTRIG0
\r
164 * - ADC_START_ON_ADCTRIG1 : Start conversion when the edge selected by bit 27 occurs on ADCTRIG1
\r
165 * - ADC_START_ON_MCOA2 : Start conversion when the edge selected by bit 27 occurs on Motocon PWM output MCOA2
\r
166 * @param EdgeOption : Stating Edge Condition, should be :
\r
167 * - ADC_TRIGGERMODE_RISING : Trigger event on rising edge
\r
168 * - ADC_TRIGGERMODE_FALLING : Trigger event on falling edge
\r
171 void Chip_ADC_Set_StartMode(LPC_ADC_T *pADC, CHIP_ADC_START_MODE_T mode, CHIP_ADC_EDGE_CFG_T EdgeOption);
\r
174 * @brief Set the ADC Sample rate
\r
175 * @param pADC : The base of ADC peripheral on the chip
\r
176 * @param ADCSetup : ADC setup structure to be modified
\r
177 * @param rate : Sample rate, should be set so the clock for A/D converter is less than or equal to 4.5MHz.
\r
180 void Chip_ADC_Set_SampleRate(LPC_ADC_T *pADC, ADC_Clock_Setup_T *ADCSetup, uint32_t rate);
\r
183 * @brief Set the ADC accuracy bits
\r
184 * @param pADC : The base of ADC peripheral on the chip
\r
185 * @param ADCSetup : ADC setup structure to be modified
\r
186 * @param resolution : The resolution, should be ADC_10BITS -> ADC_3BITS
\r
189 void Chip_ADC_Set_Resolution(LPC_ADC_T *pADC, ADC_Clock_Setup_T *ADCSetup, CHIP_ADC_RESOLUTION_T resolution);
\r
192 * @brief Enable or disable the ADC channel on ADC peripheral
\r
193 * @param pADC : The base of ADC peripheral on the chip
\r
194 * @param channel : Channel to be enable or disable
\r
195 * @param NewState : New state, should be:
\r
200 void Chip_ADC_Channel_Enable_Cmd(LPC_ADC_T *pADC, CHIP_ADC_CHANNEL_T channel, FunctionalState NewState);
\r
203 * @brief Enable burst mode
\r
204 * @param pADC : The base of ADC peripheral on the chip
\r
205 * @param NewState : New state, should be:
\r
210 void Chip_ADC_Burst_Cmd(LPC_ADC_T *pADC, FunctionalState NewState);
\r
213 * @brief Read the ADC value and convert it to 8bits value
\r
214 * @param pADC : The base of ADC peripheral on the chip
\r
215 * @param channel: selected channel
\r
216 * @param data : Storage for data
\r
217 * @return Status : ERROR or SUCCESS
\r
219 Status Chip_ADC_Read_Byte(LPC_ADC_T *pADC, CHIP_ADC_CHANNEL_T channel, uint8_t *data);
\r
229 #endif /* __ADC_18XX_43XX_H_ */
\r