lpcware

4337 ADC problem with value returned and DONE status

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by krhodesnb on Thu Jan 30 20:25:58 MST 2014
I have 2 problems with the ADC:
1) The Chip_ADC_ReadStatus returns that the ADC is ready immediately but the values aren't correct. If I put a 1mSec delay after starting the acquisition, it seems to have a fully calculated value
2) When the input voltage is 3.3v, the value read is 0 and when the input voltage is about 2v, the value read is 511. This seems inverted. When at 3.3v, it should read the full 10 bits (or 1023) and when at 2v, should be around 511

Below is the code I'm using, adapted from the 4370 examples and lpcopen 1.03 as there is none for the 4337.

Thanks...Keith

    int i, j;
    // Initialization
ADC_Clock_Setup_T ADCSetup;

Chip_ADC_Init(LPC_ADC0, &ADCSetup);
Chip_ADC_Set_SampleRate(LPC_ADC0, &ADCSetup, 4500000);
Chip_ADC_Set_Resolution(LPC_ADC0, &ADCSetup, ADC_10BITS);

const CHIP_ADC_CHANNEL_T channelIndex[5] = { ADC_CH4, ADC_CH3, ADC_CH5, ADC_CH2 };

    // walk thru each of 4 channels, getting the value of each
        for(i = 0;i<4;i++)
        {
// Tell ADC multiplexer which one to sample
Chip_SCU_ADC_Channel_Config(0, channelIndex);
Chip_ADC_Channel_Enable_Cmd(LPC_ADC0, channelIndex, ENABLE);

Chip_ADC_Burst_Cmd(LPC_ADC0, DISABLE);

Chip_ADC_Set_StartMode(LPC_ADC0, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

for(j=0;j<MAX_KEYBOARD_CONVERT_LOOP;j++)
{
if(Chip_ADC_Read_Status(LPC_ADC0, channelIndex, ADC_DR_DONE_STAT) == SET)
{
/* Read ADC value */
if(SUCCESS == Chip_ADC_Read_Value(LPC_ADC0, channelIndex, &dataADC))
{
                                        // prints 0 when value is 3.3v, and 511 when value is 2v
printf("channel: %d, value: %d\n", channelindex, dataADC);
break;
}
}
}

Chip_ADC_Channel_Enable_Cmd(LPC_ADC0, channelIndex, DISABLE);

Outcomes