Skip to content

Commit f3d9cdd

Browse files
committed
Introduction of shared TempProbeClass
1 parent f69ca1a commit f3d9cdd

18 files changed

+680
-290
lines changed

docs/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ https://www.arduino.cc/reference/en/libraries/arduino_portentamachinecontrol/
1818
- Manages input signals, including:
1919
- 8 digital inputs at 24Vdc
2020
- 2 channels for encoder readings
21-
- 3 analog inputs for PT100/J/K temperature probes
21+
- 3 analog inputs for PT100 and TC J/K/T temperature probes
2222
- 3 analog inputs for 4-20mA/0-10V/NTC signals
2323

2424
- Manages output signals, including:
@@ -81,6 +81,7 @@ void loop() {
8181
- **[RTC_Alarm](../examples/RTC_Alarm):** This example demonstrates how to set up and utilize RTC alarms.
8282
- **[Temp_probes_RTD](../examples/Temp_probes_RTD):** This example demonstrates the temperature probe readings using RTD sensors.
8383
- **[Temp_probes_Thermocouples](../examples/Temp_probes_Thermocouples):** This example demonstrates the temperature probe readings using thermocouple sensors.
84+
- **[Temp_probes_Mixed](../examples/Temp_probes_Mixed):** This example demonstrates the temperature probe readings using both thermocouple and RTD sensors at the same time.
8485
- **[USB_host](../examples/USB_host):** This example shows the USB host functionality.
8586

8687
## API

docs/api.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
`class` [`RTDTempProbeClass`](#class-rtdtempprobeclass) | Class for managing the Resistance Temperature Detector (RTD) temperature sensor connector of the Portenta Machine Control.
1414
`class` [`RtcControllerClass`](#class-rtccontrollerclass) | Class for controlling the PCF8563T RTC of the Portenta Machine Control.
1515
`class` [`TCTempProbeClass`](#class-tctempprobeclass) | Class for managing the Thermocouple (TC) temperature sensor connector of the Portenta Machine Control.
16+
`class` [`TempProbeClass`](#class-tempprobeclass) | Class for managing the temperature sensor connector in mixed configurations of the Portenta Machine Control.
1617
`class` [`USBClass`](#class-usbclass) | Class for managing the USB functionality of the Portenta Machine Control.
1718

1819
# class `AnalogInClass`
@@ -128,11 +129,12 @@ Class for managing RTD temperature sensor inputs of the Portenta Machine Control
128129

129130
Members | Descriptions
130131
--------------------------------|---------------------------------------------
131-
`public ` [`RTDTempProbeClass`](#public-rtdtempprobeclasspinname-rtd_cs_pin--mc_rtd_cs_pin-pinname-ch_sel0_pin--mc_rtd_sel0_pin-pinname-ch_sel1_pin--mc_rtd_sel1_pin-pinname-ch_sel2_pin--mc_rtd_sel2_pin-pinname-rtd_th_pin--mc_rtd_th_pin)`(PinName rtd_cs_pin, PinName ch_sel0_pin, PinName ch_sel1_pin, PinName ch_sel2_pin, PinName rtd_th_pin)` | Construct a RTDTempProbeClass object.
132+
`public ` [`RTDTempProbeClass`](#public-rtdtempprobeclasspinname-rtd_cs_pin--mc_rtd_cs_pin-pinname-ch_sel0_pin--mc_tp_sel0_pin-pinname-ch_sel1_pin--mc_tp_sel1_pin-pinname-ch_sel2_pin--mc_tp_sel2_pin-pinname-rtd_th_pin--mc_rtd_th_pin)`(PinName rtd_cs_pin, PinName ch_sel0_pin, PinName ch_sel1_pin, PinName ch_sel2_pin, PinName rtd_th_pin)` | Construct a RTDTempProbeClass object.
132133
`public ` [`~RTDTempProbeClass`](#public-rtdtempprobeclass)`()` | Destruct the RTDTempProbeClass object.
133-
`public bool` [`begin`](#public-bool-beginuint8_t-io_address--three_wire)`(uint8_t io_address)` | Initialize the RTDTempProbeClass with the specified I/O address.
134+
`public bool` [`begin`](#public-bool-beginuint8_t-io_address--probe_rtd_3w)`(uint8_t io_address)` | Initialize the RTDTempProbeClass with the specified I/O address.
134135
`public void` [`end`](#public-void-end)`()` | Disable the temperature sensors and release any resources.
135136
`public void` [`selectChannel`](#public-void-selectchannelint-channel)`(int channel)` | Select the input channel to be read (3 channels available).
137+
`public float` [`readTemperature`](#public-float-readTemperaturefloat-rtdnominal-float-refresistor)`(float RTDnominal, float refResistor)` | Read temperature value of the connected RTD.
136138

137139
# class `RtcControllerClass`
138140
Class for controlling the PCF8563T RTC.
@@ -151,11 +153,27 @@ Class for managing thermocouples temperature sensor of the Portenta Machine Cont
151153

152154
Members | Descriptions
153155
--------------------------------|---------------------------------------------
154-
`public ` [`TCTempProbeClass`](#public-tctempprobeclasspinname-tc_cs_pin--mc_tc_cs_pin-pinname-ch_sel0_pin--mc_tc_sel0_pin-pinname-ch_sel1_pin--mc_tc_sel1_pin-pinname-ch_sel2_pin--mc_tc_sel2_pin)`(PinName tc_cs_pin, PinName ch_sel0_pin, PinName ch_sel1_pin, PinName ch_sel2_pin)` | Construct a TCTempProbeClass object.
156+
`public ` [`TCTempProbeClass`](#public-tctempprobeclasspinname-tc_cs_pin--mc_tc_cs_pin-pinname-ch_sel0_pin--mc_tp_sel0_pin-pinname-ch_sel1_pin--mc_tp_sel1_pin-pinname-ch_sel2_pin--mc_tp_sel2_pin)`(PinName tc_cs_pin, PinName ch_sel0_pin, PinName ch_sel1_pin, PinName ch_sel2_pin)` | Construct a TCTempProbeClass object.
155157
`public ` [`~TCTempProbeClass`](#public-tctempprobeclass)`()` | Destruct the TCTempProbeClass object.
156158
`public bool` [`begin`](#public-bool-begin)`()` | Initialize the TCTempProbeClass.
157159
`public void` [`end`](#public-void-end)`()` | Disable the temperature sensors and release any resources.
158160
`public void` [`selectChannel`](#public-void-selectchannelint-channel)`(int channel)` | Select the input channel to be read (3 channels available).
161+
`public float` [`readTemperature`](#public-float-readTemperatureuint8_t-type--probe_tc_k)`(uint8_t type)` | Read temperature value of the connected thermocouple.
162+
163+
# class `TempProbeClass`
164+
Class for managing Resistance Temperature Detector (RTD) and Thermocouple (TC) temperature sensor connectors of the Portenta Machine Control.
165+
166+
## Summary
167+
168+
Members | Descriptions
169+
--------------------------------|---------------------------------------------
170+
`public ` [`TempProbeClass`](#public-tctempprobeclasspinname-ch_sel0_pin--mc_tp_sel0_pin-pinname-ch_sel1_pin--mc_tp_sel1_pin-pinname-ch_sel2_pin--mc_tp_sel2_pin-pinname-tc_cs_pin--mc_tc_cs_pin-pinname-rtd_cs_pin--mc_rtd_cs_pin-pinname-rtd_th_pin--mc_rtd_th_pin)`(PinName ch_sel0_pin, PinName ch_sel1_pin, PinName ch_sel2_pin, PinName tc_cs_pin, PinName rtd_cs_pin, PinName rtd_th_pin)` | Construct a TempProbeClass object.
171+
`public ` [`~TempProbeClass`](#public-tctempprobeclass)`()` | Destruct the TCTempProbeClass object.
172+
`public bool` [`beginTC`](#public-bool-begintc)`()` | Initialize the TempProbeClass for TC measurements.
173+
`public bool` [`beginRTD`](#public-bool-beginrtd)`()` | Initialize the TempProbeClass for RTD measurements.
174+
`public void` [`endTC`](#public-void-endtc)`()` | Disable the TC temperature sensors and release any resources.
175+
`public void` [`endRTD`](#public-void-endrtd)`()` | Disable the temperature sensors and release any resources.
176+
`public void` [`selectChannel`](#public-void-selectchanneluint8_t-channel-uint8_t-uint8_t-probetype)`(uint8_t channel, uint8_t probeType)` | Select the input channel and probe type to be read (3 channels available).
159177

160178
# class `USBClass`
161179
Class for managing the USB functionality of the Portenta Machine Control.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Portenta Machine Control - Temperature Probes Mixed Example
3+
*
4+
* This example provides a method to test the RTD/TC inputs
5+
* on the Machine Control Carrier for mixed setups.
6+
*
7+
* Acquisition of 2-wire RTDs is possible by shorting the RTDx pin to the TPx pin.
8+
* The Machine Control Carrier features a precise 400 ohm 0.1% reference resistor,
9+
* which serves as a reference for the MAX31865.
10+
*
11+
* Circuit:
12+
* - Portenta H7
13+
* - Portenta Machine Control
14+
* - RTDs 3-wire or 2-wire
15+
* - TCs type K/J/T
16+
*
17+
* This example code is in the public domain.
18+
* Copyright (c) 2024 Arduino
19+
* SPDX-License-Identifier: MPL-2.0
20+
*/
21+
22+
#include <Arduino_PortentaMachineControl.h>
23+
24+
// The value of the Rref resistor.
25+
#define RREF 400.0
26+
// The 'nominal' 0-degrees-C resistance of the sensor
27+
// 100.0 for PT100
28+
#define RNOMINAL 100.0
29+
30+
void setup() {
31+
Serial.begin(9600);
32+
while (!Serial) {
33+
;
34+
}
35+
36+
// Initialize RTD temperature probes
37+
MachineControl_TempProbe.beginRTD();
38+
Serial.println("RTD Temperature probes initialization done");
39+
40+
// Initialize TC temperature probes
41+
MachineControl_TCTempProbe.beginTC();
42+
Serial.println("TC Temperature probes initialization done");
43+
}
44+
45+
void loop() {
46+
MachineControl_TempProbe.selectChannel(0, PROBE_RTD_3W);
47+
Serial.println("CHANNEL 0 SELECTED");
48+
uint16_t rtd = MachineControl_TempProbe.readRTD();
49+
float ratio = rtd;
50+
ratio /= 32768;
51+
52+
// Check and print any faults
53+
if (!checkRTDFault()) {
54+
Serial.print("RTD value: "); Serial.println(rtd);
55+
Serial.print("Ratio = "); Serial.println(ratio, 8);
56+
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
57+
Serial.print("Temperature = "); Serial.println(MachineControl_TempProbe.convertRTDTemperature(RNOMINAL, RREF));
58+
}
59+
Serial.println();
60+
delay(100);
61+
62+
//Set CH1, has internal 150 ms delay
63+
MachineControl_TempProbe.selectChannel(0, PROBE_TC_T);
64+
Serial.println("CHANNEL 0 SELECTED");
65+
//Take CH0 measurement
66+
float temp_ch1 = MachineControl_TempProbe.readTCTemperature();
67+
// Check and print any faults
68+
if (!checkTCFault()) {
69+
Serial.print("TC Temperature CH1 [°C]: ");
70+
Serial.print(temp_ch1);
71+
Serial.println();
72+
}
73+
74+
MachineControl_TempProbe.selectChannel(2, PROBE_RTD_3W);
75+
Serial.println("CHANNEL 2 SELECTED");
76+
rtd = MachineControl_TempProbe.readRTD();
77+
ratio = rtd;
78+
ratio /= 32768;
79+
80+
// Check and print any faults
81+
if (!checkRTDFault()) {
82+
Serial.print("RTD value: "); Serial.println(rtd);
83+
Serial.print("Ratio = "); Serial.println(ratio, 8);
84+
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
85+
Serial.print("Temperature = "); Serial.println(MachineControl_TempProbe.convertRTDTemperature(RNOMINAL, RREF));
86+
}
87+
Serial.println();
88+
delay(1000);
89+
}
90+
91+
bool checkRTDFault() {
92+
// Check and print any faults
93+
uint8_t fault = MachineControl_TempProbe.readRTDFault();
94+
if (fault) {
95+
Serial.print("Fault 0x"); Serial.println(fault, HEX);
96+
if (MachineControl_TempProbe.getRTDHighThresholdFault(fault)) {
97+
Serial.println("RTD High Threshold");
98+
}
99+
if (MachineControl_TempProbe.getRTDLowThresholdFault(fault)) {
100+
Serial.println("RTD Low Threshold");
101+
}
102+
if (MachineControl_TempProbe.getRTDLowREFINFault(fault)) {
103+
Serial.println("REFIN- > 0.85 x Bias");
104+
}
105+
if (MachineControl_TempProbe.getRTDHighREFINFault(fault)) {
106+
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
107+
}
108+
if (MachineControl_TempProbe.getRTDLowRTDINFault(fault)) {
109+
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
110+
}
111+
if (MachineControl_TempProbe.getRTDVoltageFault(fault)) {
112+
Serial.println("Under/Over voltage");
113+
}
114+
MachineControl_TempProbe.clearRTDFault();
115+
return true;
116+
} else {
117+
return false;
118+
}
119+
}
120+
121+
bool checkTCFault() {
122+
// Check and print any faults
123+
uint8_t fault = MachineControl_TempProbe.getTCLastFault();
124+
if (fault & TC_FAULT_OPEN) {
125+
Serial.println("Thermocouple is open - no connections.");
126+
return true;
127+
}
128+
if (fault & TC_FAULT_SHORT_GND) {
129+
Serial.println("Thermocouple is short-circuited to GND.");
130+
return true;
131+
}
132+
if (fault & TC_FAULT_SHORT_VCC) {
133+
Serial.println("Thermocouple is short-circuited to VCC.");
134+
return true;
135+
}
136+
return false;
137+
}

examples/Temp_probes_RTD/Temp_probes_RTD.ino

+24-56
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* - Portenta Machine Control
1313
* - 3-wire RTD or 2-wire RTD
1414
*
15-
* This example code is in the public domain.
15+
* This example code is in the public domain.
1616
* Copyright (c) 2024 Arduino
1717
* SPDX-License-Identifier: MPL-2.0
1818
*/
@@ -31,40 +31,20 @@ void setup() {
3131
;
3232
}
3333

34-
MachineControl_RTDTempProbe.begin(THREE_WIRE);
34+
MachineControl_RTDTempProbe.begin(PROBE_RTD_3W);
35+
Serial.println("RTD Temperature probes initialization done");
3536
}
3637

3738
void loop() {
39+
//Set CH0, has internal 75 ms delay
3840
MachineControl_RTDTempProbe.selectChannel(0);
3941
Serial.println("CHANNEL 0 SELECTED");
4042
uint16_t rtd = MachineControl_RTDTempProbe.readRTD();
4143
float ratio = rtd;
4244
ratio /= 32768;
4345

4446
// Check and print any faults
45-
uint8_t fault = MachineControl_RTDTempProbe.readFault();
46-
if (fault) {
47-
Serial.print("Fault 0x"); Serial.println(fault, HEX);
48-
if (MachineControl_RTDTempProbe.getHighThresholdFault(fault)) {
49-
Serial.println("RTD High Threshold");
50-
}
51-
if (MachineControl_RTDTempProbe.getLowThresholdFault(fault)) {
52-
Serial.println("RTD Low Threshold");
53-
}
54-
if (MachineControl_RTDTempProbe.getLowREFINFault(fault)) {
55-
Serial.println("REFIN- > 0.85 x Bias");
56-
}
57-
if (MachineControl_RTDTempProbe.getHighREFINFault(fault)) {
58-
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
59-
}
60-
if (MachineControl_RTDTempProbe.getLowRTDINFault(fault)) {
61-
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
62-
}
63-
if (MachineControl_RTDTempProbe.getVoltageFault(fault)) {
64-
Serial.println("Under/Over voltage");
65-
}
66-
MachineControl_RTDTempProbe.clearFault();
67-
} else {
47+
if (!checkRTDFault()) {
6848
Serial.print("RTD value: "); Serial.println(rtd);
6949
Serial.print("Ratio = "); Serial.println(ratio, 8);
7050
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
@@ -73,36 +53,15 @@ void loop() {
7353
Serial.println();
7454
delay(100);
7555

56+
//Set CH1, has internal 75 ms delay
7657
MachineControl_RTDTempProbe.selectChannel(1);
7758
Serial.println("CHANNEL 1 SELECTED");
7859
rtd = MachineControl_RTDTempProbe.readRTD();
7960
ratio = rtd;
8061
ratio /= 32768;
8162

8263
// Check and print any faults
83-
fault = MachineControl_RTDTempProbe.readFault();
84-
if (fault) {
85-
Serial.print("Fault 0x"); Serial.println(fault, HEX);
86-
if (MachineControl_RTDTempProbe.getHighThresholdFault(fault)) {
87-
Serial.println("RTD High Threshold");
88-
}
89-
if (MachineControl_RTDTempProbe.getLowThresholdFault(fault)) {
90-
Serial.println("RTD Low Threshold");
91-
}
92-
if (MachineControl_RTDTempProbe.getLowREFINFault(fault)) {
93-
Serial.println("REFIN- > 0.85 x Bias");
94-
}
95-
if (MachineControl_RTDTempProbe.getHighREFINFault(fault)) {
96-
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
97-
}
98-
if (MachineControl_RTDTempProbe.getLowRTDINFault(fault)) {
99-
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
100-
}
101-
if (MachineControl_RTDTempProbe.getVoltageFault(fault)) {
102-
Serial.println("Under/Over voltage");
103-
}
104-
MachineControl_RTDTempProbe.clearFault();
105-
} else {
64+
if (!checkRTDFault()) {
10665
Serial.print("RTD value: "); Serial.println(rtd);
10766
Serial.print("Ratio = "); Serial.println(ratio, 8);
10867
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
@@ -111,14 +70,27 @@ void loop() {
11170
Serial.println();
11271
delay(100);
11372

73+
//Set CH2, has internal 75 ms delay
11474
MachineControl_RTDTempProbe.selectChannel(2);
11575
Serial.println("CHANNEL 2 SELECTED");
11676
rtd = MachineControl_RTDTempProbe.readRTD();
11777
ratio = rtd;
11878
ratio /= 32768;
11979

12080
// Check and print any faults
121-
fault = MachineControl_RTDTempProbe.readFault();
81+
if (!checkRTDFault()) {
82+
Serial.print("RTD value: "); Serial.println(rtd);
83+
Serial.print("Ratio = "); Serial.println(ratio, 8);
84+
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
85+
Serial.print("Temperature = "); Serial.println(MachineControl_RTDTempProbe.readTemperature(RNOMINAL, RREF));
86+
}
87+
Serial.println();
88+
delay(1000);
89+
}
90+
91+
bool checkRTDFault() {
92+
// Check and print any faults
93+
uint8_t fault = MachineControl_RTDTempProbe.readFault();
12294
if (fault) {
12395
Serial.print("Fault 0x"); Serial.println(fault, HEX);
12496
if (MachineControl_RTDTempProbe.getHighThresholdFault(fault)) {
@@ -140,12 +112,8 @@ void loop() {
140112
Serial.println("Under/Over voltage");
141113
}
142114
MachineControl_RTDTempProbe.clearFault();
115+
return true;
143116
} else {
144-
Serial.print("RTD value: "); Serial.println(rtd);
145-
Serial.print("Ratio = "); Serial.println(ratio, 8);
146-
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
147-
Serial.print("Temperature = "); Serial.println(MachineControl_RTDTempProbe.readTemperature(RNOMINAL, RREF));
117+
return false;
148118
}
149-
Serial.println();
150-
delay(1000);
151-
}
119+
}

0 commit comments

Comments
 (0)