Added calculation for PT100 and PT1000

master
Jan Beníček 2023-11-16 16:45:50 +01:00
parent a9909c8d2a
commit d007ee78c2
2 changed files with 124 additions and 0 deletions

70
Electric/RTD/PT100.cs Normal file
View File

@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calculations.Electric.TemperatureSensorsRecalculation
{
public static class PT100
{
private static readonly decimal KoeficientA = 0.0039083M;
private static readonly decimal KoeficientB = -0.0000005775M;
private static readonly decimal KoeficientC = -0.000000000004183M;
/// <summary>
/// Recalculate temperature to PT100 Resistance
/// </summary>
/// <param name="temperature">Temperature in °C</param>
/// <returns>Resistance</returns>
public static decimal TemperatureToResistance(decimal temperature)
{
if (temperature < 0)
{
return 100 * (1 + KoeficientA * temperature + KoeficientB * (decimal)Math.Pow((double)temperature, 2) + KoeficientC * (decimal)Math.Pow((double)temperature, 3) * (temperature - 100));
}
else
{
return 100 * (1 + KoeficientA * temperature + KoeficientB * (decimal)Math.Pow((double)temperature, 2));
}
}
/// <summary>
/// Recalculate PT100 resistance to Temperature
/// </summary>
/// <param name="resistance">Resistance PT100</param>
/// <returns>Temperature in °C</returns>
public static double ResistanceToTemperature(double resistance)
{
return (Math.Sqrt((double)KoeficientB * resistance - 100 * (double)KoeficientB + 25 * Math.Pow((double)KoeficientA, 2)) - 5 * (double)KoeficientA) / (double)(10 * KoeficientB);
}
/// <summary>
/// Recalculate PT100 resistance to Temperature
/// </summary>
/// <param name="resistance">Resistance PT100</param>
/// <returns>Temperature in °C</returns>
public static double ResistanceToTemperature(decimal resistance)
{
return ResistanceToTemperature((double)resistance);
}
}
}

54
Electric/RTD/PT1000.cs Normal file
View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calculations.Electric.RTD
{
public static class PT1000
{
private static readonly decimal KoeficientA = 0.0039083M;
private static readonly decimal KoeficientB = -0.0000005775M;
private static readonly decimal KoeficientC = -0.000000000004183M;
/// <summary>
/// Recalculate temperature to PT1000 Resistance
/// </summary>
/// <param name="temperature">Temperature in °C</param>
/// <returns>Resistance PT1000</returns>
public static decimal TemperatureToResistance(decimal temperature)
{
if (temperature < 0)
{
return 1000 * (1 + KoeficientA * temperature + KoeficientB * (decimal)Math.Pow((double)temperature, 2) + KoeficientC * (decimal)Math.Pow((double)temperature, 3) * (temperature - 100));
}
else
{
return 1000 * (1 + KoeficientA * temperature + KoeficientB * (decimal)Math.Pow((double)temperature, 2));
}
}
/// <summary>
/// Recalculate PT1000 resistance to Temperature
/// </summary>
/// <param name="resistance">Resistance PT1000</param>
/// <returns>Temperature in °C</returns>
public static double ResistanceToTemperature(double resistance)
{
return (Math.Sqrt((double)KoeficientB * (resistance / 10) - 100 * (double)KoeficientB + 25 * Math.Pow((double)KoeficientA, 2)) - 5 * (double)KoeficientA) / (double)(10 * KoeficientB);
}
/// <summary>
/// Recalculate PT1000 resistance to Temperature
/// </summary>
/// <param name="resistance">Resistance PT1000</param>
/// <returns>Temperature in °C</returns>
public static double ResistanceToTemperature(decimal resistance)
{
return ResistanceToTemperature((double)resistance);
}
}
}