Problems with ADC conversion

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems with ADC conversion

1,555 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ledi007 on Tue Apr 19 07:02:19 MST 2016
Hello,

i do my first steps with an LPC822 and would like to make a simple ADC conversion @ ADC_2 pin.

I wrote this code for initialization and basically the code works, but the result is wrong.
On ADC_2 (pin PIO_14) i had connected a poti between Vcc and GND. As result i get only the value 0 and 4095.
Every 200ms i start an adc conversion in the SysTick_Handler and in the endless loop i read the adc data register of channel 2.

I hope, someone can help me ?

Here is my code:
#include "chip.h"
#include <cr_section_macros.h>

void SysTick_Handler(void)
{
LPC_GPIO_PORT->NOT[0] = (1<<15);// Toggle PIO0_15
Chip_ADC_StartSequencer(LPC_ADC, ADC_SEQA_IDX);// manual start for ADC conversion sequence A
}

int main(void)
{
uint32_t rawSample, ADC_result;

Chip_SystemInit();// setup system clocking
SystemCoreClockUpdate();// Read clock settings and update SystemCoreClock variable
    SysTick_Config(SystemCoreClock / 5);// Systick is reloading 1/5 of a second = 200ms...

    LPC_GPIO_PORT->DIR[0] |= (1<<15); // Set direction of PIO0_15 to output

    Chip_ADC_Init(LPC_ADC,0);// setup ADC 12-bit mode, normal power
    Chip_ADC_StartCalibration(LPC_ADC);// calibration after ADC initialization
    while (!(Chip_ADC_IsCalibrationDone(LPC_ADC))) {}

    Chip_ADC_SetClockRate(LPC_ADC, ADC_MAX_SAMPLE_RATE);
    Chip_ADC_SetupSequencer(LPC_ADC, ADC_SEQA_IDX, (ADC_SEQ_CTRL_CHANSEL(2) | ADC_SEQ_CTRL_MODE_EOS)); // setup SEQA, ADC_CH2
    Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); // enable the clock to the switch matrix
    Chip_SWM_EnableFixedPin(SWM_FIXED_ADC2);// config the switch matrix  for PIO0_14 as the input for ADC_2
    Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); // disable the clock to the switch matrix to save power
    Chip_ADC_EnableSequencer(LPC_ADC, ADC_SEQA_IDX);// enable sequencer

    while(1)
    {
    rawSample = Chip_ADC_GetDataReg(LPC_ADC, 2);// read ADC data register of ADC channel 2
    ADC_result = (rawSample >> 4) & 0xFFF;  // getting adc converted result from 4th to 15th bit of DR
    }
    return 0 ;
}


Labels (1)
0 Kudos
Reply
7 Replies

1,355 Views
lpcware
NXP Employee
NXP Employee
bump
0 Kudos
Reply

1,355 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by IanB on Thu Apr 21 07:40:39 MST 2016
I always wondered what would happen if you didn't connect them - they are always such a pain to track on the pcb.
0 Kudos
Reply

1,355 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ledi007 on Thu Apr 21 05:52:10 MST 2016
oh my goodness :- i had solved the problem!
It was unfortunately self-made by myself...i forgot to connect the pins VREFN with GND and VREFP with Vcc.

Now it works!  :bigsmile:
0 Kudos
Reply

1,354 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ledi007 on Thu Apr 21 05:20:30 MST 2016
now i measured the voltage @ ADC_2 pin with a resistance divider (Vcc---10k---10k---GND). I measured a voltage of 1,8V by Vcc = 3,2V. Thats not exactly the half! The reading change from 0 to 4095 or from 4095 to 0 at a voltage on the pin of 0,24V.

Attached you can see the content of the registers adc, sysahbclkctrl, iocon and adc after initialization.
0 Kudos
Reply

1,355 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by IanB on Thu Apr 21 03:11:11 MST 2016
Nothing too obvious - a little more investigation is required. . .

Assuming a linear pot, does the voltage on the pin equal half-supply when the pot is in the middle? (That gives a clue if anything internally is driving the pin)
At what voltage on the pin does the reading change from 0 to 4095?
0 Kudos
Reply

1,355 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ledi007 on Wed Apr 20 03:13:14 MST 2016
Yes, it is enabled in PDRUNCFG and SYSAHBCLKCTRL
0 Kudos
Reply

1,355 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by IanB on Wed Apr 20 00:40:30 MST 2016
Is the ADC bit enabled in PDRUNCFG and SYSAHBCLKCTRL?
0 Kudos
Reply