-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadc.c
141 lines (117 loc) · 4.12 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* adc.c
*
* Created on: 20-Sep-2014
* Author: Harish
*/
#include "stdint.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/adc.h"
#include "driverlib/fpu.h"
#include "stdbool.h"
#include "inc/hw_ints.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
#include "status_led.h"
#include "comm/comm_core.h"
#include "comm/comm_usb.h"
#include "adc.h"
#define HW_OVERSAMPLE_FACTOR 8
void InitADC(void){
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
//GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); // Not sure why this throws an exception with my Stellaris Launchpad.
ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS);
ROM_ADCHardwareOversampleConfigure(ADC0_BASE, HW_OVERSAMPLE_FACTOR);
ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_INT);
ROM_ADCSequenceDisable(ADC0_BASE, ADC_0_SEQUENCER);
ROM_ADCSequenceConfigure(ADC0_BASE, ADC_0_SEQUENCER, ADC_TRIGGER_PROCESSOR, 0);
ROM_ADCSequenceStepConfigure(ADC0_BASE, ADC_0_SEQUENCER, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
ROM_ADCSequenceEnable(ADC0_BASE, ADC_0_SEQUENCER);
if(enableDualChannel){
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
//GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); // Not sure why this throws an exception with my Stellaris Launchpad.
ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_ADC1);
ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS);
ROM_ADCHardwareOversampleConfigure(ADC1_BASE, HW_OVERSAMPLE_FACTOR);
ROM_ADCReferenceSet(ADC1_BASE, ADC_REF_INT);
ROM_ADCSequenceDisable(ADC1_BASE, ADC_1_SEQUENCER);
ROM_ADCSequenceConfigure(ADC1_BASE, ADC_1_SEQUENCER, ADC_TRIGGER_PROCESSOR, 0);
ROM_ADCSequenceStepConfigure(ADC1_BASE, ADC_1_SEQUENCER, 0, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);
ROM_ADCSequenceEnable(ADC1_BASE, ADC_1_SEQUENCER);
}
ROM_ADCIntClear(ADC0_BASE, ADC_0_SEQUENCER);
ROM_ADCIntEnable(ADC0_BASE, ADC_0_SEQUENCER);
if(enableDualChannel){
ROM_ADCIntClear(ADC1_BASE, ADC_1_SEQUENCER);
ROM_ADCIntEnable(ADC1_BASE, ADC_1_SEQUENCER);
}
}
/*
* ADC_0 Sequence 3 interrupt handler.
*
* Check running mode
* 1. Continuous mode
* Send ADC value immediately to requester(host application).
* 2. Burst mode
* Store ADC value in memory. Once samples count reaches BURST_DATA_SIZE then send entire data to requester.
*/
void ADC_0_S3_IntHandler(void){
ROM_ADCSequenceDisable(ADC0_BASE, ADC_0_SEQUENCER);
ROM_ADCIntClear(ADC0_BASE, ADC_0_SEQUENCER);
ROM_ADCSequenceDataGet(ADC0_BASE, ADC_0_SEQUENCER, &ulADC_0_Value);
if(burstMode){
burstData[burstDataCounter++] = 0x8000 | ulADC_0_Value;
if(burstDataCounter >= BURST_DATA_SIZE){
LEDOff_Blue();
burstMode = false;
Stop_Stream();
Send_BurstData();
}
}else{
TransmitData(0b10000000 | ((ulADC_0_Value >> 8) & 0x00FF), ulADC_0_Value & 0x00FF);
}
if(sendStream){
ROM_ADCSequenceEnable(ADC0_BASE, ADC_0_SEQUENCER);
ROM_ADCProcessorTrigger(ADC0_BASE, ADC_0_SEQUENCER);
}
}
/*
* ADC_1 Sequence 3 interrupt handler.
*
* Check running mode
* 1. Continuous mode
* Send ADC value immediately to requester(host application).
* 2. Burst mode
* Store ADC value in memory. Once samples count reaches BURST_DATA_SIZE then send entire data to requester.
*/
void ADC_1_S3_IntHandler(void){
ROM_ADCSequenceDisable(ADC1_BASE, ADC_1_SEQUENCER);
ROM_ADCIntClear(ADC1_BASE, ADC_1_SEQUENCER);
ROM_ADCSequenceDataGet(ADC1_BASE, ADC_1_SEQUENCER, &ulADC_1_Value);
if(burstMode){
burstData[burstDataCounter++] = 0x4000 | ulADC_1_Value;
if(burstDataCounter >= BURST_DATA_SIZE){
LEDOff_Blue();
burstMode = false;
Stop_Stream();
Send_BurstData();
}
}else{
TransmitData(0b01000000 | ((ulADC_0_Value >> 8) & 0x00FF), ulADC_1_Value & 0x00FF);
}
if(sendStream){
ROM_ADCSequenceEnable(ADC1_BASE, ADC_1_SEQUENCER);
ROM_ADCProcessorTrigger(ADC1_BASE, ADC_1_SEQUENCER);
}
}
void ADC_0_S2_IntHandler(void){return;}
void ADC_0_S1_IntHandler(void){return;}
void ADC_0_S0_IntHandler(void){return;}
void ADC_1_S2_IntHandler(void){return;}
void ADC_1_S1_IntHandler(void){return;}
void ADC_1_S0_IntHandler(void){return;}