Content originally posted in LPCWare by Getdan35 on Mon Nov 18 08:39:45 MST 2013
Thanks for the reply Pacman, i dont want to use channels or interrupts. I just want to switch between registers, like ADDR0 to ADDR5, READ first register which is attached to AD0.0 and print result to console. Ive attached code that works fine but only reads one input but i can switch between any input from ADO.O TO ADO.5 and it will print the correct value but now i just want it to read all registers in a loop and print them to console.
#include "LPC17xx.h"
int ADC_Val1, ADC_Val2; //ADC_Val3; ADC_Val4; ADC_Val5; ADC_Val6;
double v1,v2; //v3;v4;v5;v6;
void initADC()
{
//A/D Converter is powered on
LPC_SC->PCONP |= 1<<12;
//set P0.23 as AD0.0
LPC_PINCON->PINSEL1 |= (1<<14); //P0.23 is connected to AD0.0
LPC_PINCON->PINSEL1 |= (1<<16); //P0.24 is connected to AD0.1
//Set PINMODE of AD0.0 as no pull-up/down resistors
//LPC_PINCON->PINMODE1 |= (2 << 14);
//select AD0.0, CLKDIV = 4+1 => 25MHz/5 = 5MHz < 13MHz, power on
LPC_ADC->ADCR |= (1 << 0) | (1 << 21);
}
int readADC()
{
//start conversion
LPC_ADC->ADCR |= (1 << 24);
//wait for conversion to finish by checking ADGDR.31
while((LPC_ADC->ADDR0 & (1<<31)) == 0);
//return conversion result
return ((LPC_ADC->ADDR0 >> 4) & 0xFFF);
}
// Enter an infinite loop, just incrementing a counter
volatile static int i = 0 ;
int main(void)
{
printf("ADC CHANNEL TEST");
initADC();
while(1)
{
ADC_Val1=readADC();
v1 = (3.13/4096.0)*ADC_Val1;
printf("\nADC0: %.2lf", v1);
}
return 0 ;
}