Ashok K
/
ADCWITHOUT
ANALOG TO DIGITAL CONVERSION WITHOUT USING READ AND ANALOG IN (FOR TEMPERATURE SENSOR AND C- CODE)
main.cpp@0:666052f13fcb, 2014-05-21 (annotated)
- Committer:
- AshokK
- Date:
- Wed May 21 10:31:54 2014 +0000
- Revision:
- 0:666052f13fcb
ANALOG TO DIGITAL CONVERSION WITHOUT USING READ, ANALOGIN ....; ( FOR TEMPERATURE SENSOR AND POTENTIOMETER)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AshokK | 0:666052f13fcb | 1 | #include "mbed.h" |
AshokK | 0:666052f13fcb | 2 | Serial pc(USBTX,USBRX); |
AshokK | 0:666052f13fcb | 3 | int value1; |
AshokK | 0:666052f13fcb | 4 | int value; |
AshokK | 0:666052f13fcb | 5 | void initadc() |
AshokK | 0:666052f13fcb | 6 | { |
AshokK | 0:666052f13fcb | 7 | pc.printf("in adc\n"); |
AshokK | 0:666052f13fcb | 8 | LPC_SC->PCONP|=(1<<15);/// SELECT PCONP GPIO 15th pin |
AshokK | 0:666052f13fcb | 9 | LPC_SC->PCONP|=(1<<12);/// SELECT PCONP PCADC 12TH pin |
AshokK | 0:666052f13fcb | 10 | LPC_SC->PCLKSEL0 &= ~ (1<<24); |
AshokK | 0:666052f13fcb | 11 | LPC_SC->PCLKSEL0 &= ~(1<<25);//SETTING UP OF CCLK for 25Mhz; |
AshokK | 0:666052f13fcb | 12 | int CCLK = LPC_ADC->ADCR|=(7<<8); ///SET PRESCALAR VALUE /1 so that it works at 13mhz; |
AshokK | 0:666052f13fcb | 13 | pc.printf("cclkvalue is %d\n",CCLK); |
AshokK | 0:666052f13fcb | 14 | LPC_PINCON->PINSEL1|=(1<<14);/// select pin (p0.23 ad0.0) |
AshokK | 0:666052f13fcb | 15 | LPC_PINCON->PINMODE1|=(2<<15);/// |
AshokK | 0:666052f13fcb | 16 | LPC_ADC->ADCR |=(1<<21); //ADC on |
AshokK | 0:666052f13fcb | 17 | LPC_ADC->ADINTEN |=(1<<0); /// interrupt enable on dis pin |
AshokK | 0:666052f13fcb | 18 | } |
AshokK | 0:666052f13fcb | 19 | void initchan(int ch) |
AshokK | 0:666052f13fcb | 20 | { |
AshokK | 0:666052f13fcb | 21 | LPC_ADC->ADCR|=(1<<ch);//SELECT CHANNEL(SEL BITS) |
AshokK | 0:666052f13fcb | 22 | pc.printf("in channel"); |
AshokK | 0:666052f13fcb | 23 | } |
AshokK | 0:666052f13fcb | 24 | void startadc() |
AshokK | 0:666052f13fcb | 25 | { |
AshokK | 0:666052f13fcb | 26 | LPC_ADC->ADCR=(1<<24); |
AshokK | 0:666052f13fcb | 27 | } |
AshokK | 0:666052f13fcb | 28 | int main() |
AshokK | 0:666052f13fcb | 29 | { |
AshokK | 0:666052f13fcb | 30 | initadc(); |
AshokK | 0:666052f13fcb | 31 | initchan(0); |
AshokK | 0:666052f13fcb | 32 | while(1) |
AshokK | 0:666052f13fcb | 33 | { |
AshokK | 0:666052f13fcb | 34 | pc.printf("in main\n"); |
AshokK | 0:666052f13fcb | 35 | // startadc(); |
AshokK | 0:666052f13fcb | 36 | LPC_ADC->ADCR |= (1<<24); // START = start conversion now |
AshokK | 0:666052f13fcb | 37 | while ((LPC_ADC->ADGDR & (0x80000000))==0); //wait till done bit in adcr is set |
AshokK | 0:666052f13fcb | 38 | /* Wait for Conversion end */ |
AshokK | 0:666052f13fcb | 39 | int value = (LPC_ADC->ADDR0 >> 4) & 0xFFF; |
AshokK | 0:666052f13fcb | 40 | pc.printf("adc is %f\n",(value*100)*(3.3/4096)); |
AshokK | 0:666052f13fcb | 41 | } |
AshokK | 0:666052f13fcb | 42 | } |
AshokK | 0:666052f13fcb | 43 | |
AshokK | 0:666052f13fcb | 44 | |
AshokK | 0:666052f13fcb | 45 | |
AshokK | 0:666052f13fcb | 46 | |
AshokK | 0:666052f13fcb | 47 | |
AshokK | 0:666052f13fcb | 48 | |
AshokK | 0:666052f13fcb | 49 | |
AshokK | 0:666052f13fcb | 50 | |
AshokK | 0:666052f13fcb | 51 | |
AshokK | 0:666052f13fcb | 52 | |
AshokK | 0:666052f13fcb | 53 | |
AshokK | 0:666052f13fcb | 54 | |
AshokK | 0:666052f13fcb | 55 | |
AshokK | 0:666052f13fcb | 56 | |
AshokK | 0:666052f13fcb | 57 | |
AshokK | 0:666052f13fcb | 58 | |
AshokK | 0:666052f13fcb | 59 | |
AshokK | 0:666052f13fcb | 60 | |
AshokK | 0:666052f13fcb | 61 | |
AshokK | 0:666052f13fcb | 62 | |
AshokK | 0:666052f13fcb | 63 |