-
Notifications
You must be signed in to change notification settings - Fork 1
/
adc.c
75 lines (55 loc) · 1.53 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
// Standard includes
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
// Driverlib includes
#include "utils.h"
#include "hw_memmap.h"
#include "hw_common_reg.h"
#include "hw_types.h"
#include "hw_adc.h"
#include "hw_ints.h"
#include "hw_gprcm.h"
#include "rom.h"
#include "rom_map.h"
#include "interrupt.h"
#include "prcm.h"
#include "uart.h"
#include "pinmux.h"
#include "pin.h"
#include "adc.h"
//#include "adc_userinput.h"
#include "uart_if.h"
#include "gpio.h"
#define NO_OF_SAMPLES 128
extern unsigned long pulAdcSamples[4096];
void adc (void){
unsigned long ulSample;
unsigned int uiChannel;
unsigned int uiIndex=0;
while(uiIndex < NO_OF_SAMPLES + 4)
{
if(MAP_ADCFIFOLvlGet(ADC_BASE, uiChannel))
{
ulSample = MAP_ADCFIFORead(ADC_BASE, uiChannel);
pulAdcSamples[uiIndex++] = ulSample; // Fill data sample buffer
}
}
}
void adcPrint (void){
unsigned int uiIndex=0;
//
// Print out ADC samples
//
//float sum = 0;
while(uiIndex < NO_OF_SAMPLES)
{
//UART_PRINT("\n\rVoltage is %f\n\r",(((float)((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))*1.4*2.279)/4096);
//uiIndex++;
//sum += (((float)((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))*1.4*2.279)/4096;
}
//UART_PRINT("\n\rVoltage is %f\n\r",((pulAdcSamples[4] >> 2 ) & 0x0FFF)*1.4/4096);
//UART_PRINT("\n\r");
//UART_PRINT("\n\rAverage Voltage Level %f\n\r", (float)(sum/NO_OF_SAMPLES));
}