本帖最后由 fendoushuai 于 2024-3-28 18:10 编辑
从H7的ADC3 19通道读取的温度值转换后总是120多度
是需要对它进行校准吗?还是有别的配置
printf打印的结果如下
TS_CAL1=12220, TS_CAL2=16301
ADC3_INP19 TEMP Value=17179, Voltage= 127.211 C,
[C] 纯文本查看 复制代码 static void AppTaskADC(void *p_arg)
{
float AdcValues[10];
uint16_t TS_CAL1;
uint16_t TS_CAL2;
(void)p_arg;
while(1) {
BSP_vToggleLED(LED_YELLOW);
TS_CAL1 = *(__IO uint16_t *)(0x1FF1E820);
TS_CAL2 = *(__IO uint16_t *)(0x1FF1E840);
AdcValues[2] = (110.0 - 30.0) * ( aADC3ConvertedData[0] - TS_CAL1) / (TS_CAL2 - TS_CAL1) + 30;
printf("TS_CAL1=%d, TS_CAL2=%d\r\n", TS_CAL1, TS_CAL2);
printf("ADC3_INP19 TEMP Value=%d, Voltage= %5.3f C,\r\n", aADC3ConvertedData[0], AdcValues[2]);
OSTimeDlyHMSM(0, 0, 2, 0);
}
}
/* ### - 1 - Initialize ADC peripheral #################################### */
hadc3.Instance = ADC3;
if (HAL_ADC_DeInit(&hadc3) != HAL_OK) {
/* ADC de-initialization Error */
Error_Handler(__FILE__, __LINE__);
}
hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; /* Asynchronous clock mode, input ADC clock divided by 1*/
hadc3.Init.Resolution = ADC_RESOLUTION_16B; /* 16-bit resolution for converted data */
hadc3.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */
hadc3.Init.LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */
hadc3.Init.ContinuousConvMode = ENABLE; /* Continuous mode enabled (automatic conversion restart after each conversion) */
hadc3.Init.NbrOfConversion = 1; /* Parameter discarded because sequencer is disabled */
hadc3.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
hadc3.Init.NbrOfDiscConversion = 1; /* Parameter discarded because sequencer is disabled */
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* Software start to trig the 1st conversion manually, without external event */
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR; /* ADC DMA circular requested */
hadc3.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; /* DR register is overwritten with the last conversion result in case of overrun */
hadc3.Init.OversamplingMode = DISABLE; /* No oversampling */
/* Initialize ADC peripheral according to the passed parameters */
if (HAL_ADC_Init(&hadc3) != HAL_OK) {
Error_Handler(__FILE__, __LINE__);
}
/* ### - 2 - Start calibration ############################################ */
if (HAL_ADCEx_Calibration_Start(&hadc3, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED) != HAL_OK) {
Error_Handler(__FILE__, __LINE__);
}
/* ### - 3 - Channel configuration ######################################## */
sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; /* Sampled channel number */
sConfig.Rank = ADC_REGULAR_RANK_1; /* Rank of sampled channel number ADCx_CHANNEL */
sConfig.SamplingTime = ADC_SAMPLETIME_810CYCLES_5; /* Sampling time (number of clock cycles unit) */
sConfig.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
sConfig.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
sConfig.Offset = 0; /* Parameter discarded because offset correction is disabled */
if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) {
Error_Handler(__FILE__, __LINE__);
}
|