Hi everyone,
I'm new with arm microcontrollers and I'm having a problem with ADC. I'm setting it up properly (I think), but still, when I try showing the conversion result it keep changing even when a conversion isn't requested. Here is the source code, I would really appreciate if anyone could help. That is it. Thanks in advance! Rodrigo
unsigned int channel=0, valorad[7]; //global variables void adcinit(void){ //initialize adc unsigned int AD0CR_setup = (14<<8) | (1>>16) | (0<<19)|(0<<18)|(0<<17) | (1<<21) | (1<<6); //CLKDIV 15, BURST MODE ON, RESOLUTION 10 BITS, POWER UP ADC, SELECT AD0.6 AD0CR = AD0CR_setup; } void readADC(void){//read adc unsigned long AD0GDR_Read = AD0GDR;// read AD0GDR register int currentResult; //variable declaration channel = (AD0GDR_Read>>24) & 0xF; //Extract Channel Number currentResult = (AD0GDR_Read>>6) & 0x3FF; //Extract Conversion Result valorad[channel]=(currentResult*3.3); //write conversion result*VREF in the position of their channels } int main(void) { char escr[100]; //variable utilized by lcd initClocks(); //Initialize CPU and Peripheral Clocks @ 60Mhz initTimer0(); //Initialize Timer0 lcd_init(); //initialize lcd adcinit(); //initialize adc while(1) { readADC(); //read ADC conversion and channel sprintf(escr,"\f\rV = %.4d", valorad[6]); //show tension in AD0.6 lcd_puts(escr);//show tension in AD0.6 delayMS(1000);//delay 1 sec } }
So the code you posted is not the code you actually used??
This shows exactly why you should never do that!
Always use copy & paste, so that what we see is what you've got - otherwise we're just debugging your forum typos.
I used that code, but that parameters, like BURST MODE ON, CLKDIV, RESOLUTION BITS and de ADC channel was defined as constants and it won't make any sense if this declarations wasn't here, so I changed just this part, but the rest its exactly the same