-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadc.c
55 lines (43 loc) · 1.44 KB
/
adc.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
/******************************************************************************************
File Name : adc.c
Author&Editor Name : Ananth Deshpande
Professional Masters in Embedded Systems
Fall 2021, UCB.
Editor email id : [email protected]
IDE used for Coding : ccstudio IDE
Compiler : GCC
Date : 4th December 2021
Info on Code obtained from other sources:
*******************************************************************************************/
/*header files*/
#include "msp.h"
#include "adc.h"
/***************************************************************************
* Initialise ADC
*
* Parameters: None
*
* Returns: void
**************************************************************************/
void ADC_init()
{
/*configure P2.2-P2.0 as output for tricolor LEDs*/
P2->SEL0 &= ~7;
P2->SEL1 &= ~7;
P2->DIR |= 7;
/*power on and disable during configuration*/
ADC14->CTL0 = 0x00000010;
/*S/H pulse mode, sysclk, 32 sample clocks, software trigger*/
ADC14->CTL0 |= 0x04080300;
/*14-bit resolution*/
ADC14->CTL1 = 0x00000030;
/*A6 input, single-ended, vref=vcc*/
ADC14->MCTL[5] = 5;
/*configure P5.0 for A6*/
P5->SEL1 |= 0x01;
P5->SEL0 |= 0x01;
/*convert for mem reg 5*/
ADC14->CTL1 |= 0x00050000;
/*enable ADC after configuration*/
ADC14->CTL0 |= 2;
}