STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
T7Convert.cpp
Go to the documentation of this file.
1#include "t7/T7Convert.hpp"
2
3#include <cmath>
4#include <limits>
5
8
9namespace fsw {
10namespace t7 {
11
12namespace {
13constexpr double kNaN = std::numeric_limits<double>::quiet_NaN();
14constexpr double kZeroC = 273.15;
15} // namespace
16
17double cjc_device_offset_k(double device_temp_k, double ain14_v) {
18 return device_temp_k - kAin14SlopeKPerV * ain14_v;
19}
20
21double cjc_temp_c(double ain14_v, double device_offset_k, double cjc_offset_k) {
22 return kAin14SlopeKPerV * ain14_v + device_offset_k + cjc_offset_k - kZeroC;
23}
24
25double pt_psi(double volts, const config::T7Channel& ch) {
26 double lo = 0, hi = 0;
27 if (ch.signal == "0-5V") {
28 lo = 0.0, hi = 5.0;
29 } else if (ch.signal == "0.5-4.5V") {
30 lo = 0.5, hi = 4.5;
31 } else if (ch.signal == "1-5V") {
32 lo = 1.0, hi = 5.0;
33 } else if (ch.signal == "0-10V") {
34 lo = 0.0, hi = 10.0;
35 } else if (ch.signal == "4-20mA") {
36 // The T7 measures the loop current as the voltage it develops across the shunt.
37 lo = 0.004 * ch.shunt_ohms, hi = 0.020 * ch.shunt_ohms;
38 } else {
39 return kNaN;
40 }
41 if (!(hi > lo) || !(ch.full_scale > 0))
42 return kNaN;
43 return (volts - lo) / (hi - lo) * ch.full_scale;
44}
45
46double lc_kg(double volts, const config::T7Channel& ch) {
47 const double rated_v = ch.sensitivity_mv_per_v / 1000.0 * ch.excitation_v;
48 if (!(rated_v > 0) || !(ch.full_scale > 0))
49 return kNaN;
50 return volts / rated_v * ch.full_scale;
51}
52
53double tc_c(double volts, double cold_junction_c) {
54 const double cj_mv = calibration::type_k_mv_from_c(cold_junction_c);
55 return calibration::type_k_c_from_mv(volts * 1000.0 + cj_mv); // NaN propagates
56}
57
58double rtd_ohms(double volts, const config::T7Channel& ch) {
59 if (!(ch.ljtr_ohms > 0) || !(volts > 0) || !(volts < ch.vref_v))
60 return kNaN;
61 return ch.ljtr_ohms * (ch.vref_v - volts) / volts;
62}
63
64double rtd_c(double volts, const config::T7Channel& ch) {
66 cvd.R0 = ch.r0_ohms;
68}
69
70const char* calibrated_field(const std::string& kind) {
71 if (kind == "PT")
72 return "pressure_psi";
73 if (kind == "TC" || kind == "RTD")
74 return "temperature_c";
75 if (kind == "LC")
76 return "force_kg";
77 return "";
78}
79
80} // namespace t7
81} // namespace fsw
double resistance_to_temp_cvd_full(double resistance_ohms, const CVDCoeffs &cvd=CVDCoeffs{})
The full CVD inverse: exact above 0 °C (the quadratic), Newton on the C term below it.
double type_k_mv_from_c(double c)
EMF (mV, referenced to 0 C) a type K produces at c.
Definition TypeK.cpp:38
double type_k_c_from_mv(double mv)
Temperature (C) for a type K EMF in mV, referenced to 0 C.
Definition TypeK.cpp:9
double cjc_device_offset_k(double device_temp_k, double ain14_v)
AIN14 offset (K) that makes slope*ain14_v land on the device's own temperature reading.
Definition T7Convert.cpp:17
constexpr double kAin14SlopeKPerV
The T7's internal temperature sensor (an LM94021 on AIN14) reads "Device temperature K =volts * -92....
Definition T7Convert.hpp:25
double lc_kg(double volts, const config::T7Channel &ch)
LC: a bridge's output is sensitivity x excitation at rated load.
Definition T7Convert.cpp:46
double rtd_ohms(double volts, const config::T7Channel &ch)
RTD on an LJTick-Resistance: the divider's output volts -> the RTD's ohms.
Definition T7Convert.cpp:58
const char * calibrated_field(const std::string &kind)
The Elodin field a calibrated channel of this kind publishes ("pressure_psi", ...),...
Definition T7Convert.cpp:70
double tc_c(double volts, double cold_junction_c)
Type K thermocouple: the measured EMF plus the EMF the cold junction subtracts.
Definition T7Convert.cpp:53
double cjc_temp_c(double ain14_v, double device_offset_k, double cjc_offset_k)
Cold-junction temperature (C) from a streamed AIN14 reading.
Definition T7Convert.cpp:21
double pt_psi(double volts, const config::T7Channel &ch)
PT: linear between the signal's zero and full-scale outputs.
Definition T7Convert.cpp:25
double rtd_c(double volts, const config::T7Channel &ch)
RTD: ohms -> C on the IEC 60751 curve (full Callendar-Van Dusen, C term below 0 C).
Definition T7Convert.cpp:64
Motorized ball valve position: raw ADC counts -> % open.
One streamed analog input.
Definition T7Config.hpp:37
static double volts(uint32_t code)
Shunt volts for a code, as calibration_main's convert_hp_pt_to_pressure computes it.
static std::string ch(int ain, const std::string &kind, const std::string &extra="", const std::string &board="lj")
Definition test_t7.cpp:98