ALGO_Temperature_ATY.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @file ALGO_Temperature_ATY.h
  3. *
  4. * @param Project ALGO_Algorithm_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2026 MZ-ATY
  10. * - This code follows:
  11. * - MZ-ATY Various Contents Joint Statement -
  12. * <a href="https://mengze.top/MZ-ATY_VCJS">
  13. * https://mengze.top/MZ-ATY_VCJS</a>
  14. * - CC 4.0 BY-NC-SA -
  15. * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  16. * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
  17. * - Your use will be deemed to have accepted the terms of this statement.
  18. *
  19. * @brief functions of NTC or others temperature calc
  20. *
  21. * @version
  22. * - 1_01_230107 > ATY
  23. * -# Preliminary version, first Release
  24. * - 1_02_251120 > ATY
  25. * -# Full test
  26. ********************************************************************************
  27. */
  28. #ifndef __ALGO_Temperature_ATY_H
  29. #define __ALGO_Temperature_ATY_H
  30. #include "INCLUDE_ATY.h"
  31. /******************************* For user *************************************/
  32. /******************************************************************************/
  33. #define ALGO_TEMP_Kelvin_T0 0 // K
  34. #define ALGO_TEMP_Celsius_C0 0 // C
  35. #define ALGO_TEMP_Fahrenheit_F0 0 // F
  36. #define ALGO_TEMP_TtoC(T) ((T) - 273.15)
  37. #define ALGO_TEMP_CtoT(C) ((C) + 273.15)
  38. #define ALGO_TEMP_CtoF(C) ((C) * 1.8 + 32)
  39. #define ALGO_TEMP_FtoC(F) (((F) - 32 ) / 1.8)
  40. #define ALGO_TEMP_FtoT(F) (ALGO_TEMP_CtoT(ALGO_TEMP_FtoC((F))))
  41. #define ALGO_TEMP_TtoF(T) (ALGO_TEMP_CtoF(ALGO_TEMP_TtoC((T))))
  42. /**
  43. * @brief Calculate resistance from ADC voltage, NTC down(pull up)
  44. * @param vADC ADC voltage in mV
  45. * @param vRef NTC ref voltage in mV
  46. * @param rRefK ref resistance in kOhm
  47. */
  48. #define ALGO_VoltageToResDown(vADC, vRef, rRefK) \
  49. (((double)rRefK * (double)vADC) / ((double)vRef - (double)vADC))
  50. /**
  51. * @brief Calculate resistance from ADC voltage, NTC up(pull down)
  52. * @param vADC ADC voltage in mV
  53. * @param vRef NTC ref voltage in mV
  54. * @param rRefK ref resistance in kOhm
  55. */
  56. #define ALGO_VoltageToResUp(vADC, vRef, rRefK) \
  57. (((double)rRefK * ((double)vRef - (double)vADC)) / (double)vADC)
  58. double ALGO_ResToKelvinTemp(double Rntc, double R25, double B);
  59. double ALGO_VolToKelvinTemp(double vADC, double vRef, double rRefK, double R25, double B, uint8_t rRefPos);
  60. double ALGO_ResToKelvinTempABC(double Rntc, double A, double B, double C);
  61. double ALGO_Temp_RTD_T(double T);
  62. double ALGO_Temp_RTD_Res_Fast(double rtdRes);
  63. double ALGO_Temp_RTD_Res_Above(double rtdRes);
  64. double ALGO_Temp_RTD_Res_Below(double rtdRes);
  65. double ALGO_Temp_RTD_Res_PT100(double resist);
  66. double ALGO_Temp_RTD_Res_PT1000(double resist);
  67. double ALGO_Temp_TC_TempToVol(uint8_t type, double Temp);
  68. double ALGO_Temp_TC_VolToTemp(uint8_t type, double voltage);
  69. double ALGO_RT_Table_R2T(double R, const double* tableT, const double* tableR, uint16_t tableSize);
  70. double ALGO_RT_Table_T2R(double T, const double* tableT, const double* tableR, uint16_t tableSize);
  71. // #define ALGO_Temperature_ATY_Test_ATY
  72. #ifdef ALGO_Temperature_ATY_Test_ATY
  73. uint32_t ALGO_Temperature_ATY_Test(void);
  74. #endif /* ALGO_Temperature_ATY_Test_ATY */
  75. #endif /* __ALGO_Temperature_ATY_H */
  76. /******************************** End Of File *********************************/