wangcharley 发表于 2023-2-25 15:55:30

ADC 内部温度通道 采样不准确

adc 通道14 采样正常,内部温度采样输出不正确,仿真的时候看,每次获取的采样值差别就很大,使用查询方式的时候就正常,是温度只能用查询的方式获取吗???

/**
* @briefADC_Common Initialization function
* @paramvoid
* @retval None
*/
void MF_ADC_Common_Init(void)
{
    FL_ADC_CommonInitTypeDef    Common_InitStruct;

    Common_InitStruct.clockSource = FL_CMU_ADC_CLK_SOURCE_RCHF;
    Common_InitStruct.clockPrescaler = FL_ADC_CLK_PSC_DIV8;
    Common_InitStruct.referenceSource = FL_ADC_REF_SOURCE_VDDA;
    Common_InitStruct.bitWidth = FL_ADC_BIT_WIDTH_12B;

    FL_ADC_CommonInit(&Common_InitStruct);   
}
/**
* @briefADC_Sampling Initialization function
* @paramvoid
* @retval None
*/
void MF_ADC_Sampling_Init(void)
{
    FL_GPIO_InitTypeDef    GPIO_InitStruct;

    FL_ADC_InitTypeDef    Sampling_InitStruct;

    /* PC9 ADC_IN14 */
    GPIO_InitStruct.pin = FL_GPIO_PIN_9;
    GPIO_InitStruct.mode = FL_GPIO_MODE_ANALOG;
    GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
    GPIO_InitStruct.pull = FL_DISABLE;
    GPIO_InitStruct.remapPin = NULL;
    GPIO_InitStruct.analogSwitch = FL_DISABLE;
    FL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    Sampling_InitStruct.conversionMode = FL_ADC_CONV_MODE_SINGLE;
    Sampling_InitStruct.autoMode = FL_ADC_SINGLE_CONV_MODE_AUTO;
    Sampling_InitStruct.waitMode = FL_ENABLE;
    Sampling_InitStruct.overrunMode = FL_ENABLE;
    Sampling_InitStruct.scanDirection = FL_ADC_SEQ_SCAN_DIR_FORWARD;
    Sampling_InitStruct.externalTrigConv = FL_ADC_TRIGGER_EDGE_NONE;
    Sampling_InitStruct.triggerSource = FL_DISABLE;
    Sampling_InitStruct.fastChannelTime = FL_ADC_FAST_CH_SAMPLING_TIME_2_ADCCLK;
    Sampling_InitStruct.lowChannelTime = FL_ADC_SLOW_CH_SAMPLING_TIME_512_ADCCLK;
    Sampling_InitStruct.oversamplingMode = FL_ENABLE;
    Sampling_InitStruct.overSampingMultiplier = FL_ADC_OVERSAMPLING_MUL_16X;
    Sampling_InitStruct.oversamplingShift = FL_ADC_OVERSAMPLING_SHIFT_4B;

    FL_ADC_Init(ADC, &Sampling_InitStruct);

    FL_ADC_EnableSequencerChannel(ADC, FL_ADC_INTERNAL_TS);

    FL_ADC_EnableSequencerChannel(ADC, FL_ADC_INTERNAL_VREF1P2);

    // FL_ADC_EnableSequencerChannel(ADC, FL_ADC_EXTERNAL_CH14);   
}


/**
* @briefADC Interrupt Initialization function
* @paramvoid
* @retval None
*/
void MF_ADC_Interrupt_Init(void)
{
    FL_ADC_ClearFlag_EndOfConversion(ADC);
    FL_ADC_EnableIT_EndOfConversion(ADC);
}
/**
* @briefNVIC Initialization function
* @paramvoid
* @retval None
*/
static void MF_NVIC_Init(void)
{
    FL_NVIC_ConfigTypeDef InterruptConfigStruct;

    InterruptConfigStruct.preemptPriority = 0x2; /*配置中断优先级*/
    FL_NVIC_Init(&InterruptConfigStruct, ADC_IRQn);
}
uint32_t GetSingleChannelVoltage_IT(void)
{
    uint32_t GetChannelVoltage = 0;

    if(VREF1P2ChannelSample != 0)
    {
      GetChannelVoltage = (uint32_t)(((uint64_t)ExChannelSample * 3000 * (ADC_VREF)) / ((uint64_t)VREF1P2ChannelSample * 4095));
    }

    // 转换结果
    return GetChannelVoltage;
}

float GetTS_IT(void)
{
    uint32_t VPTAT = 0, VPTAT_30 = 0;
    float GetTS = 0.00f;

    if(VREF1P2ChannelSample != 0)
    {
      VPTAT = (uint32_t)(((uint64_t)GetTSChannelSample * 3000 * (ADC_VREF)) / ((uint64_t)VREF1P2ChannelSample * 4095));
      VPTAT_30 = ((uint32_t)ADC_TS * 3000) / (4095);
      GetTS = ((float)VPTAT - (float)VPTAT_30) / (2.6f) + (30.0f);
    }
    // 转换结果
    return GetTS;
}



页: [1]
查看完整版本: ADC 内部温度通道 采样不准确