NXP MCU 技术william hill官网
直播中

辛太励

7年用户 1128经验值
擅长:20153
私信 关注
[问答]

如何通过中断配置ADC通道0的2个ADC通道以及ADC通道12?

嗨,我需要通过基于中断配置 adc 通道 0 和 adc 通道 12 的 2 个 adc 通道,但我没有得到两个通道的输出
1)
#include "sdk_project_config.h"
#include <字符串.h>
#include
#include
#include “interrupt_manager.h”
#include "helper_functions.h"

易失性 int exit_code = 0;
volatile bool adcConvDone;
易失性 uint16_t adcRawValue,adcRawValue1;

/* 用户包括 */
#define ADC_INSTANCE 0UL
#define ADC_CHN ADC_INPUTCHAN_EXT12
#define ADC_VREFH 5.0f
#define ADC_VREFL 0.0f
#define PDB_INSTANCE 0UL
#define PDLY_TIMEOUT 1000000UL

/*!
  \brief 项目的主要功能。
  \details 启动初始化顺序如下:
* - 启动 asm 例程
* - 主要的()
*/
void clock_pins_init(void)
{
CLOCK_DRV_Init(&clockMan1_InitConfig0);
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0,g_pin_mux_InitConfigArr0);
}
void ADC_IRQHandler(void)
{
/* 从 ADC 通道获取通道结果 */
ADC_DRV_GetChanResult(ADC_INSTANCE, 0U, (uint16_t *)&adcRawValue);
ADC_DRV_GetChanResult(ADC_INSTANCE, 1U, (uint16_t *)&adcRawValue1);

/* 设置ADC转换完成标志 */
adcConvDone = 真;
PDB_DRV_SoftTriggerCmd(PDB_INSTANCE);

}
void adc_init(void)
{
ADC_DRV_ConfigConverter(0, &adc0_conveter);
ADC_DRV_AutoCalibration(0);
ADC_DRV_ConfigChan(0, 0, &adc_config_1_ChnConfig0);
ADC_DRV_ConfigChan(0, 1, &adc_config_1_ChnConfig1);
INT_SYS_InstallHandler(ADC0_IRQn, &ADC_IRQHandler, (isr_t*) 0);

}

void pdc_config(void)
{
uint32_t 延迟;
如果 (!calculateIntValue(&pdb_config_1_timerConfig0, PDLY_TIMEOUT, &delay))
{
/* 停止应用程序流 */
同时(1);
}
PDB_DRV_Init(0, &pdb_config_1_timerConfig0);
PDB_DRV_Enable(0);
PDB_DRV_ConfigAdcPreTrigger(0, 0, &pdb_config_1_adcTrigConfig0);
PDB_DRV_ConfigAdcPreTrigger(0, 0, &pdb_config_1_adcTrigConfig0);

PDB_DRV_SetTimerModulusValue(0,(uint32_t)延迟);

PDB_DRV_SetAdcPreTriggerDelayValue(0, 0, 0, 延迟);
PDB_DRV_SetAdcPreTriggerDelayValue(0, 1, 1, 延迟);

PDB_DRV_LoadValuesCmd(PDB_INSTANCE);
PDB_DRV_SoftTriggerCmd(PDB_INSTANCE);
/* 启用 ADC 1 中断 */
INT_SYS_EnableIRQ(ADC0_IRQn);

}
int 主要(无效)
{
/* 在这里写你的代码 */
clock_pins_init();
adc_init();
pdc_config();

同时(1);
}

/* 结束主要 */
/*!
** @}
*/

2)

#include "sdk_project_config.h"
#include <字符串.h>
#include
#include
#include “interrupt_manager.h”
#include "helper_functions.h"

易失性 int exit_code = 0;
volatile bool adcConvDone;
易失性 uint16_t adcRawValue,adcRawValue1;

/* 用户包括 */
#define ADC_INSTANCE 0UL
#define ADC_CHN ADC_INPUTCHAN_EXT12
#define ADC_VREFH 5.0f
#define ADC_VREFL 0.0f
#define PDB_INSTANCE 0UL
#define PDLY_TIMEOUT 1000000UL

