-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADC.c
68 lines (51 loc) · 1.48 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "ADC.h"
#include "GPIO.h"
#include "NVIC.h"
#include <stdio.h>
#include <stdlib.h>
/****** Method Declarations ******/
void setup(void);
void increaseSampleRate(void);
void decreaseSampleRate(void);
void _setupGPIO(void);
void _enableADC(void);
extern void setTimerReload(int reload);
extern void enqueue(int elem);
extern void printString(char str[]);
//Configures the ADC - PE3, Sampler 0, ADC0
void setupADC(void)
{
*RCGCADC |= 0x01; //Activate clock to ADC0
*RCGC0 |= 0x10000; //active clock on legacy register (doesn't fix it)
_setupGPIO();
*ADCACTSS &= ~SAMPLER; //Disable Sampler number
*ADCEMUX |= 0x05; //Sets sampler 0 trigger to timer triggered
*ADCSSCTL0 |= 0x6;//Sets first sample in sequence to be end of sequence
//and first sample to generate interrupt
*ADCIM |= 0x1; //sampler 0 triggers interrupt
*NVIC_EN0 |= 16384; //enable IRQ 14
_enableADC();
}
//Retrieves the converted value from the ADC FIFO
//and puts it in the buffer.
void adcISR(void)
{
int result = *ADCSSFIFO0;
*ADCISC |= 0x0F; //clear interrupt
enqueue(result);
}
//Sets up the GPIO port for voltage input
void _setupGPIO(void)
{
int i;
*RCGCGPIO |= 0x10; //activate clock for Port E
for (i = 0; i < 2; i++) {;} //allow clock to settle
*GPIOE_AFSEL |= 0x8; //set afsel for pin 3
*GPIOE_DEN &= ~0x8; //disable digital functions for pin 3
*GPIOE_AMSEL |= 0x8; //set analogue isolation for pin 3
}
//enables the adc
void _enableADC(void)
{
*ADCACTSS |= 0x01;
}