LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
adc_18xx_43xx.c
Go to the documentation of this file.
1
/*
2
* @brief LPC18xx/43xx A/D conversion driver
3
*
4
* @note
5
* Copyright(C) NXP Semiconductors, 2012
6
* All rights reserved.
7
*
8
* @par
9
* Software that is described herein is for illustrative purposes only
10
* which provides customers with programming information regarding the
11
* LPC products. This software is supplied "AS IS" without any warranties of
12
* any kind, and NXP Semiconductors and its licensor disclaim any and
13
* all warranties, express or implied, including all implied warranties of
14
* merchantability, fitness for a particular purpose and non-infringement of
15
* intellectual property rights. NXP Semiconductors assumes no responsibility
16
* or liability for the use of the software, conveys no license or rights under any
17
* patent, copyright, mask work right, or any other intellectual property rights in
18
* or to any products. NXP Semiconductors reserves the right to make changes
19
* in the software without notification. NXP Semiconductors also makes no
20
* representation or warranty that such application will be suitable for the
21
* specified use without further testing or modification.
22
*
23
* @par
24
* Permission to use, copy, modify, and distribute this software and its
25
* documentation is hereby granted, under NXP Semiconductors' and its
26
* licensor's relevant copyrights in the software, without fee, provided that it
27
* is used in conjunction with NXP Semiconductors microcontrollers. This
28
* copyright, permission, and disclaimer notice must appear in all copies of
29
* this code.
30
*/
31
32
#include "
adc_18xx_43xx.h
"
33
34
/*****************************************************************************
35
* Private types/enumerations/variables
36
****************************************************************************/
37
38
/*The channel to be operated on */
39
static
uint8_t
active_channel
;
40
41
/*****************************************************************************
42
* Public types/enumerations/variables
43
****************************************************************************/
44
45
/*****************************************************************************
46
* Private functions
47
****************************************************************************/
48
49
/* Returns the clock for the selected ADC */
50
static
CCU_CLK_T
Chip_ADC_GetClk
(
LPC_ADC_Type
*pADC)
51
{
52
CCU_CLK_T
adcclk;
53
54
if
(pADC ==
LPC_ADC0
) {
55
adcclk =
CLK_APB3_ADC0
;
56
}
57
else
{
58
adcclk =
CLK_APB3_ADC1
;
59
}
60
61
return
adcclk;
62
}
63
64
/*****************************************************************************
65
* Public functions
66
****************************************************************************/
67
68
/* Initialize the ADC peripheral and the ADC setup structure to default value */
69
void
Chip_ADC_Init
(
LPC_ADC_Type
*pADC,
ADC_Clock_Setup_Type
*
ADCSetup
)
70
{
71
CCU_CLK_T
adcclk =
Chip_ADC_GetClk
(pADC);
72
73
/* Enable ADC clocking */
74
Chip_Clock_EnableOpts
(adcclk,
true
,
true
, 1);
75
ADCSetup->
adcPerClock
=
Chip_Clock_GetRate
(adcclk);
76
77
ADCSetup->
adcRate
= 400000;
78
ADCSetup->
bitsAccuracy
=
ADC_10BITS
;
79
IP_ADC_Init
(pADC, ADCSetup->
adcRate
, ADCSetup->
adcPerClock
, ADCSetup->
bitsAccuracy
);
80
}
81
82
/* Select the mode starting the AD conversion */
83
void
Chip_ADC_Set_StartMode
(
LPC_ADC_Type
*pADC,
ADC_StartMode
mode
,
ADC_EdgeCfg
EdgeOption)
84
{
85
if
((mode !=
ADC_START_NOW
) && (mode !=
ADC_NO_START
)) {
86
IP_ADC_EdgeStartConfig
(pADC, (uint8_t) EdgeOption);
87
}
88
IP_ADC_SetStartMode
(pADC, (uint8_t) mode);
89
}
90
91
/* Set the ADC Sample rate */
92
void
Chip_ADC_Set_SampleRate
(
LPC_ADC_Type
*pADC,
ADC_Clock_Setup_Type
*
ADCSetup
,
uint32_t
rate)
93
{
94
ADCSetup->
adcRate
= rate;
95
IP_ADC_Init
(pADC, ADCSetup->
adcRate
, ADCSetup->
adcPerClock
, ADCSetup->
bitsAccuracy
);
96
97
}
98
99
/* Set the ADC accuracy bits */
100
void
Chip_ADC_Set_Resolution
(
LPC_ADC_Type
*pADC,
ADC_Clock_Setup_Type
*
ADCSetup
,
ADC_Resolution
resolution)
101
{
102
ADCSetup->
bitsAccuracy
= resolution;
103
IP_ADC_Init
(pADC, ADCSetup->
adcRate
, ADCSetup->
adcPerClock
, ADCSetup->
bitsAccuracy
);
104
}
105
106
/* Enable or disable the ADC channel on ADC peripheral */
107
void
Chip_ADC_Channel_Enable_Cmd
(
LPC_ADC_Type
*pADC,
ADC_Channel
channel,
FunctionalState
NewState)
108
{
109
IP_ADC_SetChannelNumber
(pADC, channel, NewState);
110
active_channel
= channel;
111
}
112
113
/* Enable burst mode */
114
void
Chip_ADC_Burst_Cmd
(
LPC_ADC_Type
*pADC,
FunctionalState
NewState)
115
{
116
IP_ADC_SetStartMode
(pADC,
ADC_NO_START
);
117
IP_ADC_SetBurstMode
(pADC, NewState);
118
}
119
120
/* Read the ADC value and convert it to 8bits value */
121
Status
Chip_ADC_Read_Byte
(
LPC_ADC_Type
*pADC, uint8_t *data)
122
{
123
uint16_t temp;
124
Status
rt;
125
126
rt =
IP_ADC_Get_Val
(pADC,
active_channel
, &temp);
127
*data = (uint8_t) temp;
128
129
return
rt;
130
}
131
132
/* Set a channel to be read A/D data */
133
void
Chip_ADC_Active_Channel
(uint8_t channel)
134
{
135
active_channel
= channel;
136
}
software
lpc_core
lpc_chip
chip_18xx_43xx
adc_18xx_43xx.c
Generated on Fri Nov 16 2012 13:36:40 for LPCOpen Platform by
1.8.2