![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Versão do protegemed que calcula o tempo em ms da fuga, calcula o numero de onverflow (valores muito baixo) e underflow (valores muito altos). Além disso, calcula um valor médio a partir dos valores capturados e não apenas pela fft.
Dependencies: EthernetInterface mbed-rtos mbed
Drivers/adc.c@2:86c3cb25577b, 2014-07-21 (annotated)
- Committer:
- rebonatto
- Date:
- Mon Jul 21 00:58:34 2014 +0000
- Revision:
- 2:86c3cb25577b
- Parent:
- 0:c64e1194230b
Problemas com objeto para aquisi??o da rfid (serial)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rebonatto | 0:c64e1194230b | 1 | /* |
rebonatto | 0:c64e1194230b | 2 | * adc.c |
rebonatto | 0:c64e1194230b | 3 | * |
rebonatto | 0:c64e1194230b | 4 | * Created on: 02/07/2011 |
rebonatto | 0:c64e1194230b | 5 | * Author: francisco |
rebonatto | 0:c64e1194230b | 6 | */ |
rebonatto | 0:c64e1194230b | 7 | |
rebonatto | 0:c64e1194230b | 8 | #include <LPC17xx.h> |
rebonatto | 0:c64e1194230b | 9 | #include "adc.h" |
rebonatto | 0:c64e1194230b | 10 | |
rebonatto | 0:c64e1194230b | 11 | void init_adc(int adc_clk) |
rebonatto | 0:c64e1194230b | 12 | { |
rebonatto | 0:c64e1194230b | 13 | // Turn on power to ADC block |
rebonatto | 0:c64e1194230b | 14 | LPC_SC->PCONP |= PCADC; |
rebonatto | 0:c64e1194230b | 15 | |
rebonatto | 0:c64e1194230b | 16 | // Turn on ADC peripheral clock |
rebonatto | 0:c64e1194230b | 17 | LPC_SC->PCLKSEL0 &= ~(3 << PCLK_ADC); |
rebonatto | 0:c64e1194230b | 18 | LPC_SC->PCLKSEL0 |= (ADC_CCLK << PCLK_ADC); //CLK/8 |
rebonatto | 0:c64e1194230b | 19 | |
rebonatto | 0:c64e1194230b | 20 | unsigned int clkdiv = (SystemCoreClock/1)/65; |
rebonatto | 0:c64e1194230b | 21 | clkdiv = clkdiv/adc_clk; |
rebonatto | 0:c64e1194230b | 22 | |
rebonatto | 0:c64e1194230b | 23 | LPC_ADC->ADCR &= ~(ADC_OPERATIONAL|ADC_CLKDIV(255)); |
rebonatto | 0:c64e1194230b | 24 | LPC_ADC->ADCR |= (ADC_OPERATIONAL|ADC_CLKDIV(clkdiv)); |
rebonatto | 0:c64e1194230b | 25 | |
rebonatto | 0:c64e1194230b | 26 | //NVIC_EnableIRQ(ADC_IRQn); |
rebonatto | 0:c64e1194230b | 27 | } |
rebonatto | 0:c64e1194230b | 28 | |
rebonatto | 0:c64e1194230b | 29 | void setup_start(int mode,int edge) |
rebonatto | 0:c64e1194230b | 30 | { |
rebonatto | 0:c64e1194230b | 31 | LPC_ADC->ADCR |= mode; |
rebonatto | 0:c64e1194230b | 32 | } |
rebonatto | 0:c64e1194230b | 33 | |
rebonatto | 0:c64e1194230b | 34 | void select_channels(int adc_ch) |
rebonatto | 0:c64e1194230b | 35 | { |
rebonatto | 0:c64e1194230b | 36 | LPC_ADC->ADCR &= ~(ADC_CH_0|ADC_CH_1|ADC_CH_2|ADC_CH_3|ADC_CH_4|ADC_CH_5|ADC_CH_6|ADC_CH_7); |
rebonatto | 0:c64e1194230b | 37 | LPC_ADC->ADCR |= adc_ch; |
rebonatto | 0:c64e1194230b | 38 | |
rebonatto | 0:c64e1194230b | 39 | LPC_ADC->ADINTEN |= (1U<<8);//adc_ch; |
rebonatto | 0:c64e1194230b | 40 | |
rebonatto | 0:c64e1194230b | 41 | if(adc_ch&ADC_CH_0) |
rebonatto | 0:c64e1194230b | 42 | { |
rebonatto | 0:c64e1194230b | 43 | LPC_PINCON->PINSEL1 |= 1U<<14; |
rebonatto | 0:c64e1194230b | 44 | LPC_PINCON->PINMODE1 |= 2U<<14; |
rebonatto | 0:c64e1194230b | 45 | } |
rebonatto | 0:c64e1194230b | 46 | if(adc_ch&ADC_CH_1) |
rebonatto | 0:c64e1194230b | 47 | { |
rebonatto | 0:c64e1194230b | 48 | LPC_PINCON->PINSEL1 |= 1U<<16; |
rebonatto | 0:c64e1194230b | 49 | LPC_PINCON->PINMODE1 |= 2U<<16; |
rebonatto | 0:c64e1194230b | 50 | } |
rebonatto | 0:c64e1194230b | 51 | if(adc_ch&ADC_CH_2) |
rebonatto | 0:c64e1194230b | 52 | { |
rebonatto | 0:c64e1194230b | 53 | LPC_PINCON->PINSEL1 |= 1U<<18; |
rebonatto | 0:c64e1194230b | 54 | LPC_PINCON->PINMODE1 |= 2U<<18; |
rebonatto | 0:c64e1194230b | 55 | } |
rebonatto | 0:c64e1194230b | 56 | if(adc_ch&ADC_CH_3) |
rebonatto | 0:c64e1194230b | 57 | { |
rebonatto | 0:c64e1194230b | 58 | LPC_PINCON->PINSEL1 |= 1U<<20; |
rebonatto | 0:c64e1194230b | 59 | LPC_PINCON->PINMODE1 |= 2U<<20; |
rebonatto | 0:c64e1194230b | 60 | } |
rebonatto | 0:c64e1194230b | 61 | if(adc_ch&ADC_CH_4) |
rebonatto | 0:c64e1194230b | 62 | { |
rebonatto | 0:c64e1194230b | 63 | LPC_PINCON->PINSEL3 |= 3U<<28; |
rebonatto | 0:c64e1194230b | 64 | LPC_PINCON->PINMODE3 |= 2U<<28; |
rebonatto | 0:c64e1194230b | 65 | } |
rebonatto | 0:c64e1194230b | 66 | if(adc_ch&ADC_CH_5) |
rebonatto | 0:c64e1194230b | 67 | { |
rebonatto | 0:c64e1194230b | 68 | LPC_PINCON->PINSEL3 |= 3U<<30; |
rebonatto | 0:c64e1194230b | 69 | LPC_PINCON->PINMODE3 |= 2U<<30; |
rebonatto | 0:c64e1194230b | 70 | } |
rebonatto | 0:c64e1194230b | 71 | if(adc_ch&ADC_CH_6) |
rebonatto | 0:c64e1194230b | 72 | { |
rebonatto | 0:c64e1194230b | 73 | LPC_PINCON->PINSEL0 |= 2U<<6; |
rebonatto | 0:c64e1194230b | 74 | LPC_PINCON->PINMODE0 |= 2U<<6; |
rebonatto | 0:c64e1194230b | 75 | } |
rebonatto | 0:c64e1194230b | 76 | if(adc_ch&ADC_CH_7) |
rebonatto | 0:c64e1194230b | 77 | { |
rebonatto | 0:c64e1194230b | 78 | LPC_PINCON->PINSEL0 |= 2U<<4; |
rebonatto | 0:c64e1194230b | 79 | LPC_PINCON->PINMODE0 |= 2U<<4; |
rebonatto | 0:c64e1194230b | 80 | } |
rebonatto | 0:c64e1194230b | 81 | } |