-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadc.h
More file actions
94 lines (67 loc) · 1.97 KB
/
adc.h
File metadata and controls
94 lines (67 loc) · 1.97 KB
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
#ifndef ADC_H
#define ADC_H
/*
* Considerations:
* ADC interrupts must read from the buffer THEN clear the interrupt flag AFTER the buffer is read.
* Max sample speed is 400 ksps
* Sample time minimum is 200 ns
*/
//Pre: ADC must be OFF
//Post: Analog Pins that are used will be put into analog mode
void configANPins();
//Pre: ADC must be OFF
//Post: Configures the two MUX inputs A and B
void configIntoMux();
//Pre: ADC must be OFF
//Post: Configures the format of the result buffer - currently a 32 bit unsigned int format
//with rightmost 10 bits being data, the rest is 0
void setOutputFormat();
//Pre: ADC must be OFF
//Post: Sets Conversion to happen automatically
void setSampleConvTrigger();
//Pre: ADC must be OFF
//Post: Sets Voltage Reference for HIGH and LOW for system
void setVoltageRefs();
//Pre: ADC must be OFF
//Post: Sets input scan mode to OFF
void selectScanMode();
//Pre: ADC must be OFF
//Post: Sets the rate of samples the interrupt should occur
//in our case 2 Samples are converted then the interrupt happens
void setConvPerInterrupt();
//Pre: ADC must be OFF
//Post: Buffer Size is set to either 8 bit or 16 bit mode - we are using 16 bit
void setBufferFillMode();
//Pre: ADC must be OFF
//Post: Configures the ADC Clock Source and Speed
/*
* Clock source is PBCLK
* TAD = 18*TPB 18 times the PBCLK - ADC Clock Speed
* Auto Sample Time bits
*/
void configADC_Clock();
//Pre: ADC must be OFF
//Post: sets sample time of ADC
void setSampleTime();
//Pre: ADC must be OFF
//Post: sets the ADC to alternate between sampling TSENSE and CSENSE
void setAlternateMode();
//Pre: ADC must be OFF
//Post:
void adc_init();
//Pre: adc_init() should be called first to initialize config registers
//Post: Turns on ADC
void adc_on();
//Pre: None
//Post: Turns ADC on
void adc_off();
//Pre: ADC should be ON
//Post:
void stopSampling();
//Pre: ADC should be ON
//Post:
void startSampling();
//Pre: Set auto sample mode
//Post:
void setAutoSample();
#endif