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
已解决! 转到解答。
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
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)
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
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
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
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.