-
Notifications
You must be signed in to change notification settings - Fork 0
/
comp_e_output_toggle_Vcomp_VrefHalfVcc.c
123 lines (110 loc) · 4.14 KB
/
comp_e_output_toggle_Vcomp_VrefHalfVcc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*******************************************************************************
* MSP432 Comparator - Comparator Toggle from SLEEP; input channel C6;
* Vcompare is compared against Vcc/2
*
* Description: Use comparator and shared reference to determine if input 'Vcompare'
* is high or low. When Vcompare exceeds Vcc*1/2 COUT goes low and when
* Vcompare is less than Vcc*1/2 then CEOUT goes high.
*
*
* MSP432P401
* ------------------
* /|\| |
* | | |
* --|RST P5.7/C6|<--Vcompare
* | |
* | P7.2/COUT|----> 'low'(Vcompare>Vcc*1/2); 'high'(Vcompare<Vcc*1/2)
* | |
* | |
* | |
******************************************************************************/
//*****************************************************************************
//
// MSP432比较器例程01 - 简单电压比较
//
// 该例程将引脚上的输入电压与内部1.2V参考电压进行比较;
// 对外部通道A0和A1进行采样,差分模式,直接使用AVCC(3.3v)作为参考电压源;
// 对于转换结果,格式为补码形式。
// 在中断中将值转换为浮点型,以供用户在调试器中观察。
//
// -------MSP-EXP432P401R硬件描述 -----------
//
// MSP-EXP432P401R
// +------------------+
// /|\| |
// | | |
// --|RST P5.7/C1.6 |<--Vcompare
// | |
// | P7.2/COUT|----> 'low'(Vcompare>Vcc*1/2); 'high'(Vcompare<Vcc*1/2)
// | |
//
//-------------------------------------------------------
//
//
//*****************************************************************************
//常见标准头文件包含
#include <stdint.h>
#include <stdbool.h>
//外设驱动库DriverLib 头文件包含
//--如果编译此处出错,请查看工程的设置, 看下是否把SDK路径包含进来
//--Properties / Build / ARM Compiler / Include Options
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Comparator configuration structure */
const COMP_E_Config compConfig =
{
COMP_E_VREF, // Positive Input Terminal
COMP_E_INPUT6, // Negative Input Terminal
COMP_E_FILTEROUTPUT_DLYLVL4, // Level 4 Filter
COMP_E_NORMALOUTPUTPOLARITY // Normal Output Polarity
};
int main(void)
{
volatile uint32_t ii;
//停用看门狗
MAP_WDT_A_holdTimer();
/*
* Select Port 7
* Set Pin 2 to output Primary Module Function, (COUT).
*/
MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P7, GPIO_PIN2,
GPIO_PRIMARY_MODULE_FUNCTION);
/* Set P5.7 to be comparator in (C1.6) */
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN7,
GPIO_TERTIARY_MODULE_FUNCTION);
/* Initialize the Comparator E module
* Comparator Instance 0,
* Pin CE6 to Positive(+) Terminal,
* Reference Voltage to Negative(-) Terminal,
* Normal Power Mode,
* Output Filter On with max delay,
* Non-Inverted Output Polarity
*/
MAP_COMP_E_initModule(COMP_E1_BASE, &compConfig);
/*Set the reference voltage that is being supplied to the (-) terminal
* Comparator Instance 0,
* Reference Voltage of Vcc V,
* Lower Limit of Vcc*(16/32) = Vcc*1/2, (aprox. 1.65v at Vcc=3.3v)
* Upper Limit of Vcc*(16/32) = Vcc*1/2
*/
MAP_COMP_E_setReferenceVoltage(COMP_E1_BASE,
COMP_E_REFERENCE_AMPLIFIER_DISABLED, 16, 16);
/* Disable Input Buffer on CE1.6
* Base Address of Comparator E,
* Input Buffer port
* Selecting the CEx input pin to the comparator
* multiplexer with the CEx bits automatically
* disables output driver and input buffer for
* that pin, regardless of the state of the
* associated CEPD.x bit
*/
MAP_COMP_E_disableInputBuffer(COMP_E1_BASE, COMP_E_INPUT6);
/* Allow power to Comparator module */
MAP_COMP_E_enableModule(COMP_E1_BASE);
/* Delaying to allow comparator to settle */
for (ii = 0; ii < 400; ii++)
;
while (1)
{
MAP_PCM_gotoLPM0();
}
}