电力电子技术与新能源

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1840|回复: 0

STM32F030 内部温度传感器 温度采集问题。

[复制链接] TA的其它主题

3

主题

5

帖子

31

积分

版主

Rank: 7Rank: 7Rank: 7

积分
31
发表于 2020-4-15 00:13:02 | 显示全部楼层 |阅读模式
#define TEMP110_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FFFF7C2))
#define TEMP30_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FFFF7B8))
#define VDD_CALIB ((uint16_t) (330))
#define VDD_APPLI ((uint16_t) (300))
#define        ADC_CHANNEL_NUMBERS                                                                                                                                                        8                                //ADCͨµÀÊý




void AdcConfiguration(void)
{       
        GPIO_InitTypeDef GPIO_InitStructure;
        DMA_InitTypeDef DMA_InitStructure;
        ADC_InitTypeDef ADC_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;


        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_DMA1, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);


        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
       
        ADC_DeInit(ADC1);
        ADC_StructInit(&ADC_InitStructure);
        ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
        ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
        ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
        ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward; // ADC_ScanDirection_Upward;
        ADC_Init(ADC1, &ADC_InitStructure);


        ADC_ChannelConfig(ADC1, ADC_Channel_0, ADC_SampleTime_239_5Cycles); /* Convert the ADC1 Channel with 239.5 Cycles as sampling time */
        ADC_ChannelConfig(ADC1, ADC_Channel_1, ADC_SampleTime_239_5Cycles);   
        ADC_ChannelConfig(ADC1, ADC_Channel_4, ADC_SampleTime_239_5Cycles);
        ADC_ChannelConfig(ADC1, ADC_Channel_5, ADC_SampleTime_239_5Cycles);
        ADC_ChannelConfig(ADC1, ADC_Channel_6, ADC_SampleTime_239_5Cycles);
        ADC_ChannelConfig(ADC1, ADC_Channel_7, ADC_SampleTime_239_5Cycles);
        ADC_ChannelConfig(ADC1, ADC_Channel_9, ADC_SampleTime_239_5Cycles);
        /*************************************************************************/
        //ADC_ChannelConfig(ADC1, ADC_Channel_TempSensor, ADC_SampleTime_239_5Cycles);
        ADC_ChannelConfig(ADC1, ADC_Channel_16, ADC_SampleTime_239_5Cycles);
  //ADC_ChannelConfig(ADC1, ADC_Channel_Vrefint, ADC_SampleTime_7_5Cycles);
       
        ADC_TempSensorCmd(ENABLE);
        //ADC_VrefintCmd(ENABLE);
  /*************************************************************************/
        ADC_GetCalibrationFactor(ADC1); /* ADC Calibration */
        ADC_Cmd(ADC1, ENABLE); /* Enable ADCperipheral[PerIdx] */
        while (!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY)); /* Wait the ADCEN falg */


  









        /*--------DMAÅäÖÃ-----------*/
        DMA_DeInit(DMA1_Channel1);
        DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->DR;// ADC1_DR_ADDRESS;  
        DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&AdcValue;  
        DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
        //BufferSize=2£¬ÒòΪADCת»»ÐòÁÐÓÐ2¸öͨµÀ   
        //Èç´ËÉèÖã¬Ê¹ÐòÁÐ1½á¹û·ÅÔÚAD_Value[0]£¬ÐòÁÐ2½á¹û·ÅÔÚAD_Value[1]
        DMA_InitStructure.DMA_BufferSize = ADC_SAMPLE_TIMES*ADC_CHANNEL_NUMBERS;//7¸öͨµÀ£¬Ã¿¸öͨµÀ30¸öÖµ   
        DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;  
        DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;   
        DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;  
        DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;  
        //Ñ­»·Ä£Ê½¿ªÆô£¬BufferдÂúºó£¬×Ô¶¯»Øµ½³õʼµØÖ·¿ªÊ¼´«Êä  
        DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;   
        DMA_InitStructure.DMA_Priority = DMA_Priority_High;
        DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
        DMA_Init(DMA1_Channel1, &DMA_InitStructure);
        //ÅäÖÃÍê³Éºó£¬Æô¶¯DMAͨµÀ
        DMA_Cmd(DMA1_Channel1, ENABLE);       
        DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE); //ʹÄÜDMA´«ÊäÍê³ÉÖжÏ
  ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular); /* Enable ADC_DMA */
  ADC_DMACmd(ADC1, ENABLE);
        /*--------DMAÖжÏÅäÖÃ----------*/
        NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);          // Enable Interrupt
        ADC_StartOfConversion(ADC1); /* ADC1 regular Software Start Conv */
        while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)==RESET);

}


void ADC_GetValue(void)
{
        u32 sum = 0;
        u8 count,i;
  //        float AdcPortValut[ADC_CHANNEL_NUMBERS];
        for(i=0;i<ADC_CHANNEL_NUMBERS;i++)
        {
                for ( count=0;count<ADC_SAMPLE_TIMES;count++)
                {
                        sum += AdcValue[count];
                        AdcValue[count] = 0;
                }
                AdcValueAfterFilter=sum/ADC_SAMPLE_TIMES;
   
                sum=0;
        }       
               

}


void TemperatureCalculate(void)

{


        TemperatureSensor= (((int32_t) AdcValueAfterFilter[7] * VDD_APPLI / VDD_CALIB)- (int32_t) *TEMP30_CAL_ADDR );
       
TemperatureSensor= TemperatureSensor* (int32_t)(110 - 30);
       
TemperatureSensor= TemperatureSensor/ (int32_t)(*TEMP110_CAL_ADDR- *TEMP30_CAL_ADDR);
       

//TemperatureSensor= TemperatureSensor+ 30;
}


屏蔽这行,上电运行,算出来的温度是37度  差的很多呀,最后一行该不该屏蔽呢??
//TemperatureSensor= TemperatureSensor+ 30;









上一篇:最全PID控制算法的C语言实现
下一篇:常用PID 算法原理、调试经验以及代码 适用于初学者
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注微信公众号:电力电子技术与新能源
关注我们,每天有惊喜,每日有活动,扫描左边二维码,即可关注,你还在等什么?

QQ|Archiver|手机版|小黑屋|电力电子技术与新能源

GMT+8, 2024-11-21 19:57 , Processed in 0.060887 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表