17
17
18
18
namespace machinecontrol {
19
19
20
+ /* *
21
+ * The RTDClass allows enabling and selecting the different temperature sensor inputs
22
+ * (RTD and thermocouples)
23
+ */
20
24
class RTDClass {
21
25
public:
26
+
27
+ /* *
28
+ * Select the input channel to be read (3 channels available)
29
+ *
30
+ * @param channel (0-2)
31
+ */
22
32
void selectChannel (int channel) {
23
33
for (int i=0 ; i<3 ; i++) {
24
34
ch_sel[i] = (i == channel ? 1 : 0 );
25
35
}
26
36
delay (150 );
27
37
}
38
+
39
+ /* *
40
+ * Enable the CS of the Thermocouple to digital converter
41
+ * Disable the CS for the RTD to digital converter
42
+ */
28
43
void enableTC () {
29
44
rtd_th = 0 ;
30
45
digitalWrite (PI_0, LOW);
31
46
digitalWrite (PA_6, HIGH);
32
47
}
48
+
49
+ /* *
50
+ * Enable the CS of the RDT to digital converter.
51
+ * Disable the CS of the Thermocouple to digital converter
52
+ */
33
53
void enableRTD () {
34
54
rtd_th = 1 ;
35
55
digitalWrite (PI_0, HIGH);
36
56
digitalWrite (PA_6, LOW);
37
57
38
58
}
59
+
60
+ /* *
61
+ * Disable Chip select for both RTD and thermocouple digital converters.
62
+ *
63
+ */
39
64
void disableCS () {
40
65
digitalWrite (PI_0, HIGH);
41
66
digitalWrite (PA_6, HIGH);
@@ -53,9 +78,18 @@ extern RTDClass temp_probes;
53
78
54
79
static mbed::CAN _can (PB_8, PH_13);
55
80
81
+
82
+ /* *
83
+ * The COMMClass is used to initialize the CAN and RS485 LEDs and
84
+ * establish the power mode of the CAN bus.
85
+ */
56
86
class COMMClass {
57
87
public:
58
88
// to be tested: check if can be made a big pin initialization
89
+
90
+ /* *
91
+ * Shutdown RS485 and CAN LEDs
92
+ */
59
93
void init () {
60
94
// SHUTDOWN OF RS485 LEDS
61
95
digitalWrite (PinNameToIndex (PA_0), LOW);
@@ -73,9 +107,21 @@ class COMMClass {
73
107
rs485Slew (false );
74
108
}
75
109
110
+ /* *
111
+ * Set the CAN transceiver in Normal mode. In this mode, the transceiver
112
+ * can transmit and receive data via the bus lines CANH and CANL.
113
+ */
76
114
void enableCAN () {
77
115
can_disable = 0 ;
78
116
}
117
+
118
+ /* *
119
+ * Set the CAN transceiver in standby (low power) mode. In this mode the
120
+ * transceiver will not be able to transmit or correctly receive data via the bus lines.
121
+ * The wake-up filter on the output of the low-power receiver does not latch bus dominant states,
122
+ * but ensures that only bus dominant and bus recessive states that persist longer than tfltr(wake)
123
+ * bus are reflected on pin RXD.
124
+ */
79
125
void disableCAN () {
80
126
can_disable = 1 ;
81
127
}
@@ -118,8 +164,18 @@ extern COMMClass comm_protocols;
118
164
#define ch2_in3 ch_in[10 ]
119
165
#define ch2_in4 ch_in[11 ]
120
166
167
+ /* *
168
+ * The AnalogInClass is used to set the resistor configuration for the right type of analog sensor
169
+ * i.e. NTC sensors, 4-10mA or 0-10V.
170
+ */
121
171
class AnalogInClass {
122
172
public:
173
+
174
+ /* *
175
+ * read the sampled voltage from the selected channel
176
+ * @param channel integer for selecting the analog input (0, 1 or 2)
177
+ * @return the analog value between 0.0 and 1.0 normalized to a 16-bit value (uint16_t)
178
+ */
123
179
uint16_t read (int channel) {
124
180
uint16_t value = 0 ;
125
181
switch (channel) {
@@ -139,6 +195,10 @@ class AnalogInClass {
139
195
return value;
140
196
}
141
197
198
+ /* *
199
+ * Configure the input resistor dividers to have a ratio of 0.28.
200
+ * Maximum input voltage is 10V.
201
+ */
142
202
void set0_10V () {
143
203
ch0_in1 = 1 ;
144
204
ch0_in2 = 1 ;
@@ -156,6 +216,10 @@ class AnalogInClass {
156
216
ch2_in4 = 1 ;
157
217
}
158
218
219
+ /* *
220
+ * Enable a 120 ohm resistor to GND to convert the 4-20mA sensor currents to voltage.
221
+ * Note: 24V are available from the carrier to power the 4-20mA sensors.
222
+ */
159
223
void set4_20mA () {
160
224
ch0_in1 = 1 ;
161
225
ch0_in2 = 0 ;
@@ -173,6 +237,10 @@ class AnalogInClass {
173
237
ch2_in4 = 0 ;
174
238
}
175
239
240
+ /* *
241
+ * Enable a 100K resistor in series with the reference voltage.
242
+ * The voltage sampled is the voltage division between the 100k resistor and the input resistor (NTC/PTC)
243
+ */
176
244
void setNTC () {
177
245
ch0_in1 = 0 ;
178
246
ch0_in2 = 0 ;
@@ -217,6 +285,12 @@ extern AnalogInClass analog_in;
217
285
218
286
class AnalogOutClass {
219
287
public:
288
+
289
+ /* *
290
+ * Set output voltage value (PWM)
291
+ * @param index select channel
292
+ * @param voltage desired output voltage (max 10.5V)
293
+ */
220
294
void write (int index, float voltage) {
221
295
if (voltage < 0 ) {
222
296
voltage = 0 ;
@@ -237,6 +311,12 @@ class AnalogOutClass {
237
311
break ;
238
312
}
239
313
}
314
+
315
+ /* *
316
+ * Set the PWM period (frequency)
317
+ * @param index select channel
318
+ * @param period integer for selecting the period in ms
319
+ */
240
320
void period_ms (int index, uint8_t period) {
241
321
switch (index ) {
242
322
case 0 :
@@ -279,11 +359,21 @@ extern AnalogOutClass analog_out;
279
359
TODO: writeme
280
360
Use QEI library for mbed since it implements index pin
281
361
*/
362
+ /* *
363
+ * The EncoderClass is a wrapper for manipulating Quadrature Encoder Interface devices.
364
+ */
282
365
class EncoderClass {
283
366
public:
367
+ /* *
368
+ * returns the encoder variable depending on the index
369
+ * @param index integer for selecting the encoder (0 or 1)
370
+ * @return enc_0 for index = 0, enc_1 for index = 1
371
+ */
284
372
EncoderClass ()
285
373
: enc_0{PJ_8, PH_12, PH_11, 0 }
286
374
, enc_1{PC_13, PI_7, PJ_10, 0 } {};
375
+
376
+
287
377
QEI& operator [](int index) {
288
378
switch (index ) {
289
379
case 0 :
@@ -308,14 +398,35 @@ extern EncoderClass encoders;
308
398
TODO: check if Wire and address are correct
309
399
*/
310
400
401
+
402
+ /* *
403
+ * The ProgrammableDIOClass is used to initialize the IOExpanders and configure the
404
+ * thermal shutdown mode of the high side switches.
405
+ */
311
406
class ProgrammableDIOClass : public ArduinoIOExpanderClass {
312
407
public:
408
+
409
+ /* *
410
+ * Test connection with the IOExpander and set all the pins to the default mode.
411
+ * @return true if OK, false if fault
412
+ */
313
413
bool init () {
314
414
return begin (IO_ADD);
315
415
}
416
+
417
+ /* *
418
+ * Configures the thermal shutdown of the high-side switches (TPS4H160) to operate in latch mode.
419
+ * The output latches off when thermal shutdown occurs.
420
+ */
316
421
void setLatch () {
317
422
prog_latch_retry = 0 ;
318
423
}
424
+
425
+ /* *
426
+ * Configures the thermal shutdown of the high-side switches (TPS4H160) to operate in auto-retry mode.
427
+ * The output automatically recovers when TJ < T(SD) – T(hys), but the current is limited to ICL(TSD)
428
+ * to avoid repetitive thermal shutdown.
429
+ */
319
430
void setRetry () {
320
431
prog_latch_retry = 1 ;
321
432
}
@@ -326,20 +437,48 @@ class ProgrammableDIOClass : public ArduinoIOExpanderClass {
326
437
extern ProgrammableDIOClass digital_programmables;
327
438
328
439
440
+ /* *
441
+ * The DigitalOutputClass is used to interface with the IO Expander and
442
+ * set the digital outputs.
443
+ */
329
444
class DigitalOutputsClass {
330
445
public:
446
+
447
+ /* *
448
+ * Set all digital outputs at the same time.
449
+ * @param val 8 bit integer to set all 8 channels. e.g:
450
+ * Set all to HIGH -> val = 255 (0b11111111)
451
+ * Set all to LOW -> val = 0 (0b00000000)
452
+ */
331
453
void setAll (uint8_t val) {
332
454
for (int i = 0 ; i < 8 ; i++) {
333
455
out[i] = val & 0x1 ;
334
456
val = val >> 1 ;
335
457
}
336
458
}
459
+
460
+ /* *
461
+ * Set a particular digital output
462
+ * @param index digital output to be set
463
+ * @param val set value (HIGH/LOW)
464
+ */
337
465
void set (int index, bool val) {
338
466
out[index ] = val;
339
467
}
468
+
469
+ /* *
470
+ * Configures the thermal shutdown of the high-side switches (TPS4H160) to operate in latch mode.
471
+ * The output latches off when thermal shutdown occurs.
472
+ */
340
473
void setLatch () {
341
474
dig_out_latch_retry = 0 ;
342
475
}
476
+
477
+ /* *
478
+ * Configures the thermal shutdown of the high-side switches (TPS4H160) to operate in auto-retry mode.
479
+ * The output automatically recovers when TJ < T(SD) – T(hys), but the current is limited to ICL(TSD)
480
+ * to avoid repetitive thermal shutdown.
481
+ */
343
482
void setRetry () {
344
483
dig_out_latch_retry = 1 ;
345
484
}
@@ -358,14 +497,22 @@ extern DigitalOutputsClass digital_outputs;
358
497
359
498
class ProgrammableDINClass : public ArduinoIOExpanderClass {
360
499
public:
500
+ /* *
501
+ * Test connection with the IOExpander and set all the pins to the default mode.
502
+ * @return true if OK, false if fault
503
+ */
361
504
bool init () {
362
505
return begin (DIN_ADD);
363
506
}
364
507
};
365
508
366
509
extern ProgrammableDINClass digital_inputs;
367
510
368
-
511
+ /* *
512
+ * The RtcControllerClass is a wrapper for the PCF8563TClass() that is used to
513
+ * set and get the time to/from the PCF8563T RTC.
514
+ *
515
+ */
369
516
class RtcControllerClass : public PCF8563TClass {
370
517
public:
371
518
mbed::DigitalIn int_pin = mbed::DigitalIn(PB_9,PullUp);
@@ -376,21 +523,41 @@ class RtcControllerClass : public PCF8563TClass {
376
523
extern RtcControllerClass rtc_controller;
377
524
378
525
379
-
526
+ /* *
527
+ * The USB Class is used to enable/disable the power of the USBA (Host) and configure
528
+ * the callbacks for the different host types (i.e. Keyboard, mouse, storage device etc).
529
+ */
380
530
class USBClass {
381
531
public:
532
+ /* *
533
+ * Configures the USB host by providing the list of callbacks to support the behaviour
534
+ * of the host (keyboard, mouse, storage device etc)
535
+ *
536
+ * @param class_table a pointer to the structure containing the list of callbacks
537
+ */
382
538
void init (const tusbh_class_reg_t *class_table) {
383
539
usb.Init (USB_CORE_ID_FS, class_table);
384
540
}
385
541
542
+ /* *
543
+ * Enable power to USBA VBUS.
544
+ */
386
545
void powerEnable () {
387
546
power = 0 ;
388
547
}
389
548
549
+ /* *
550
+ * Disable power to USBA VBUS.
551
+ */
390
552
void powerDisable () {
391
553
power = 1 ;
392
554
}
393
555
556
+ /* *
557
+ * Flag to indicate overcurrent, overtemperature, or reverse−voltage conditions on the USBA VBUS.
558
+ * Active−low open−drain output.
559
+ * @return true if OK, false if fault
560
+ */
394
561
bool vflagRead () {
395
562
return usbflag;
396
563
}
0 commit comments