/*!
  \brief 项目的主要功能。
  \details 启动初始化顺序如下:
* - 启动 asm 例程
* - 主要的()
*/
void clock_pins_init(void)
{
CLOCK_DRV_Init(&clockMan1_InitConfig0);
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0,g_pin_mux_InitConfigArr0);
}
void ADC_IRQHandler(void)
{
/* 从 ADC 通道获取通道结果 */
ADC_DRV_GetChanResult(ADC_INSTANCE, 0U, (uint16_t *)&adcRawValue);
ADC_DRV_GetChanResult(ADC_INSTANCE, 1U, (uint16_t *)&adcRawValue1);

/* 设置ADC转换完成标志 */
adcConvDone = 真;

}
void adc_init(void)
{
ADC_DRV_ConfigConverter(0, &adc0_conveter);
ADC_DRV_AutoCalibration(0);
ADC_DRV_ConfigChan(0, 0, &adc_config_1_ChnConfig0);
ADC_DRV_ConfigChan(0, 1, &adc_config_1_ChnConfig1);
INT_SYS_InstallHandler(ADC0_IRQn, &ADC_IRQHandler, (isr_t*) 0);
}

void pdc_config(void)
{
uint32_t 延迟=1;
如果 (!calculateIntValue(&pdb_config_1_timerConfig0, PDLY_TIMEOUT, &delay))
{
/* 停止应用程序流 */
同时(1);
}
PDB_DRV_Init(0, &pdb_config_1_timerConfig0);
PDB_DRV_Enable(0);

PDB_DRV_ConfigAdcPreTrigger(0, 0, &pdb_config_1_adcTrigConfig0);
PDB_DRV_ConfigAdcPreTrigger(0, 1, &pdb_config_1_adcTrigConfig1);

PDB_DRV_SetTimerModulusValue(0,(uint32_t)延迟);

PDB_DRV_SetAdcPreTriggerDelayValue(0, 0, 0, (uint32_t)delay);

PDB_DRV_LoadValuesCmd(PDB_INSTANCE);
PDB_DRV_SoftTriggerCmd(PDB_INSTANCE);
/* 启用 ADC 1 中断 */
INT_SYS_EnableIRQ(ADC0_IRQn);

}
int 主要(无效)
{
/* 在这里写你的代码 */
clock_pins_init();
adc_init();
pdc_config();

而(1)
{
如果(adcConvDone == 真)
{
adcConvDone = false;
PDB_DRV_SoftTriggerCmd(PDB_INSTANCE);
}
}
}

/* 结束主要 */
/*!
** @}
*/





































回帖(1)

贺服窍

2023-9-16 18:04:32
FL 5.0f#define ADC_RES ADC_RESOLUTION_12_BITvoid ADC_Callback(ADC_Type *base, adc_channel_t channel, void *userData){ if(channel == ADC_CHN){ // ADC channel 0 adcRawValue = ADC_GetChannelConversionValue(base,channel); // Read the ADC value from channel 0 adcConvDone = true; }}void ADC_Channel12_Callback(ADC_Type *base, adc_channel_t channel, void *userData){ if(channel == ADC_INPUTCHAN_EXT12){ // ADC channel 12 adcRawValue1 = ADC_GetChannelConversionValue(base,channel); // Read the ADC value from channel 12 adcConvDone = true; }}int main(void){ adcConvDone = false;// Initialize the ADC driver adc_config_t adcConfigStruct;adcConfigStruct.resolution = ADC_RES;adcConfigStruct.vref = kADC_ReferenceVoltageVref2;/* Initialize ADC */ADC_Init(ADC0,&adcConfigStruct);// Configure the ADC channel 0 interrupt ADC_EnableInterrupts(ADC0,kADC_ChannelConversionDoneInterruptEnable | kADC_InterruptEnable);ADC_RegisterCallback(ADC0,ADC_Callback,NULL);// Configure the ADC channel 12 interrupt ADC_EnableInterrupts(ADC0,kADC_Channel12InterruptEnable | kADC_InterruptEnable);ADC_RegisterCallback(ADC0,ADC_Channel12_Callback,NULL);// Start the ADC conversion ADC_DoAutoCalibration(ADC0);ADC_SetHardwareAverage(ADC_INSTANCE,kADC_HardwareAverageCount1);// Once the calibration is successful, start the conversion ADC_DoSoftwareTriggerContinuous(ADC_INSTANCE,ADC_CHN);// Wait for the ADC conversion to complete while(!adcConvDone){/* Wait for ADC conversion to complete */} adcConvDone = false; // Clear the flag ADC_DoSoftwareTriggerContinuous(ADC_INSTANCE,ADC_INPUTCHAN_EXT12);// Wait for the ADC conversion to complete while(!adcConvDone){/* Wait for ADC conversion to complete */}ADC_Deinit(ADC_INSTANCE);// End of program return exit_code;}

注意事项:在使用此代码之前,请确保您正确配置了所有的 ADC 通道和中断,并有具体的硬件支持。另外,此代码只是一个示例,并不能保证适用于所有情况。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分