Trouble configuring the ADC on the LPC845

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

Trouble configuring the ADC on the LPC845

Jump to solution
3,690 Views
tomchr
Contributor III

I'm trying to use the ADC on the LPC845 and am having a hard time with it. It seems the conversion never finishes. I hope one of you would be able to get me unstuck.

Here's the setup:

const adc_config_t ADC0configStruct = {

  .clockMode = kADC_ClockSynchronousMode,

  .clockDividerNumber = 1,

  .enableLowPowerMode = false,

  .voltageRange = kADC_HighVoltageRange,

};

/* Conversion sequence A configuration structure */

const adc_conv_seq_config_t ADC0ConvSeqAConfigStruct = {

  .channelMask = 1U,

  .triggerMask = 0U,

  .triggerPolarity = kADC_TriggerPolarityNegativeEdge,

  .enableSyncBypass = false,

  .enableSingleStep = false,

  .interruptMode = kADC_InterruptForEachConversion

};



static void ADC0_init(void) {

  /* Perform self calibration */

  ADC_DoSelfCalibration(ADC0_PERIPHERAL, ADC0_CLK_FREQ);

  /* Initialize ADC0 peripheral */

  ADC_Init(ADC0_PERIPHERAL, &ADC0configStruct);

  /* Configure the conversion sequence A */

  ADC_SetConvSeqAConfig(ADC0_PERIPHERAL, &ADC0ConvSeqAConfigStruct);

  /* Enable the conversion sequence A */

  ADC_EnableConvSeqA(ADC0_PERIPHERAL, true);

  /* Configure threshold compare interrupt on channel 0 */

  ADC_EnableThresholdCompareInterrupt(ADC0_PERIPHERAL, 0U, kADC_ThresholdInterruptDisabled);

}

And here's how I use it:

    adc_result_info_t ADC_Result;

    ADC_DoSoftwareTriggerConvSeqA(ADC0_PERIPHERAL);
    while (!ADC_GetChannelConversionResult(ADC0_PERIPHERAL, 0U, &ADC_Result))
    {
    }
    printf("Results register cleared\n");

 

The program never reaches the printf() statement. I'm sure I'm missing something really fundamental here... The clock source is the 15 MHz output from the FRO.

 

Thanks in advance.

 

Tom

Labels (1)
0 Kudos
Reply
1 Solution
3,662 Views
tomchr
Contributor III

Like I said, "it's probably something simple". I have concluded that it helps considerably if the ADC is turned on. I was missing:

#include "fsl_power.h"

POWER_DisablePD(kPDRUNCFG_PD_ADC0);

I'm a bit surprised this isn't added automatically by the peripheral configuration tool, but whatever.

Tom

View solution in original post

7 Replies
3,522 Views
tomchr
Contributor III

Did you tell the ADC to use the two reference voltages and set the correct voltage range?

Tom

0 Kudos
Reply
3,513 Views
srchethan
Contributor I

Thanks.. for your soon reply.

A/D trim register, reset value is 0. (VRANGE is High voltage, VDD = 2.7 V to 3.6 V).
I'm giving reference voltage VREFP is 3.3V, so i'm not configure A/D trim register.

Is their is anything else, to configure ADC for the two reference voltages.(VREFP and VREFN)

 

0 Kudos
Reply
3,468 Views
tomchr
Contributor III

I used the peripheral configuration tool in the IDE to set up the ADC. I set up the voltage range and clock. I turn the ADC on via its power-down bit as pointed to in the post marked 'solution' in this thread. I'm pretty sure that's all you need to do if you want to use polling with the ADC. 

If you also want to use interrupts, you need to set up an ISR for the ADC and point it to that in the peripheral configurator tool (or somewhere in the ADC setup).

I'd look at the code @carstengroen posted in this thread (2020/10/08).

Tom

0 Kudos
Reply
3,663 Views
tomchr
Contributor III

Like I said, "it's probably something simple". I have concluded that it helps considerably if the ADC is turned on. I was missing:

#include "fsl_power.h"

POWER_DisablePD(kPDRUNCFG_PD_ADC0);

I'm a bit surprised this isn't added automatically by the peripheral configuration tool, but whatever.

Tom

3,685 Views
tomchr
Contributor III

Here's what's in BOARD_BootClockRUN:

 

    CLOCK_Select(kADC_Clk_From_Fro);                       /*!< select FRO for ADC */

    CLOCK_SetCoreSysClkDiv(1U);

    CLOCK_SetClkDivider(kCLOCK_DivAdcClk, 15U);     /*!< set ADC clock div */

 

Tom

0 Kudos
Reply
3,536 Views
srchethan
Contributor I

Will you please help?

I am using LPC845 33 pin chip. Properly connected VREFP and VREFN
I am giving an input of 1.7V to PIO0_21(ADC_5), pin 28

When tried to initialise the ADC, first ensuring IOCON PIO0_21 is set for no-pull-up and no-pull-down
and then assigning ADC_5 through SWM, the voltage goes to 0.3V

Even if I proceed to calibrate and read, I get a low value of 0x19

I tried changing the sequence of initialising SWM and then IOCON, and this time
firat I get some 1.7V but the moment the IOCON is loaded, the voltage drops.


To avoid any problem related to library, I even tried using all register addresses and bit values dirctly

No change in the result.

I had tried SDK 2.5 and 2.8 versions both. I need some help very much, please.

0 Kudos
Reply
3,680 Views
carstengroen
Senior Contributor II

@tomchr ,

attached is my ADC code (for 845) from my last project, works perfectly. Maybe you can get some hints from that ?

0 Kudos
Reply