First Version

Dependencies:   EthernetInterface mbed-rtos mbed

Committer:
rebonatto
Date:
Tue Jul 21 21:29:49 2015 +0000
Revision:
0:9df41090ba33
First Version

Who changed what in which revision?

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