在线时间42 小时
UID3156990
注册时间2017-12-12
NXP金币0
TA的每日心情 | 擦汗 2023-12-19 16:25 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
中级会员
- 积分
- 367
- 最后登录
- 2023-12-19
|
初始化了两路ADC,自己用电位器测试了可以使用,电压在0--4096之间变化,但是接上传感器之后输出一直咂3700左右变化。
使用示波器直接测试传感器的输出也是正确的,有变化,但是接上单片机之后再测试就发现测试结果不对了,就稳定在了3700左右。
请问这是什么问题,下面贴上我的代码:
uint8_t adc_init(void)
{
uint8_t ret = 0;
adc_config_t adcConfigStruct;
adc_conv_seq_config_t adcConvSeqConfigStruct;
// Configure the power and clock for ADC.
POWER_DisablePD(kPDRUNCFG_PD_ADC0); /* Power on the ADC converter. */
POWER_DisablePD(kPDRUNCFG_PD_VD7_ENA); /* Power on the analog power supply. */
POWER_DisablePD(kPDRUNCFG_PD_VREFP_SW); /* Power on the reference voltage source. */
POWER_DisablePD(kPDRUNCFG_PD_TEMPS); /* Power on the temperature sensor. */
// Enable the clock.
// CLOCK_AttachClk(kFRO12M_to_MAIN_CLK);
CLOCK_EnableClock(kCLOCK_Adc0); /* SYSCON->AHBCLKCTRL[0] |= SYSCON_AHBCLKCTRL_ADC0_MASK; */
// IOCON_PinMuxSet(IOCON, 1, 0, IOCON_MODE_INACT | IOCON_FUNC0 | IOCON_ANALOG_EN | IOCON_INPFILT_OFF);
// Calibration
if (ADC_DoSelfCalibration(ADC0))
{
;
}
else
{
return 0;
}
/* Configure the converter. */
adcConfigStruct.clockMode = kADC_ClockSynchronousMode; /* Using sync clock source. */
adcConfigStruct.clockDividerNumber = 1; /* The divider for sync clock is 2. */
adcConfigStruct.resolution = kADC_Resolution12bit;
adcConfigStruct.enableBypassCalibration = false;
adcConfigStruct.sampleTimeNumber = 0U;
ADC_Init(ADC0, &adcConfigStruct);
/* Use the sensor input to channel 0. */
ADC_EnableTemperatureSensor(ADC0, true);
/* Enable channel 0's conversion in Sequence A. */
adcConvSeqConfigStruct.channelMask = (1U << ADC_CHANNEL4_NUM | 1U << ADC_CHANNEL5_NUM); /* Includes channel 0. */
adcConvSeqConfigStruct.triggerMask = 0U;
adcConvSeqConfigStruct.triggerPolarity = kADC_TriggerPolarityNegativeEdge;
adcConvSeqConfigStruct.enableSingleStep = false;
adcConvSeqConfigStruct.enableSyncBypass = false;
adcConvSeqConfigStruct.interruptMode = kADC_InterruptForEachSequence;
ADC_SetConvSeqAConfig(ADC0, &adcConvSeqConfigStruct);
ADC_EnableConvSeqA(ADC0, true); /* Enable the conversion sequence A. */
// /* Enable channel 0's conversion in Sequence A. */
// adcConvSeqConfigStruct.channelMask = (1U << ADC_CHANNEL5_NUM); /* Includes channel 0. */
// adcConvSeqConfigStruct.triggerMask = 0U;
// adcConvSeqConfigStruct.triggerPolarity = kADC_TriggerPolarityNegativeEdge;
// adcConvSeqConfigStruct.enableSingleStep = false;
// adcConvSeqConfigStruct.enableSyncBypass = false;
// adcConvSeqConfigStruct.interruptMode = kADC_InterruptForEachSequence;
// ADC_SetConvSeqAConfig(ADC0, &adcConvSeqConfigStruct);
// ADC_EnableConvSeqA(ADC0, true); /* Enable the conversion sequence A. */
ret = 1;
return ret;
}
uint16_t adc_read(uint16_t num)
{
ADC_DoSoftwareTriggerConvSeqA(ADC0);
/* Wait for the converter to be done. */
while (!ADC_GetChannelConversionResult(ADC0, num, &gAdcResultInfoStruct))
{
}
return (gAdcResultInfoStruct.result&0x0FFF);
}
引脚也是初始化了的。使用MCUXpresso Config Tools v4.0初始化的
|
|