Versão sem FFT e aquisição por DMA. 256 amostras.

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed

Committer:
rebonatto
Date:
Tue Jan 05 11:45:44 2016 +0000
Revision:
0:e57bc370d339
Vers?o est?vel sem calculo de FFT. Aquisi??o por DMA. Usa 256 amostras.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rebonatto 0:e57bc370d339 1 /*
rebonatto 0:e57bc370d339 2 * adc.c
rebonatto 0:e57bc370d339 3 *
rebonatto 0:e57bc370d339 4 * Created on: 02/07/2011
rebonatto 0:e57bc370d339 5 * Author: francisco
rebonatto 0:e57bc370d339 6 */
rebonatto 0:e57bc370d339 7
rebonatto 0:e57bc370d339 8 #include <LPC17xx.h>
rebonatto 0:e57bc370d339 9 #include "adc.h"
rebonatto 0:e57bc370d339 10
rebonatto 0:e57bc370d339 11 void init_adc(int adc_clk)
rebonatto 0:e57bc370d339 12 {
rebonatto 0:e57bc370d339 13 // Turn on power to ADC block
rebonatto 0:e57bc370d339 14 LPC_SC->PCONP |= PCADC;
rebonatto 0:e57bc370d339 15
rebonatto 0:e57bc370d339 16 // Turn on ADC peripheral clock
rebonatto 0:e57bc370d339 17 LPC_SC->PCLKSEL0 &= ~(3 << PCLK_ADC);
rebonatto 0:e57bc370d339 18 LPC_SC->PCLKSEL0 |= (ADC_CCLK << PCLK_ADC); //CLK/8
rebonatto 0:e57bc370d339 19
rebonatto 0:e57bc370d339 20 unsigned int clkdiv = (SystemCoreClock/1)/65;
rebonatto 0:e57bc370d339 21 clkdiv = clkdiv/adc_clk;
rebonatto 0:e57bc370d339 22
rebonatto 0:e57bc370d339 23 LPC_ADC->ADCR &= ~(ADC_OPERATIONAL|ADC_CLKDIV(255));
rebonatto 0:e57bc370d339 24 LPC_ADC->ADCR |= (ADC_OPERATIONAL|ADC_CLKDIV(clkdiv));
rebonatto 0:e57bc370d339 25
rebonatto 0:e57bc370d339 26 //NVIC_EnableIRQ(ADC_IRQn);
rebonatto 0:e57bc370d339 27 }
rebonatto 0:e57bc370d339 28
rebonatto 0:e57bc370d339 29 void setup_start(int mode,int edge)
rebonatto 0:e57bc370d339 30 {
rebonatto 0:e57bc370d339 31 LPC_ADC->ADCR |= mode;
rebonatto 0:e57bc370d339 32 }
rebonatto 0:e57bc370d339 33
rebonatto 0:e57bc370d339 34 void select_channels(int adc_ch)
rebonatto 0:e57bc370d339 35 {
rebonatto 0:e57bc370d339 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:e57bc370d339 37 LPC_ADC->ADCR |= adc_ch;
rebonatto 0:e57bc370d339 38
rebonatto 0:e57bc370d339 39 LPC_ADC->ADINTEN |= (1U<<8);//adc_ch;
rebonatto 0:e57bc370d339 40
rebonatto 0:e57bc370d339 41 if(adc_ch&ADC_CH_0)
rebonatto 0:e57bc370d339 42 {
rebonatto 0:e57bc370d339 43 LPC_PINCON->PINSEL1 |= 1U<<14;
rebonatto 0:e57bc370d339 44 LPC_PINCON->PINMODE1 |= 2U<<14;
rebonatto 0:e57bc370d339 45 }
rebonatto 0:e57bc370d339 46 if(adc_ch&ADC_CH_1)
rebonatto 0:e57bc370d339 47 {
rebonatto 0:e57bc370d339 48 LPC_PINCON->PINSEL1 |= 1U<<16;
rebonatto 0:e57bc370d339 49 LPC_PINCON->PINMODE1 |= 2U<<16;
rebonatto 0:e57bc370d339 50 }
rebonatto 0:e57bc370d339 51 if(adc_ch&ADC_CH_2)
rebonatto 0:e57bc370d339 52 {
rebonatto 0:e57bc370d339 53 LPC_PINCON->PINSEL1 |= 1U<<18;
rebonatto 0:e57bc370d339 54 LPC_PINCON->PINMODE1 |= 2U<<18;
rebonatto 0:e57bc370d339 55 }
rebonatto 0:e57bc370d339 56 if(adc_ch&ADC_CH_3)
rebonatto 0:e57bc370d339 57 {
rebonatto 0:e57bc370d339 58 LPC_PINCON->PINSEL1 |= 1U<<20;
rebonatto 0:e57bc370d339 59 LPC_PINCON->PINMODE1 |= 2U<<20;
rebonatto 0:e57bc370d339 60 }
rebonatto 0:e57bc370d339 61 if(adc_ch&ADC_CH_4)
rebonatto 0:e57bc370d339 62 {
rebonatto 0:e57bc370d339 63 LPC_PINCON->PINSEL3 |= 3U<<28;
rebonatto 0:e57bc370d339 64 LPC_PINCON->PINMODE3 |= 2U<<28;
rebonatto 0:e57bc370d339 65 }
rebonatto 0:e57bc370d339 66 if(adc_ch&ADC_CH_5)
rebonatto 0:e57bc370d339 67 {
rebonatto 0:e57bc370d339 68 LPC_PINCON->PINSEL3 |= 3U<<30;
rebonatto 0:e57bc370d339 69 LPC_PINCON->PINMODE3 |= 2U<<30;
rebonatto 0:e57bc370d339 70 }
rebonatto 0:e57bc370d339 71 if(adc_ch&ADC_CH_6)
rebonatto 0:e57bc370d339 72 {
rebonatto 0:e57bc370d339 73 LPC_PINCON->PINSEL0 |= 2U<<6;
rebonatto 0:e57bc370d339 74 LPC_PINCON->PINMODE0 |= 2U<<6;
rebonatto 0:e57bc370d339 75 }
rebonatto 0:e57bc370d339 76 if(adc_ch&ADC_CH_7)
rebonatto 0:e57bc370d339 77 {
rebonatto 0:e57bc370d339 78 LPC_PINCON->PINSEL0 |= 2U<<4;
rebonatto 0:e57bc370d339 79 LPC_PINCON->PINMODE0 |= 2U<<4;
rebonatto 0:e57bc370d339 80 }
rebonatto 0:e57bc370d339 81 }