Skip to content

Commit dc3631d

Browse files
create two different classes for the temp probes: RTD (RTDTempProbeClass) and TC (TCTempProbeClass)
1 parent 30609f8 commit dc3631d

9 files changed

+356
-191
lines changed

examples/Temp_probes_RTD/Temp_probes_RTD.ino

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,120 +25,120 @@
2525
void setup() {
2626
Serial.begin(9600);
2727
Serial.println("MAX31865 PT100 Sensor Test!");
28-
MachineControl_TempProbes.begin(TEMPPROBE_RTD, THREE_WIRE);
28+
MachineControl_RTDTempProbe.begin(THREE_WIRE);
2929
}
3030

3131
void loop() {
32-
MachineControl_TempProbes.selectChannel(0);
32+
MachineControl_RTDTempProbe.selectChannel(0);
3333
Serial.println("CHANNEL 0 SELECTED");
34-
uint16_t rtd = MachineControl_TempProbes.RTD.readRTD();
34+
uint16_t rtd = MachineControl_RTDTempProbe.readRTD();
3535
float ratio = rtd;
3636
ratio /= 32768;
3737

3838
// Check and print any faults
39-
uint8_t fault = MachineControl_TempProbes.RTD.readFault();
39+
uint8_t fault = MachineControl_RTDTempProbe.readFault();
4040
if (fault) {
4141
Serial.print("Fault 0x"); Serial.println(fault, HEX);
42-
if (MachineControl_TempProbes.RTD.getHighThresholdFault(fault)) {
42+
if (MachineControl_RTDTempProbe.getHighThresholdFault(fault)) {
4343
Serial.println("RTD High Threshold");
4444
}
45-
if (MachineControl_TempProbes.RTD.getLowThresholdFault(fault)) {
45+
if (MachineControl_RTDTempProbe.getLowThresholdFault(fault)) {
4646
Serial.println("RTD Low Threshold");
4747
}
48-
if (MachineControl_TempProbes.RTD.getLowREFINFault(fault)) {
48+
if (MachineControl_RTDTempProbe.getLowREFINFault(fault)) {
4949
Serial.println("REFIN- > 0.85 x Bias");
5050
}
51-
if (MachineControl_TempProbes.RTD.getHighREFINFault(fault)) {
51+
if (MachineControl_RTDTempProbe.getHighREFINFault(fault)) {
5252
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
5353
}
54-
if (MachineControl_TempProbes.RTD.getLowRTDINFault(fault)) {
54+
if (MachineControl_RTDTempProbe.getLowRTDINFault(fault)) {
5555
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
5656
}
57-
if (MachineControl_TempProbes.RTD.getVoltageFault(fault)) {
57+
if (MachineControl_RTDTempProbe.getVoltageFault(fault)) {
5858
Serial.println("Under/Over voltage");
5959
}
60-
MachineControl_TempProbes.RTD.clearFault();
60+
MachineControl_RTDTempProbe.clearFault();
6161
} else {
6262
Serial.print("RTD value: "); Serial.println(rtd);
6363
Serial.print("Ratio = "); Serial.println(ratio, 8);
6464
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
65-
Serial.print("Temperature = "); Serial.println(MachineControl_TempProbes.RTD.readTemperature(RNOMINAL, RREF));
65+
Serial.print("Temperature = "); Serial.println(MachineControl_RTDTempProbe.readTemperature(RNOMINAL, RREF));
6666
}
6767
Serial.println();
6868
delay(100);
6969

70-
MachineControl_TempProbes.selectChannel(1);
70+
MachineControl_RTDTempProbe.selectChannel(1);
7171
Serial.println("CHANNEL 1 SELECTED");
72-
rtd = MachineControl_TempProbes.RTD.readRTD();
72+
rtd = MachineControl_RTDTempProbe.readRTD();
7373
ratio = rtd;
7474
ratio /= 32768;
7575

7676
// Check and print any faults
77-
fault = MachineControl_TempProbes.RTD.readFault();
77+
fault = MachineControl_RTDTempProbe.readFault();
7878
if (fault) {
7979
Serial.print("Fault 0x"); Serial.println(fault, HEX);
80-
if (MachineControl_TempProbes.RTD.getHighThresholdFault(fault)) {
80+
if (MachineControl_RTDTempProbe.getHighThresholdFault(fault)) {
8181
Serial.println("RTD High Threshold");
8282
}
83-
if (MachineControl_TempProbes.RTD.getLowThresholdFault(fault)) {
83+
if (MachineControl_RTDTempProbe.getLowThresholdFault(fault)) {
8484
Serial.println("RTD Low Threshold");
8585
}
86-
if (MachineControl_TempProbes.RTD.getLowREFINFault(fault)) {
86+
if (MachineControl_RTDTempProbe.getLowREFINFault(fault)) {
8787
Serial.println("REFIN- > 0.85 x Bias");
8888
}
89-
if (MachineControl_TempProbes.RTD.getHighREFINFault(fault)) {
89+
if (MachineControl_RTDTempProbe.getHighREFINFault(fault)) {
9090
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
9191
}
92-
if (MachineControl_TempProbes.RTD.getLowRTDINFault(fault)) {
92+
if (MachineControl_RTDTempProbe.getLowRTDINFault(fault)) {
9393
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
9494
}
95-
if (MachineControl_TempProbes.RTD.getVoltageFault(fault)) {
95+
if (MachineControl_RTDTempProbe.getVoltageFault(fault)) {
9696
Serial.println("Under/Over voltage");
9797
}
98-
MachineControl_TempProbes.RTD.clearFault();
98+
MachineControl_RTDTempProbe.clearFault();
9999
} else {
100100
Serial.print("RTD value: "); Serial.println(rtd);
101101
Serial.print("Ratio = "); Serial.println(ratio, 8);
102102
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
103-
Serial.print("Temperature = "); Serial.println(MachineControl_TempProbes.RTD.readTemperature(RNOMINAL, RREF));
103+
Serial.print("Temperature = "); Serial.println(MachineControl_RTDTempProbe.readTemperature(RNOMINAL, RREF));
104104
}
105105
Serial.println();
106106
delay(100);
107107

108-
MachineControl_TempProbes.selectChannel(2);
108+
MachineControl_RTDTempProbe.selectChannel(2);
109109
Serial.println("CHANNEL 2 SELECTED");
110-
rtd = MachineControl_TempProbes.RTD.readRTD();
110+
rtd = MachineControl_RTDTempProbe.readRTD();
111111
ratio = rtd;
112112
ratio /= 32768;
113113

114114
// Check and print any faults
115-
fault = MachineControl_TempProbes.RTD.readFault();
115+
fault = MachineControl_RTDTempProbe.readFault();
116116
if (fault) {
117117
Serial.print("Fault 0x"); Serial.println(fault, HEX);
118-
if (MachineControl_TempProbes.RTD.getHighThresholdFault(fault)) {
118+
if (MachineControl_RTDTempProbe.getHighThresholdFault(fault)) {
119119
Serial.println("RTD High Threshold");
120120
}
121-
if (MachineControl_TempProbes.RTD.getLowThresholdFault(fault)) {
121+
if (MachineControl_RTDTempProbe.getLowThresholdFault(fault)) {
122122
Serial.println("RTD Low Threshold");
123123
}
124-
if (MachineControl_TempProbes.RTD.getLowREFINFault(fault)) {
124+
if (MachineControl_RTDTempProbe.getLowREFINFault(fault)) {
125125
Serial.println("REFIN- > 0.85 x Bias");
126126
}
127-
if (MachineControl_TempProbes.RTD.getHighREFINFault(fault)) {
127+
if (MachineControl_RTDTempProbe.getHighREFINFault(fault)) {
128128
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
129129
}
130-
if (MachineControl_TempProbes.RTD.getLowRTDINFault(fault)) {
130+
if (MachineControl_RTDTempProbe.getLowRTDINFault(fault)) {
131131
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
132132
}
133-
if (MachineControl_TempProbes.RTD.getVoltageFault(fault)) {
133+
if (MachineControl_RTDTempProbe.getVoltageFault(fault)) {
134134
Serial.println("Under/Over voltage");
135135
}
136-
MachineControl_TempProbes.RTD.clearFault();
136+
MachineControl_RTDTempProbe.clearFault();
137137
} else {
138138
Serial.print("RTD value: "); Serial.println(rtd);
139139
Serial.print("Ratio = "); Serial.println(ratio, 8);
140140
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
141-
Serial.print("Temperature = "); Serial.println(MachineControl_TempProbes.RTD.readTemperature(RNOMINAL, RREF));
141+
Serial.print("Temperature = "); Serial.println(MachineControl_RTDTempProbe.readTemperature(RNOMINAL, RREF));
142142
}
143143
Serial.println();
144144
delay(1000);

examples/Temp_probes_Thermocouples/Temp_probes_Thermocouples.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,31 @@
2121
void setup() {
2222
Serial.begin(9600);
2323
// Initialize temperature probes
24-
MachineControl_TempProbes.begin(TEMPPROBE_TC);
24+
MachineControl_TCTempProbe.begin();
2525
Serial.println("Temperature probes initialization done");
2626
}
2727

2828
void loop() {
2929
//Set CH0, has internal 150 ms delay
30-
MachineControl_TempProbes.selectChannel(0);
30+
MachineControl_TCTempProbe.selectChannel(0);
3131
//Take CH0 measurement
32-
float temp_ch0 = MachineControl_TempProbes.TC.readTemperature();
32+
float temp_ch0 = MachineControl_TCTempProbe.readTemperature();
3333
Serial.print("Temperature CH0 [°C]: ");
3434
Serial.print(temp_ch0);
3535
Serial.println();
3636

3737
//Set CH1, has internal 150 ms delay
38-
MachineControl_TempProbes.selectChannel(1);
38+
MachineControl_TCTempProbe.selectChannel(1);
3939
//Take CH1 measurement
40-
float temp_ch1 = MachineControl_TempProbes.TC.readTemperature();
40+
float temp_ch1 = MachineControl_TCTempProbe.readTemperature();
4141
Serial.print("Temperature CH1 [°C]: ");
4242
Serial.print(temp_ch1);
4343
Serial.println();
4444

4545
//Set CH2, has internal 150 ms delay
46-
MachineControl_TempProbes.selectChannel(2);
46+
MachineControl_TCTempProbe.selectChannel(2);
4747
//Take CH2 measurement
48-
float temp_ch2 = MachineControl_TempProbes.TC.readTemperature();
48+
float temp_ch2 = MachineControl_TCTempProbe.readTemperature();
4949
Serial.print("Temperature CH2 [°C]: ");
5050
Serial.print(temp_ch2);
5151
Serial.println();

src/Arduino_MachineControl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include "DigitalOutputsClass.h"
77
#include "ProgrammableDIOClass.h"
88
#include "ProgrammableDINClass.h"
9-
#include "TempProbesClass.h"
9+
#include "RTDTempProbeClass.h"
10+
#include "TCTempProbeClass.h"
1011
#include "RtcControllerClass.h"
1112
#include "USBClass.h"
1213
#include "EncoderClass.h"

src/CANCommClass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* The `CANCommClass` is a subclass of `mbed::CAN` and provides methods to work with the CAN Bus communication protocol on the Portenta Machine Control board.
2525
* It includes initialization of the corresponding LED for CAN.
2626
*/
27-
class CANCommClass: public mbed::CAN {
27+
class CANCommClass: public mbed::CAN { //TODO: Check ARDUINO API VERSION to use Arduino_CAN
2828
public:
2929
/**
3030
* @brief Construct a CANCommClass object.
Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
2-
* @file TempProbesClass.cpp
2+
* @file RTDTempProbeClass.cpp
33
* @author Leonardo Cavagnis
4-
* @brief Source file for the Temperature Probes connector of the Portenta Machine Control.
4+
* @brief Source file for the Resistance Temperature Detector (RTD) temperature sensor connector of the Portenta Machine Control.
55
*/
66

77
/* Includes -----------------------------------------------------------------*/
8-
#include "TempProbesClass.h"
8+
#include "RTDTempProbeClass.h"
99

1010
#if __has_include("portenta_info.h")
1111
#include "portenta_info.h"
@@ -15,45 +15,33 @@ uint8_t* boardInfo();
1515
#endif
1616

1717
/* Functions -----------------------------------------------------------------*/
18-
TempProbesClass::TempProbesClass(PinName ch_sel0_pin,
19-
PinName ch_sel1_pin,
20-
PinName ch_sel2_pin,
21-
PinName rtd_th_pin)
22-
: _ch_sel0{ch_sel0_pin}, _ch_sel1{ch_sel0_pin}, _ch_sel2{ch_sel2_pin}, _rtd_th{rtd_th_pin}
18+
RTDTempProbeClass::RTDTempProbeClass(PinName rtd_cs_pin,
19+
PinName ch_sel0_pin,
20+
PinName ch_sel1_pin,
21+
PinName ch_sel2_pin,
22+
PinName rtd_th_pin)
23+
: MAX31865Class(rtd_cs_pin), _rtd_cs{rtd_cs_pin}, _ch_sel0{ch_sel0_pin}, _ch_sel1{ch_sel0_pin}, _ch_sel2{ch_sel2_pin}, _rtd_th{rtd_th_pin}
2324
{ }
2425

25-
TempProbesClass::~TempProbesClass()
26+
RTDTempProbeClass::~RTDTempProbeClass()
2627
{ }
2728

28-
bool TempProbesClass::begin(uint8_t tempprobe_type, uint8_t io_address) {
29-
bool status = true;
30-
31-
switch(tempprobe_type) {
32-
case TEMPPROBE_RTD:
33-
TempProbesClass::RTD.begin(io_address);
34-
_enableRTD();
35-
break;
36-
case TEMPPROBE_TC:
37-
TempProbesClass::TC.begin();
38-
_enableTC();
39-
break;
40-
default:
41-
status = false;
42-
break;
43-
}
29+
bool RTDTempProbeClass::begin(uint8_t io_address) {
30+
MAX31865Class::begin(io_address);
4431

4532
pinMode(_ch_sel0, OUTPUT);
4633
pinMode(_ch_sel1, OUTPUT);
4734
pinMode(_ch_sel2, OUTPUT);
4835
pinMode(_rtd_th, OUTPUT);
4936

50-
pinMode(PI_0, OUTPUT);
51-
pinMode(PA_6, OUTPUT);
37+
pinMode(_rtd_cs, OUTPUT);
38+
39+
_enable();
5240

53-
return status;
41+
return true;
5442
}
5543

56-
void TempProbesClass::selectChannel(int channel) {
44+
void RTDTempProbeClass::selectChannel(int channel) {
5745

5846
#ifdef TRY_REV2_RECOGNITION
5947
// check if OTP data is present AND the board is mounted on a r2 carrier
@@ -98,28 +86,21 @@ void TempProbesClass::selectChannel(int channel) {
9886
delay(150);
9987
}
10088

101-
void TempProbesClass::end() {
102-
_disableCS();
103-
}
104-
105-
void TempProbesClass::_enableTC() {
106-
digitalWrite(_rtd_th, LOW);
107-
108-
digitalWrite(PI_0, LOW);
109-
digitalWrite(PA_6, HIGH);
89+
void RTDTempProbeClass::end() {
90+
MAX31865Class::end();
91+
92+
_disable();
11093
}
11194

112-
void TempProbesClass::_enableRTD() {
95+
void RTDTempProbeClass::_enable() {
11396
digitalWrite(_rtd_th, HIGH);
11497

115-
digitalWrite(PI_0, HIGH);
116-
digitalWrite(PA_6, LOW);
98+
digitalWrite(_rtd_cs, LOW);
11799
}
118100

119-
void TempProbesClass::_disableCS() {
120-
digitalWrite(PI_0, HIGH);
121-
digitalWrite(PA_6, HIGH);
101+
void RTDTempProbeClass::_disable() {
102+
digitalWrite(_rtd_cs, HIGH);
122103
}
123104

124-
TempProbesClass MachineControl_TempProbes;
105+
RTDTempProbeClass MachineControl_RTDTempProbe;
125106
/**** END OF FILE ****/

0 commit comments

Comments
 (0)