forked from arduino-libraries/Arduino_MachineControl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemp_probes_RTD.ino
149 lines (139 loc) · 5.08 KB
/
Temp_probes_RTD.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Portenta Machine Control - Temperature Probes RTD Example
*
* This example provides a method to test the 3-wire RTDs
* on the Machine Control Carrier. It is also possible to
* acquire 2-wire RTDs by shorting the RTDx pin to the TPx pin.
* The Machine Control Carrier features a precise 400 ohm 0.1% reference resistor,
* which serves as a reference for the MAX31865.
*
* Circuit:
* - Portenta H7
* - Portenta Machine Control
* - 3-wire RTD or 2-wire RTD
*
* Initial author: Riccardo Rizzo @Rocketct
*/
#include <Arduino_MachineControl.h>
// The value of the Rref resistor. Use 430.0 for PT100
#define RREF 400.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100
#define RNOMINAL 100.0
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
MachineControl_RTDTempProbe.begin(THREE_WIRE);
}
void loop() {
MachineControl_RTDTempProbe.selectChannel(0);
Serial.println("CHANNEL 0 SELECTED");
uint16_t rtd = MachineControl_RTDTempProbe.readRTD();
float ratio = rtd;
ratio /= 32768;
// Check and print any faults
uint8_t fault = MachineControl_RTDTempProbe.readFault();
if (fault) {
Serial.print("Fault 0x"); Serial.println(fault, HEX);
if (MachineControl_RTDTempProbe.getHighThresholdFault(fault)) {
Serial.println("RTD High Threshold");
}
if (MachineControl_RTDTempProbe.getLowThresholdFault(fault)) {
Serial.println("RTD Low Threshold");
}
if (MachineControl_RTDTempProbe.getLowREFINFault(fault)) {
Serial.println("REFIN- > 0.85 x Bias");
}
if (MachineControl_RTDTempProbe.getHighREFINFault(fault)) {
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
}
if (MachineControl_RTDTempProbe.getLowRTDINFault(fault)) {
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
}
if (MachineControl_RTDTempProbe.getVoltageFault(fault)) {
Serial.println("Under/Over voltage");
}
MachineControl_RTDTempProbe.clearFault();
} else {
Serial.print("RTD value: "); Serial.println(rtd);
Serial.print("Ratio = "); Serial.println(ratio, 8);
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
Serial.print("Temperature = "); Serial.println(MachineControl_RTDTempProbe.readTemperature(RNOMINAL, RREF));
}
Serial.println();
delay(100);
MachineControl_RTDTempProbe.selectChannel(1);
Serial.println("CHANNEL 1 SELECTED");
rtd = MachineControl_RTDTempProbe.readRTD();
ratio = rtd;
ratio /= 32768;
// Check and print any faults
fault = MachineControl_RTDTempProbe.readFault();
if (fault) {
Serial.print("Fault 0x"); Serial.println(fault, HEX);
if (MachineControl_RTDTempProbe.getHighThresholdFault(fault)) {
Serial.println("RTD High Threshold");
}
if (MachineControl_RTDTempProbe.getLowThresholdFault(fault)) {
Serial.println("RTD Low Threshold");
}
if (MachineControl_RTDTempProbe.getLowREFINFault(fault)) {
Serial.println("REFIN- > 0.85 x Bias");
}
if (MachineControl_RTDTempProbe.getHighREFINFault(fault)) {
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
}
if (MachineControl_RTDTempProbe.getLowRTDINFault(fault)) {
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
}
if (MachineControl_RTDTempProbe.getVoltageFault(fault)) {
Serial.println("Under/Over voltage");
}
MachineControl_RTDTempProbe.clearFault();
} else {
Serial.print("RTD value: "); Serial.println(rtd);
Serial.print("Ratio = "); Serial.println(ratio, 8);
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
Serial.print("Temperature = "); Serial.println(MachineControl_RTDTempProbe.readTemperature(RNOMINAL, RREF));
}
Serial.println();
delay(100);
MachineControl_RTDTempProbe.selectChannel(2);
Serial.println("CHANNEL 2 SELECTED");
rtd = MachineControl_RTDTempProbe.readRTD();
ratio = rtd;
ratio /= 32768;
// Check and print any faults
fault = MachineControl_RTDTempProbe.readFault();
if (fault) {
Serial.print("Fault 0x"); Serial.println(fault, HEX);
if (MachineControl_RTDTempProbe.getHighThresholdFault(fault)) {
Serial.println("RTD High Threshold");
}
if (MachineControl_RTDTempProbe.getLowThresholdFault(fault)) {
Serial.println("RTD Low Threshold");
}
if (MachineControl_RTDTempProbe.getLowREFINFault(fault)) {
Serial.println("REFIN- > 0.85 x Bias");
}
if (MachineControl_RTDTempProbe.getHighREFINFault(fault)) {
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
}
if (MachineControl_RTDTempProbe.getLowRTDINFault(fault)) {
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
}
if (MachineControl_RTDTempProbe.getVoltageFault(fault)) {
Serial.println("Under/Over voltage");
}
MachineControl_RTDTempProbe.clearFault();
} else {
Serial.print("RTD value: "); Serial.println(rtd);
Serial.print("Ratio = "); Serial.println(ratio, 8);
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
Serial.print("Temperature = "); Serial.println(MachineControl_RTDTempProbe.readTemperature(RNOMINAL, RREF));
}
Serial.println();
delay(1000);
}