This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F5438A ADC片内温度读取设置及转化公式

Other Parts Discussed in Thread: MSP430F5438A

以下程序是MSP430F5438A ADC片内温度传感器的配置及读取函数,不知道读取的ADC_CH10数值误差大不大,想知道片内温度转化公式,希望有知道的大神帮忙解决一下,谢谢!!!附上以下代码,代码中的公式用在149是可以的,5438A应该是其他公式??

#include "Adc12_Temp.h"

u16 results[5]={0};
/********************************************
函数名称:ADC12初始化函数
功能:    
输入:    无
输出:    无
备注:    REFCTL0 |= REFMSTR+REFVSEL_2+REFON+REFTCOFF必须要加
********************************************/
void Adc12_Init()
{
  u8 i;
  P6SEL |= BIT0+BIT1+BIT2+BIT3;                    // 使能ADC功能
  ADC12CTL0 &= ~ADC12ENC;                          // 使能转换
  REFCTL0 |= REFMSTR+REFVSEL_2+REFON;              //使能REF管理,内部参考电压选择2.5v、打开内部参考电压
  ADC12CTL0 = ADC12SHT0_8+ADC12MSC+ADC12REF2_5V+ADC12REFON+ADC12ON;
                                                   //ADC12SHT0_8:采样周期256(2的8次方)
                                                   //ADC12MSC:首次转换需要SHI信号的上升沿出发采样定时器,
                                                   //以后每次转换在前一次转换结束后立即进行
                                                   //ADC12REF2_5V:选择2.5V内部参考电压
                                                   //ADC12REFON:开启内部参考电压
                                                   //ADC12ON:开启ADC12内核 
  ADC12CTL1 = ADC12CSTARTADD_0+ADC12SHP+ADC12CONSEQ_3;   
                                                   //CSTARTADD_0:单次转换起始地址或序列转换的首地址
                                                   //ADC12CSTARTADD_x表示把转换结果存储在ADC12MEMx中
                                                   //转换地址为ADC12MCTLx,转换使能为ADC12IE = BITx
                                                   //ADC12SHP:SAMPCON信号来自采样定时器,由采样输入信号的上升沿触发
                                                   //ADC12CONSEQ_3:序列通道重复转换模式
  ADC12CTL2 &= ~ADC12TCOFF;  
  ADC12MCTL0 = ADC12SREF_1+ADC12INCH_0;            //ADC12SREF_1;基准源选择Vref+,模拟电压输入通道选择
                                                   //ADC12INCH1:端口对应的通道号
  ADC12MCTL1 = ADC12SREF_1+ADC12INCH_1; 
  ADC12MCTL2 = ADC12SREF_1+ADC12INCH_2;
  ADC12MCTL3 = ADC12SREF_1+ADC12INCH_3;
  ADC12MCTL4 = ADC12SREF_1+ADC12INCH_10+ADC12EOS;  //INCH_10:片内温度传感器对应的通道号
                                                   //EOS:停止通道转换
  ADC12IE = BIT4;                                  //使能ADC中断 Enable ADC12IFG.4
   for ( i=0; i<0x30; i++);                       
  ADC12CTL0 |= ADC12ENC;                  // 使能转换
  ADC12CTL0 |= ADC12SC;                  // 开始转换
}
/*******************************************
函数名称:ADC12ISR
功    能:ADC中断服务函数,在这里用多次平均的
          计算P6.1口的模拟电压数值
参    数:无       
返回值  :无
********************************************/
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
  switch(__even_in_range(ADC12IV,34))
  {
  case  0: break;                           // Vector  0:  No interrupt
  case  2: break;                           // Vector  2:  ADC overflow
  case  4: break;                           // Vector  4:  ADC timing overflow
  case  6: break;                           // Vector  6:  ADC12IFG0
  case  8: break;                           // Vector  8:  ADC12IFG1
  case 10: break;                           // Vector 10:  ADC12IFG2
  case 12: break;                           // Vector 12:  ADC12IFG3
  case 14: 
           results[0] = ADC12MEM0;          //读取后中断标志位自动清除
           results[1] = ADC12MEM1;          
           results[2] = ADC12MEM2;          
           results[3] = ADC12MEM3;          
           results[4] = ADC12MEM4;   
           break;                           // Vector 14:  ADC12IFG4
           
  case 16: break;                           // Vector 16:  ADC12IFG5
  case 18: break;                           // Vector 18:  ADC12IFG6
  case 20: break;                           // Vector 20:  ADC12IFG7
  case 22: break;                           // Vector 22:  ADC12IFG8
  case 24: break;                           // Vector 24:  ADC12IFG9
  case 26: break;                           // Vector 26:  ADC12IFG10
  case 28: break;                           // Vector 28:  ADC12IFG11
  case 30: break;                           // Vector 30:  ADC12IFG12
  case 32: break;                           // Vector 32:  ADC12IFG13
  case 34: break;                           // Vector 34:  ADC12IFG14
  default: break; 
  }
}

