DSP2803x_TempSensorConv.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //###########################################################################
  2. //
  3. // FILE: DSP2803x_TempSensorConv.c
  4. //
  5. // TITLE: DSP2803x ADC Temperature Sensor Conversion Functions
  6. //
  7. // This file contains funcions necessary to convert the temperature sensor
  8. // reading into degrees C or K.
  9. //
  10. // This program makes use of variables stored in OTP during factory
  11. // test on 2803x TMS devices only.
  12. // These OTP locations on pre-TMS devices may not be populated.
  13. // Ensure that the following memory locations in TI OTP are populated
  14. // (not 0xFFFF) before use:
  15. //
  16. // 0x3D7E90 to 0x3D7EA4
  17. //
  18. // Note that these functions pull data from the OTP by calling functions which
  19. // reside in OTP. Therefore the OTP wait-states (controlled by
  20. // FlashRegs.FOTPWAIT.bit.OTPWAIT) will significantly affect the time required
  21. // to execute these functions.
  22. //
  23. //###########################################################################
  24. // $TI Release: F2803x C/C++ Header Files and Peripheral Examples V130 $
  25. // $Release Date: May 8, 2015 $
  26. // $Copyright: Copyright (C) 2009-2015 Texas Instruments Incorporated -
  27. // http://www.ti.com/ ALL RIGHTS RESERVED $
  28. //###########################################################################
  29. #include "DSP2803x_Device.h" // DSP2803x Headerfile Include File
  30. #include "DSP2803x_Examples.h" // DSP2803x Examples Include File
  31. // Useful definitions
  32. #define FP_SCALE 32768 //Scale factor for Q15 fixed point numbers (2^15)
  33. #define FP_ROUND FP_SCALE/2 //Added to Q15 numbers before converting to integer to round the number
  34. // Amount to add to Q15 fixed point numbers to shift from Celsius to Kelvin
  35. // (Converting guarantees number is positive, which makes rounding more efficient)
  36. #define KELVIN 273
  37. #define KELVIN_OFF FP_SCALE*KELVIN
  38. // The folloing pointers to function calls are:
  39. //Slope of temperature sensor (deg. C / ADC code). Stored in fixed point Q15 format.
  40. #define getTempSlope() (*(int (*)(void))0x3D7E82)()
  41. //ADC code corresponding to temperature sensor output at 0 deg. C
  42. #define getTempOffset() (*(int (*)(void))0x3D7E85)()
  43. //This function uses the reference data stored in OTP to convert the raw temperature
  44. //sensor reading into degrees C
  45. int16 GetTemperatureC(int16 sensorSample)
  46. {
  47. return ((sensorSample - getTempOffset())*(int32)getTempSlope() + FP_ROUND + KELVIN_OFF)/FP_SCALE - KELVIN;
  48. }
  49. //This function uses the reference data stored in OTP to convert the raw temperature
  50. //sensor reading into degrees K
  51. int16 GetTemperatureK(int16 sensorSample)
  52. {
  53. return ((sensorSample - getTempOffset())*(int32)getTempSlope() + FP_ROUND + KELVIN_OFF)/FP_SCALE;
  54. }