-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalogo_digital.bak
41 lines (37 loc) · 943 Bytes
/
analogo_digital.bak
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
#include "Nucleo.h"
#include "analogo_digital.h"
#define ADC_TAD_MUL_4 0x10
#define ADC_INPUT_PORT 0x2F
int AD_init_adc(){
//corregir despues
/*
#if (getenv("CLOCK") == 4000000)
setup_adc(ADC_CLOCK_DIV_8|ADC_TAD_MUL_2);
#elif (getenv("CLOCK") == 8000000)
setup_adc(ADC_CLOCK_DIV_16|ADC_TAD_MUL_2);
#elif (getenv("CLOCK") == 10000000)
setup_adc(ADC_CLOCK_DIV_32|ADC_TAD_MUL_2);
#elif (getenv("CLOCK") == 20000000)
setup_adc(ADC_CLOCK_DIV_64|ADC_TAD_MUL_2);
#else
setup_adc(ADC_CLOCK_DIV_32|ADC_TAD_MUL_2); // default
#endif
*/
output_a(0x00);
set_tris_a(ADC_INPUT_PORT); //RA0 a RA4 entradas
setup_adc_ports(AN0_TO_AN4);
setup_adc(ADC_CLOCK_DIV_32|ADC_TAD_MUL_4|VSS_VDD);
return (0);
}
int AD_leer_canal(int canal, int16 *buffer){
int1 done;
set_adc_channel(canal);
//delay_us(10);
read_adc(ADC_START_ONLY);
do {
done = adc_done();
}while(!done);
*buffer = read_adc(ADC_READ_ONLY);
delay_us(3);
return (0);
}