final project  1
adc.c
Go to the documentation of this file.
1 
10 #include "main.h"
11 
12 
13 
15 
19 void ADC_init()
20 {
21  //enableADC 0 module on port D
22  SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R3;
23 
24  //enable clock for ADC
25  SYSCTL_RCGCADC_R |= 0x1;
26 
27  //enable port D pin 0 to work as alternate functions
28  GPIO_PORTD_AFSEL_R |= 0x01;
29 
30  //set pin to input -0
31  GPIO_PORTD_DEN_R &= 0b11111110;
32 
33  //disable analog isolation for the pin
34  GPIO_PORTD_AMSEL_R |= 0x01;
35 
36  //initialize the port trigger source as processor (default)
37  GPIO_PORTD_ADCCTL_R=0x00;
38 
39  //disable SS0 sample sequencer to configure it
40  ADC0_ACTSS_R &= ~ADC_ACTSS_ASEN0;
41 
42  //initialize the ADC trigger source as processor (default)
43  ADC0_EMUX_R = ADC_EMUX_EM0_PROCESSOR;
44 
45  //set 1st sample to use the AIN10 ADC pin
46  ADC0_SSMUX0_R |= 0x000A;
47 
48  //enable raw interrupt status
49  ADC0_SSCTL0_R |= (ADC_SSCTL0_IE0 | ADC_SSCTL0_END0);
50 
51  //enable oversampling to average
52  ADC0_SAC_R |= ADC_SAC_AVG_64X;
53 
54  //re-enable ADC0 SS0
55  ADC0_ACTSS_R |= ADC_ACTSS_ASEN0;
56 }
the main code for the robot to interact with the user
void ADC_init()
initializes the registers and timers needed for the ADC
Definition: adc.c:19