We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
ADC Read giving me 0!
my MCU is LPC1768
this is my code: the library i wrote for adc
[CODE] #include "LPC17xx.H"
void adc_init() { LPC_SC->PCONP |= (1 << 12); //set PCADC for power on ADC ; LPC_ADC->ADCR |= (1 << 21); // start adc LPC_PINCON->PINSEL1 &= ~0x003FC000; /* P0.23~26, A0.0~3, function 01 */ LPC_PINCON->PINSEL1 |= 0x00154000; LPC_PINCON->PINMODE1 &= ~0x003FC000; LPC_PINCON->PINMODE1 |= 0x002A8000; }
int ADCRead(char channelNum) { int data; LPC_ADC->ADCR &= 0xFFFFFF00; // clear channels LPC_ADC->ADCR |= (1 << 24) | (1 << channelNum); // set chanel and start convert while (!(LPC_ADC->ADGDR & (1<<31))); //wait to done data = LPC_ADC->ADDR7; LPC_ADC->ADCR &= 0xF8FFFFFF; /* stop ADC now */
data = ( data >> 4 ) & 0xFFF; return ( data ); /* return A/D conversion value */ } [/CODE]
[CODE]#include <br> #include <br> #include "uart.h" #include "adc.h"
void Delay (uint32_t Time) { uint32_t i;
i = 0; while (Time--) { for (i = 0; i < 5000; i++); } }
int main(void) { volatile int i=0; unsigned char lcd_buf[32];
SystemInit(); adc_init(); UART0_Init();
while (1) { i++; sprintf(lcd_buf,"AnalogRead(%d)(A0): %d\r\n\n",i,ADCRead(0)); UART0_SendString(lcd_buf); Delay(2000); } }[/CODE]
it just keeps returning 0!!!!
sorry :)
anyway i made it work, it wasn't code fault, my aref jumper on headerboard was off :|
thanks for replying anyway :)
while(true) thanks();