LPCOpen Platform
v1.03
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Modules
Data Structures
Files
Related Pages
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
acmp_001.c
Go to the documentation of this file.
1
/*
2
* Copyright(C) NXP Semiconductors, 2012
3
* All rights reserved.
4
*
5
* Software that is described herein is for illustrative purposes only
6
* which provides customers with programming information regarding the
7
* LPC products. This software is supplied "AS IS" without any warranties of
8
* any kind, and NXP Semiconductors and its licensor disclaim any and
9
* all warranties, express or implied, including all implied warranties of
10
* merchantability, fitness for a particular purpose and non-infringement of
11
* intellectual property rights. NXP Semiconductors assumes no responsibility
12
* or liability for the use of the software, conveys no license or rights under any
13
* patent, copyright, mask work right, or any other intellectual property rights in
14
* or to any products. NXP Semiconductors reserves the right to make changes
15
* in the software without notification. NXP Semiconductors also makes no
16
* representation or warranty that such application will be suitable for the
17
* specified use without further testing or modification.
18
*
19
* Permission to use, copy, modify, and distribute this software and its
20
* documentation is hereby granted, under NXP Semiconductors' and its
21
* licensor's relevant copyrights in the software, without fee, provided that it
22
* is used in conjunction with NXP Semiconductors microcontrollers. This
23
* copyright, permission, and disclaimer notice must appear in all copies of
24
* this code.
25
*/
26
27
#include "
acmp_001.h
"
28
29
/*****************************************************************************
30
* Private types/enumerations/variables
31
****************************************************************************/
32
33
/* EDGECLR interrupt clear bit, write 1, then 0 */
34
#define ACMP_EDGECLR_BIT (1 << 20)
35
36
#define ACMP_EDGESEL_MASK (0x3 << 3)
37
#define ACMP_COMPVPSEL_MASK (0x7 << 8)
38
#define ACMP_COMPVMSEL_MASK (0x7 << 11)
39
#define ACMP_HYSTERESIS_MASK (0x3 << 25)
40
#define ACMP_LADSEL_MASK (0x1F << 1)
41
#define ACMP_LADREF_MASK (0x1 << 6)
42
43
/*****************************************************************************
44
* Public types/enumerations/variables
45
****************************************************************************/
46
47
/*****************************************************************************
48
* Private functions
49
****************************************************************************/
50
51
/*****************************************************************************
52
* Public functions
53
****************************************************************************/
54
55
/* Clears the EDGECLR bit */
56
void
IP_ACMP_EdgeClear
(
ACMP_001_T
*pACMP)
57
{
58
uint32_t
reg = pACMP->
CTRL
;
59
60
/* Toggle EDGECLR bit high and then low */
61
pACMP->
CTRL
= reg |
ACMP_EDGECLR_BIT
;
62
pACMP->
CTRL
= reg & ~
ACMP_EDGECLR_BIT
;
63
}
64
65
/* Sets up ACMP edge selection */
66
void
IP_ACMP_SetEdgeSelection
(
ACMP_001_T
*pACMP,
IP_ACMP_001_EDGESEL_T
edgeSel)
67
{
68
uint32_t
reg = pACMP->
CTRL
& ~
ACMP_EDGESEL_MASK
;
69
70
/* Select edge for COMPEDGE */
71
pACMP->
CTRL
= reg | (
uint32_t
) edgeSel;
72
}
73
74
/* Selects positive voltage input */
75
void
IP_ACMP_SetPosVoltRef
(
ACMP_001_T
*pACMP,
uint32_t
Posinput)
76
{
77
uint32_t
reg = pACMP->
CTRL
& ~
ACMP_COMPVPSEL_MASK
;
78
79
/* Select positive input */
80
pACMP->
CTRL
= reg | Posinput;
81
}
82
83
/* Selects negative voltage input */
84
void
IP_ACMP_SetNegVoltRef
(
ACMP_001_T
*pACMP,
uint32_t
Neginput)
85
{
86
uint32_t
reg = pACMP->
CTRL
& ~
ACMP_COMPVMSEL_MASK
;
87
88
/* Select negative input */
89
pACMP->
CTRL
= reg | Neginput;
90
}
91
92
/* Selects hysteresis level */
93
void
IP_ACMP_SetHysteresis
(
ACMP_001_T
*pACMP,
IP_ACMP_HYS_001_T
hys)
94
{
95
uint32_t
reg = pACMP->
CTRL
& ~
ACMP_HYSTERESIS_MASK
;
96
97
/* Select negative input */
98
pACMP->
CTRL
= reg | (
uint32_t
) hys;
99
}
100
101
/* Helper function for setting up ACMP control */
102
void
IP_ACMP_SetupAMCPRefs
(
ACMP_001_T
*pACMP,
IP_ACMP_001_EDGESEL_T
edgeSel,
103
uint32_t
Posinput,
uint32_t
Neginput,
IP_ACMP_HYS_001_T
hys)
104
{
105
uint32_t
reg = pACMP->
CTRL
& ~(
ACMP_HYSTERESIS_MASK
|
106
ACMP_COMPVMSEL_MASK
|
ACMP_COMPVPSEL_MASK
|
ACMP_EDGESEL_MASK
);
107
108
/* Select negative input */
109
pACMP->
CTRL
= reg | (
uint32_t
) edgeSel | (
uint32_t
) Posinput |
110
(
uint32_t
) Neginput | (
uint32_t
) hys;
111
}
112
113
/* Sets up voltage ladder */
114
void
IP_ACMP_SetupVoltLadder
(
ACMP_001_T
*pACMP,
uint32_t
ladsel,
bool
ladrefVDDCMP)
115
{
116
uint32_t
reg = pACMP->
LAD
& ~(
ACMP_LADSEL_MASK
|
ACMP_LADREF_MASK
);
117
118
/* Setup voltage ladder and ladder reference */
119
if
(ladrefVDDCMP) {
120
reg |=
ACMP_LADREF_MASK
;
121
}
122
pACMP->
LAD
= reg | ladsel;
123
}
software
lpc_core
lpc_ip
acmp_001.c
Generated on Fri May 10 2013 10:42:17 for LPCOpen Platform by
1.8.2