This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Wrong values from ADC LPC1768

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;
}

Parents Reply Children
No data