ALGO_Temperature_ATY.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @file ALGO_Temperature_ATY.c
  3. *
  4. * @param Project ALGO_Algorithm_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2023 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 Familiar functions of NTC or others temperature calc
  20. *
  21. * @version
  22. * - 1_01_230107 > ATY
  23. * -# Preliminary version, first Release
  24. ********************************************************************************
  25. */
  26. #ifndef __ALGO_Temperature_ATY_C
  27. #define __ALGO_Temperature_ATY_C
  28. #include "ALGO_Temperature_ATY.h"
  29. /******************************* For user *************************************/
  30. /******************************************************************************/
  31. /**
  32. * @brief Calculate temperature from ntc resistance
  33. * @param Rntc Current NTC resistance value
  34. * @param R25 NTC standard resistance value at 25C
  35. * @param B B value of NTC
  36. * @return Current temperature in Celsius
  37. * @note T25: Kelvin temperature at 25C = 298.15 = ALGO_TEMP_CtoT(25)
  38. * R25: NTC standard resistance value at 25C like 10K,5K,100K...
  39. * B: B value of NTC like 3435,3950...
  40. * Rntc: Current NTC resistance value
  41. * Tn: Actual Kelvin temperature(Cn = Tn-273.15)
  42. * B = (lnR25 - lnRntc)/(1/T25 - 1/Tn)
  43. */
  44. float ALGO_ResToKelvinTemp(float Rntc, float R25, float B)
  45. {
  46. float Tn = 0.0;
  47. float Cn = 0.0;
  48. float temp_f[2];
  49. temp_f[0] = (ALGO_MATH_LogLn(R25) - ALGO_MATH_LogLn(Rntc)) / B;
  50. temp_f[1] = (1 / ALGO_TEMP_CtoT(25)) - temp_f[0];
  51. Tn = 1 / temp_f[1];
  52. Cn = ALGO_TEMP_TtoC(Tn);
  53. return Cn;
  54. }
  55. // resultTemp = ALGO_ResToKelvinTemp(ALGO_VoltageToResDown(resultTemp, vref_t, 10), 1, 3200);
  56. #endif /* __ALGO_Temperature_ATY_C */
  57. /******************************** End Of File *********************************/