-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathADC.c
More file actions
39 lines (33 loc) · 1.03 KB
/
ADC.c
File metadata and controls
39 lines (33 loc) · 1.03 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
#include <fsl_device_registers.h>
#include "ADC.h"
unsigned short ADC_read16b(void)
{
ADC0_SC1A = 0 & ADC_SC1_ADCH_MASK; //Write to SC1A to start conversion
while(ADC0_SC2 & ADC_SC2_ADACT_MASK); //Conversion in progress
while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)); //Wait until conversion complete
return ADC0_RA;
}
void DelayFunction (void)
{
unsigned long Counter = 0xFFFFF;
do
{
Counter--;
}while(Counter);
}
void initADC(void)
{
SIM_SCGC6 |= SIM_SCGC6_ADC0_MASK;
ADC0_CFG1 |= ADC_CFG1_MODE(3); //16 bit single-ended
//ADC0_CFG1 |= ADC_CFG1_ADIV(1);
ADC0_SC1A |= ADC_SC1_ADCH(0);
SIM_SCGC3 |= SIM_SCGC3_ADC1_MASK;
ADC1_CFG1 |= ADC_CFG1_MODE(3); //16 bit single-ended
//ADC1_CFG1 |= ADC_CFG1_ADIV(1);
ADC1_SC1A |= ADC_SC1_ADCH(0);
//set clock frequency
//ADC0_CFG2 |= ADC_CFG2_ADHSC(4); //high speed conversion
//ADC0_CFG1 = ADC_CFG1_ADLSMP(0); //short sample time
//ADC1_CFG2 |= ADC_CFG2_ADHSC(4); //high speed conversion
//ADC0_CFG1 = ADC_CFG1_ADLSMP(0); //short sample time
}