Hi Kerry,
So sorry for my later reply.
I find it is my mistake, I ignore the hardware, the FRDM-KL27 VFEFH is not connected to 3.3V in default.
R17 is not connected, after I connect the VREFH, it works OK now.
Still take SDK_2.8.0_FRDM-KL27Z\boards\frdmkl27z\driver_examples\adc16\interrupt
as an example,
config->enableContinuousConversion = true;//false;
/*
* Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2018 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "fsl_debug_console.h"
#include "board.h"
#include "fsl_adc16.h"
#include "pin_mux.h"
#include "clock_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define DEMO_ADC16_BASE ADC0
#define DEMO_ADC16_CHANNEL_GROUP 0U
#define DEMO_ADC16_USER_CHANNEL 1U /* PTE16, A0-ADC0_SE1, J4-2 on FRDM-KL27Z. */
#define DEMO_ADC16_IRQn ADC0_IRQn
#define DEMO_ADC16_IRQ_HANDLER_FUNC ADC0_IRQHandler
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
volatile bool g_Adc16ConversionDoneFlag = false;
volatile uint32_t g_Adc16ConversionValue;
volatile uint32_t g_Adc16InterruptCounter;
const uint32_t g_Adc16_12bitFullRange = 4096U;
/*******************************************************************************
* Code
******************************************************************************/
void DEMO_ADC16_IRQ_HANDLER_FUNC(void)
{
g_Adc16ConversionDoneFlag = true;
/* Read conversion result to clear the conversion completed flag. */
// if(!(ADC0->CFG2 & ADC_SC2_ADACT_MASK))
if (( (ADC0->SC1[0]) & ADC_SC1_COCO_MASK ) == ADC_SC1_COCO_MASK)
{
g_Adc16ConversionValue = ADC16_GetChannelConversionValue(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP);
g_Adc16InterruptCounter++;
PRINTF("ADC Value: %d\r\n", g_Adc16ConversionValue);
}
SDK_ISR_EXIT_BARRIER;
}
/*!
* @brief Main function
*/
int main(void)
{
adc16_config_t adc16ConfigStruct;
adc16_channel_config_t adc16ChannelConfigStruct;
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
EnableIRQ(DEMO_ADC16_IRQn);
PRINTF("\r\nADC16 interrupt Example.\r\n");
/*
* adc16ConfigStruct.referenceVoltageSource = kADC16_ReferenceVoltageSourceVref;
* adc16ConfigStruct.clockSource = kADC16_ClockSourceAsynchronousClock;
* adc16ConfigStruct.enableAsynchronousClock = true;
* adc16ConfigStruct.clockDivider = kADC16_ClockDivider8;
* adc16ConfigStruct.resolution = kADC16_ResolutionSE12Bit;
* adc16ConfigStruct.longSampleMode = kADC16_LongSampleDisabled;
* adc16ConfigStruct.enableHighSpeed = false;
* adc16ConfigStruct.enableLowPower = false;
* adc16ConfigStruct.enableContinuousConversion = false;
*/
ADC16_GetDefaultConfig(&adc16ConfigStruct);
#ifdef BOARD_ADC_USE_ALT_VREF
adc16ConfigStruct.referenceVoltageSource = kADC16_ReferenceVoltageSourceValt;
#endif
ADC16_Init(DEMO_ADC16_BASE, &adc16ConfigStruct);
ADC16_EnableHardwareTrigger(DEMO_ADC16_BASE, false); /* Make sure the software trigger is used. */
#if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
if (kStatus_Success == ADC16_DoAutoCalibration(DEMO_ADC16_BASE))
{
PRINTF("ADC16_DoAutoCalibration() Done.\r\n");
}
else
{
PRINTF("ADC16_DoAutoCalibration() Failed.\r\n");
}
#endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */
PRINTF("ADC Full Range: %d\r\n", g_Adc16_12bitFullRange);
PRINTF("Press any key to get user channel's ADC value ...\r\n");
adc16ChannelConfigStruct.channelNumber = DEMO_ADC16_USER_CHANNEL;
adc16ChannelConfigStruct.enableInterruptOnConversionCompleted = true; /* Enable the interrupt. */
#if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
adc16ChannelConfigStruct.enableDifferentialConversion = false;
#endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
g_Adc16InterruptCounter = 0U;
ADC16_SetChannelConfig(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP, &adc16ChannelConfigStruct);
while (1)
{
GETCHAR();
g_Adc16ConversionDoneFlag = false;
/*
When in software trigger mode, each conversion would be launched once calling the "ADC16_ChannelConfigure()"
function, which works like writing a conversion command and executing it. For another channel's conversion,
just to change the "channelNumber" field in channel configuration structure, and call the function
"ADC16_ChannelConfigure()"" again.
Also, the "enableInterruptOnConversionCompleted" inside the channel configuration structure is a parameter for
the conversion command. It takes affect just for the current conversion. If the interrupt is still required
for the following conversion, it is necessary to assert the "enableInterruptOnConversionCompleted" every time
for each command.
*/
/* ADC16_SetChannelConfig(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP, &adc16ChannelConfigStruct);
while (!g_Adc16ConversionDoneFlag)
{
}
*/
// PRINTF("ADC Value: %d\r\n", g_Adc16ConversionValue);
// PRINTF("ADC Interrupt Count: %d\r\n", g_Adc16InterruptCounter);
}
}
When I change the voltage, the conversion result is changed, it is correct, the same one time trigger.
So, do you check your hardware, do you add the VREFH?
SDK_2.8.0_FRDM-KL27Z\boards\frdmkl27z\driver_examples\adc16\continuous_dma
is also correct, this is the test result:
ADC value: 0
ADC value: 0
ADC value: 0
ADC value: 406
ADC value: 409
ADC value: 407
ADC value: 3706
ADC value: 3718
ADC value: 3725
ADC value: 5271
ADC value: 5274
ADC value: 5275
ADC value: 7059
ADC value: 7047
ADC value: 7059
ADC value: 9142
ADC value: 9149
ADC value: 9164
ADC value: 11465
ADC value: 11477
ADC value: 11410
ADC value: 13772
ADC value: 13753
ADC value: 13775
ADC value: 16960
ADC value: 17001
ADC value: 17003
ADC value: 20073
ADC value: 20074
ADC value: 20070
ADC value: 23399
ADC value: 23403
ADC value: 23406
ADC value: 26512
ADC value: 26497
ADC value: 26508
ADC value: 30065
ADC value: 30079
ADC value: 30088
ADC value: 32341
ADC value: 32368
ADC value: 32358
ADC value: 35233
ADC value: 35245
ADC value: 35284
ADC value: 38089
ADC value: 38134
ADC value: 38123
ADC value: 42358
ADC value: 42354
ADC value: 42360
ADC value: 47254
ADC value: 47315
ADC value: 47326
ADC value: 50636
ADC value: 50639
ADC value: 50618
ADC value: 53282
ADC value: 53296
ADC value: 53290
ADC value: 57946
ADC value: 57970
ADC value: 57941
ADC value: 64402
ADC value: 64390
ADC value: 64400
ADC value: 64405
ADC value: 64402
ADC value: 64399
Wish it helps you!
If you still have questions about it, please kindly let me know!
Best Regards,
Kerry
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-----------------------------------------------------------------------------