Ashok K
/
ADCWITHOUT
ANALOG TO DIGITAL CONVERSION WITHOUT USING READ AND ANALOG IN (FOR TEMPERATURE SENSOR AND C- CODE)
Diff: main.cpp
- Revision:
- 0:666052f13fcb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed May 21 10:31:54 2014 +0000 @@ -0,0 +1,63 @@ +#include "mbed.h" +Serial pc(USBTX,USBRX); +int value1; +int value; + void initadc() +{ + pc.printf("in adc\n"); + LPC_SC->PCONP|=(1<<15);/// SELECT PCONP GPIO 15th pin + LPC_SC->PCONP|=(1<<12);/// SELECT PCONP PCADC 12TH pin + LPC_SC->PCLKSEL0 &= ~ (1<<24); + LPC_SC->PCLKSEL0 &= ~(1<<25);//SETTING UP OF CCLK for 25Mhz; + int CCLK = LPC_ADC->ADCR|=(7<<8); ///SET PRESCALAR VALUE /1 so that it works at 13mhz; + pc.printf("cclkvalue is %d\n",CCLK); + LPC_PINCON->PINSEL1|=(1<<14);/// select pin (p0.23 ad0.0) + LPC_PINCON->PINMODE1|=(2<<15);/// + LPC_ADC->ADCR |=(1<<21); //ADC on + LPC_ADC->ADINTEN |=(1<<0); /// interrupt enable on dis pin +} +void initchan(int ch) +{ + LPC_ADC->ADCR|=(1<<ch);//SELECT CHANNEL(SEL BITS) + pc.printf("in channel"); +} + void startadc() +{ + LPC_ADC->ADCR=(1<<24); + } +int main() +{ + initadc(); + initchan(0); + while(1) + { + pc.printf("in main\n"); + // startadc(); + LPC_ADC->ADCR |= (1<<24); // START = start conversion now + while ((LPC_ADC->ADGDR & (0x80000000))==0); //wait till done bit in adcr is set + /* Wait for Conversion end */ + int value = (LPC_ADC->ADDR0 >> 4) & 0xFFF; + pc.printf("adc is %f\n",(value*100)*(3.3/4096)); + } +} + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file