/*********************************************
   温度计算公式为
   Adc_Temp = ((((Adc_Num/4096)*Vref)-986mv)/3.55mv)
   当Vref=1.5V时
            Adc_Temp=(Adc_Num-2692)*423/4096;
   当Vref=2.5V时
            Adc_Temp=(Adc_Num-1617)*704/4096;
**********************************************/
u32 MCU_Tenp(u16 Temp_Value)
{
   u32 MCU_Temp =0;  
   Temp_Value = Temp_Value*2500/4096;
   MCU_Temp = (Temp_Value-1617)*704;    
   MCU_Temp = MCU_Temp/4096;
   return MCU_Temp;
//   Printf("read the ADC_Volt is %d mv\n",Volt_Average);
//   Printf("read the MCU_Temp is %d C\n",MCU_Temp);
//   Printf("\r\n");  Printf("\r\n");  
//   Delay_MS(1000);
}
  • /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     * 
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //  MSP430F543xA Demo - ADC12_A, Sample A10 Temp and Convert to oC and oF
    //
    //  Description: A single sample is made on A10 with reference to internal
    //  1.5V Vref. Software sets ADC12SC to start sample and conversion - ADC12SC
    //  automatically cleared at EOC. ADC12 internal oscillator times sample
    //  and conversion. In Mainloop MSP430 waits in LPM4 to save power until
    //  ADC10 conversion complete, ADC12_ISR will force exit from any LPMx in
    //  Mainloop on reti.
    //  ACLK = n/a, MCLK = SMCLK = default DCO ~ 1.045MHz, ADC12CLK = ADC12OSC
    //
    //  Uncalibrated temperature measured from device to devive will vary due to
    //  slope and offset variance from device to device - please see datasheet.
    //  Note:Use the TLV calibrated temperature to measure temperature 
    // (the TLV CALIBRATED DATA IS STORED IN THE INFORMATION SEGMENT, SEE DEVICE DATASHEET)
    //
    //                MSP430F5438A
    //             -----------------
    //         /|\|              XIN|-
    //          | |                 |
    //          --|RST          XOUT|-
    //            |                 |
    //            |A10              |
    //
    //   F. Chen
    //   Texas Instruments Inc.
    //   Dec. 2012
    //   Built with IAR Embedded Workbench Version: 5.51.1 & Code Composer Studio V5.2.1
    //******************************************************************************
    #include <msp430.h>
    
    #define CALADC12_15V_30C  *((unsigned int *)0x1A1A)   // Temperature Sensor Calibration-30 C
                                                          //See device datasheet for TLV table memory mapping
    #define CALADC12_15V_85C  *((unsigned int *)0x1A1C)   // Temperature Sensor Calibration-85 C
    
    unsigned int temp;
    volatile float temperatureDegC;
    volatile float temperatureDegF;
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      
      /* Initialize the shared reference module */ 
      REFCTL0 |= REFMSTR + REFVSEL_0 + REFON;    // Enable internal 1.5V reference
      
      /* Initialize ADC12_A */ 
      ADC12CTL0 = ADC12SHT0_8 + ADC12ON;		    // Set sample time 
      ADC12CTL1 = ADC12SHP;                     // Enable sample timer
      ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_10;  // ADC input ch A10 => temp sense 
      ADC12IE = 0x001;                          // ADC_IFG upon conv result-ADCMEMO
      
      __delay_cycles(75);                       // delay to allow Ref to settle
                                                // based on default DCO frequency.
                                                // See Datasheet for typical settle
                                                // time.
      ADC12CTL0 |= ADC12ENC;
    
      while(1)
      {
        ADC12CTL0 &= ~ADC12SC; 
    	ADC12CTL0 |= ADC12SC;                   // Sampling and conversion start
    
        __bis_SR_register(LPM4_bits + GIE);     // LPM4 with interrupts enabled
        __no_operation();
    	
        // Temperature in Celsius. See the Device Descriptor Table section in the
        // System Resets, Interrupts, and Operating Modes, System Control Module
        // chapter in the device user's guide for background information on the
        // used formula.
        temperatureDegC = (float)(((long)temp - CALADC12_15V_30C) * (85 - 30)) /
                (CALADC12_15V_85C - CALADC12_15V_30C) + 30.0f;
    
        // Temperature in Fahrenheit Tf = (9/5)*Tc + 32
        temperatureDegF = temperatureDegC * 9.0f / 5.0f + 32.0f;
        
        __no_operation();                       // SET BREAKPOINT HERE
      }
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=ADC12_VECTOR
    __interrupt void ADC12ISR (void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      switch(__even_in_range(ADC12IV,34))
      {
      case  0: break;                           // Vector  0:  No interrupt
      case  2: break;                           // Vector  2:  ADC overflow
      case  4: break;                           // Vector  4:  ADC timing overflow
      case  6:                                  // Vector  6:  ADC12IFG0
        temp = ADC12MEM0;                       // Move results, IFG is cleared
        __bic_SR_register_on_exit(LPM4_bits);   // Exit active CPU
        break;
      case  8: break;                           // Vector  8:  ADC12IFG1
      case 10: break;                           // Vector 10:  ADC12IFG2
      case 12: break;                           // Vector 12:  ADC12IFG3
      case 14: break;                           // Vector 14:  ADC12IFG4
      case 16: break;                           // Vector 16:  ADC12IFG5
      case 18: break;                           // Vector 18:  ADC12IFG6
      case 20: break;                           // Vector 20:  ADC12IFG7
      case 22: break;                           // Vector 22:  ADC12IFG8
      case 24: break;                           // Vector 24:  ADC12IFG9
      case 26: break;                           // Vector 26:  ADC12IFG10
      case 28: break;                           // Vector 28:  ADC12IFG11
      case 30: break;                           // Vector 30:  ADC12IFG12
      case 32: break;                           // Vector 32:  ADC12IFG13
      case 34: break;                           // Vector 34:  ADC12IFG14
      default: break;
      }
    }
    
  • 我用了你的程序,1.5V temperatureDegC = 18度左右,temperatureDegF = 65左右,摄氏度和华氏度应该差273度吧???想知道

    #define CALADC12_15V_30C *((unsigned int *)0x1A1A) // Temperature Sensor Calibration-30 C

                                                                                                          //See device datasheet for TLV table memory mapping

    #define CALADC12_15V_85C *((unsigned int *)0x1A1C) // Temperature Sensor Calibration-85 C

    这些数据是从哪里得到的,现在我想用2.5V参考电压如何修改呢,非常感谢您的答复!!!

  • 因为每个芯片出厂的时候存都在差异,在出厂的时候,TI做了一些典型温度下的校准,存在对应的位置里,可以在Datasheet里面TLV中看到。

  • 楼上那个表格没截全,不同的参考电压,校准参数是不同的。具体可以看数据手册 http://www.ti.com.cn/cn/lit/ds/symlink/msp430f5438a.pdf 第92页

  • 非常感谢,谢谢了