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.
I have a problem with the ADC in the LPC1768. The user manual says that the ADC is 12-bit but the maximum value of ADGDR register is 0x3FF (10-bit). In my case the ADGDR register values are greater than 0x3FF. At the ADC input maximum voltage is 1.75 V (checked using an oscilloscope), but my variable "maxVoltage" is 3,3V. Have a look at my code and please help.
const float maxAdcBits = 4095.0f; // Using Float for clarity const float maxVolts = 3.3f; // Using Float for clarity ( VREFP = 3,3V) const float voltsPerBit = (maxVolts / maxAdcBits); uint16_t AD_last; void ADC07_init (void) { LPC_PINCON->PINSEL0 &= ~(3<<4); /* P0.2 is GPIO */ LPC_PINCON->PINSEL0 |= (2<<4); /* P0.2 is AD0.7 */ LPC_SC->PCONP |= (1<<12); /* Enable power to ADC block */ LPC_ADC->ADCR = (1<<7) | /* select AD0.7 pin */ (4<< 8) | /* ADC clock is 25MHz/5 */ (1<<21); /* enable ADC */ //LPC_ADC->ADINTEN = (1<< 8); /* global enable interrupt */ LPC_ADC->ADINTEN = 0x00000180; NVIC_SetPriority(ADC_IRQn, 0x1F); NVIC_EnableIRQ(ADC_IRQn); /* enable ADC Interrupt */ // LPC_ADC->ADCR |= (1<<16); //ciagla konwersja } void ADC_IRQHandler(void) { AD_last = (LPC_ADC->ADGDR>>4) & 0xFFF;/* Read Conversion Result */ yourVoltage = AD_last * voltsPerBit; if(yourVoltage>maxVoltage) maxVoltage = yourVoltage; }
Since the resolution of the ADC is 12-bit the maximum value is 0xFFF (ADGDR.15..4).
0x3FF value in the user manual is a typo (value inherited from LPC2xxx where the ADC was 10-bit).
Hi Robert,
you are right. But I still have the problem. I want to determine the maximum value of voltage between two timestamps. Because the ADC input voltage is changing from 0V to max 1.75V (almost sin), so the value in the registry ADGDR should never be equal 0xFFF.
Best Regards
That should be easy enough - have you thought about ways to do it?
I collect data from ADC for a period of time and I look for maximum value. Still I can not find a solution to my problem. Does anybody help?
What, exactly, is your problem?
You say you're collecting the data OK - so finding the maximum should then be easy.
Where, precisely, are you stuck?
My Vrefp is 3.0V and the ADC input voltage is changing from 0V to max 1.75V (almost sin), so the value in the registry ADGDR should never be equal 0x0FFF. The problem is that the ADGR registry value is equal to 0x0FFF from time to time.