kodi.sudar
Member level 5
Hi
I have written the code for adc conversion for adc 0 channel 1 . it works well but i also wanted to use channel 2 for another input .I tried by changing the value in control register but i dont kow to extract the data for adc channel 2. here with i am enclosing the code for one channel .
How to use multiple channel adc ?
modified code .
How to use multiple channel and how to extract the data ?
Thanks in advance .
I have written the code for adc conversion for adc 0 channel 1 . it works well but i also wanted to use channel 2 for another input .I tried by changing the value in control register but i dont kow to extract the data for adc channel 2. here with i am enclosing the code for one channel .
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 #include <LPC213X.H> #include <stdio.h> #include "lcd.h" //VBC CLOCK 12MHZ void delay(); void adc_data(); void adc_ini(); unsigned long val,adc_val; unsigned char buffer [21]; // Set size to LCD width plus one null int main(void) { while(1) { adc_ini(); //initializing adc adc_data();//extracting data /*code for lcd print*/ PINSEL0=0X00000000; // gpio pin 0.0 to 0.15 PINSEL2=0X00000000; // gpio pin 1.16 to 1.31 IODIR0=0X00000007; //p0.0 rs p0.1 r/w p0.2 e IODIR1=0X00ff0000; //p1.16 to p1.24 output lcdinit(); sprintf (buffer, "ADC Value: %x", adc_val); lcdputs(buffer); } } void adc_ini(void) { PINSEL1 = 0X01000000; //pin 13 p0.28 adc 0 channel 1 PCONP |= 0X00001000; //select adc 0 bit 12 AD0CR &= 0X00000000; AD0CR |= 0X00200202; // WITH PCLK 12/(2+1)=4MHZ ADC0 CHANNEL 1 PIN 13 AD0INTEN &= 0x00000000; //Completion of a conversion on ADC channel 0 will not generate an interrupt. } void adc_data(void) { AD0CR |= 0x01000000; /* Start A/D Conversion */ while((AD0DR & 0x80000000)==0); //until bit 31 is high (DONE) val = AD0DR; //read a/d data register adc_val = ((val >> 6) & 0x3FF); // Extract AD result }
How to use multiple channel adc ?
modified code .
Code:
void adc_ini(void)
{
PINSEL1 = 0X05000000; //pin 13 p0.28 and p0.29 adc 0 channel 1 and 2
PCONP |= 0X00001000; //select adc 0 bit 12
AD0CR &= 0X00000000;
AD0CR |= 0X00200206; // WITH PCLK 12/(2+1)=4MHZ ADC0 CHANNEL 1 and 2 PIN 13 and 14
AD0INTEN &= 0x00000000; //Completion of a conversion on ADC channel 0 will not generate an interrupt.
}
Thanks in advance .
Last edited by a moderator: