lpcware

Problems with ADC conversion

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 18, 2016 by lpcware
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 ;
}


Outcomes