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.

[参考译文] MSP432P401R:驱动程序库的版本3.21 .00.05 中的示例"ADC_14_single通道温度传感器和quot;出现问题

Guru**** 2589280 points
Other Parts Discussed in Thread: MSP432WARE

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/632925/msp432p401r-problems-with-the-example-adc_14_single_channel_temperature_sensor-in-version-3-21-00-05-of-the-driver-library

部件号:MSP432P401R
主题中讨论的其他部件:MSP432WARE

驱动程序库版本3.21 .00.05 中的示例“ADC_14_single通道温度传感器”的代码存在一些问题。  中断处理程序的原始代码是:

void ADC14_IRQHandler (void)

   UINT64_t状态;
   uINT32_t cal30,cal85;

   状态= ADC14_getEnabledInterruptStatus();
   ADC14_clearInterruptFlag (状态);

   IF (状态和ADC_INT0)
   {
       cal30 = sysctl_getTempCalibrationConstant (sysctl_2_5V_REF,
               sysctl_30_degrees_C);
       cal85 = sysctl_getTempCalibrationConstant (sysctl_2_5V_REF,
               sysctl_85_degrees_C);

       tempC =(float)(((UINT32_t) ADC14_getResult (ADC_MEM0)- cal30)*(85 - 30))
               /(cal85 - cal30)+ 30.0f;
       tempF = tempC * 9.0f / 5.0f + 32.0f;
   }

}


当我在版本2 MSP432 Launchpad上运行未经修改的示例时,我得到的温度读数为5.76 million degrees C 。似乎有点热。  问题是ADC的结果小于cal30。  由于变量是uin32_t,减去cal30将得到一个巨大的正数,而不是负数。  将类型更改为Int32_t可正确计算。  但是,我仍然没有得到一个合理的温度。  这些值包括:

cal30 = 4881
cal85 = 5626
ADC14_getResult返回(3638或接近该值的数字)

这将给出-ADC deg C 。因此校准常数错误或示例读取61.77 的方式有问题。

更新:我从另一个论坛条目中发现ADC设置中存在错误。  行:

ADC14_configureConversionMemory (ADC_MEM0,ADC_VREFPOS_AVCC_VREFNEG_VSS,ADC_INPUT_A22,FALSE);

应该是

ADC14_configureConversionMemory (ADC_MEM0,ADC_VREFPOS_INTBUF_VREFNEG_VSS,ADC_INPUT_A22,FALSE);

结果是25.7 deg C,这是合理的。


此外,当我在版本1 MSP432 Launchpad上运行代码时,我得到除以零错误。  这是因为在我拥有的XMS432 Rev B处理器上,cal30和cal85都定义为0xffff,所以分母(cal85 - cal30)为零。  代码应检查该问题。

我现在使用的中断例程是:

void ADC14_IRQHandler (void)

   UINT64_t状态;
   int32_t cal30,cal85,adcval,denom;

   状态= ADC14_getEnabledInterruptStatus();
   ADC14_clearInterruptFlag (状态);

   IF (状态和ADC_INT0)
   {
       cal30 = sysctl_getTempCalibrationConstant (sysctl_2_5V_REF,
               sysctl_30_degrees_C);
       cal85 = sysctl_getTempCalibrationConstant (sysctl_2_5V_REF,
               sysctl_85_degrees_C);

     adcval =(Int32_t) ADC14_getResult(ADC_MEM0);
   
     denom =(cal85 - cal30);
   
     如果(denom != 0)
       tempC =(浮点)((adcval - cal30)*(85 - 30))
          / denom + 30.0f;
      否则
         tempC =-40.0f;
   
       tempF = tempC * 9.0f / 5.0f + 32.0f;
   }

}

随着ADC14_configureConversionMemory的更改,这似乎可以解决问题。