You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/05.pro-solutions/solutions-and-kits/portenta-machine-control/tutorials/pmc-modbus-rtu-plc-ide/assets/pmc_plcide_client_relaySet.svg
Copy file name to clipboardExpand all lines: content/hardware/05.pro-solutions/solutions-and-kits/portenta-machine-control/tutorials/pmc-modbus-rtu-plc-ide/assets/pmc_plcide_server_mainCode.svg
Copy file name to clipboardExpand all lines: content/hardware/05.pro-solutions/solutions-and-kits/portenta-machine-control/tutorials/pmc-modbus-rtu-plc-ide/assets/pmc_plcide_server_statVar.svg
Copy file name to clipboardExpand all lines: content/hardware/05.pro-solutions/solutions-and-kits/portenta-machine-control/tutorials/pmc-modbus-rtu-plc-ide/content.md
+66-17Lines changed: 66 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -184,9 +184,7 @@ The example project will be used to test the Modbus RTU connection between two P
184
184
185
185
To create a live handshake verification procedure between two Portenta Machine Control devices, the example project will slightly modify its default example code using the counter ('cnt') variable and broadcast the counter data.
186
186
187
-
-- TEST SETUP
188
-
189
-
Based on the counter data it receives from the "Modbus RTU Server Portenta Machine Control," the "Modbus RTU Client Portenta Machine Control" will activate the relay and the status LED. You may learn how to configure the Modbus RTU role for each Portenta Machine Control device using the role-specific sections.
187
+
Based on the counter data it receives from the "Modbus RTU Server Portenta Machine Control," the "Modbus RTU Client Portenta Machine Control" will control the programmable digital I/Os and the digital outputs. Each Portenta Machine Control will have a simple dedicated task using previously mentioned elements. You will learn how to configure the Modbus RTU role for each Portenta Machine Control device and its processes using the role-specific sections.
190
188
191
189
You may access the entire example project [here](assets/ModbusRTU_PMC_Example.zip) if you would like to test it right away. Every setting and component is ready to be assembled and uploaded to the corresponding Portenta Machine Control.
192
190
@@ -206,11 +204,11 @@ To configure the Portenta Machine Control as a Modbus RTU Server, navigate to th
206
204
207
205
Alternative values can be used per requirements if needed.
208
206
209
-
The subsequent image displays the `Status variables (volatile)` window. Within this window, we will define the `cnt` variable, specifying its access address and data type for Modbus RTU transmission.
207
+
The subsequent image displays the `Status variables (volatile)` window. Within this window, we will define the `counter_stack` variable, specifying its access address and data type for Modbus RTU transmission.
210
208
211
-

209
+

212
210
213
-
The `cnt` status variable uses the following parameters:
211
+
The `counter_stack` status variable uses the following parameters:
214
212
215
213
* Address: 25000 (dec) / 0x61A8 (hex)
216
214
* Name: cnt
@@ -238,6 +236,7 @@ IF counter_buffer >= delay_buffer THEN
238
236
cnt := 0;
239
237
END_IF;
240
238
counter_buffer := 0;
239
+
counter_stack := counter_stack + 1;
241
240
END_IF;
242
241
243
242
// Translate count to binary
@@ -249,11 +248,21 @@ DO_4 := SHR(cnt,4) AND 1;
249
248
DO_5 := SHR(cnt,5) AND 1;
250
249
DO_6 := SHR(cnt,6) AND 1;
251
250
DO_7 := SHR(cnt,7) AND 1;
251
+
252
+
IF counter_stack > 50 THEN
253
+
counter_stack := 0;
254
+
END_IF;
252
255
```
253
256
254
-
The role of the Portenta Machine Control server is to continually count until it hits `2750`, then reset. To transfer this counting task to the Portenta Machine Control, you can either select `Download PLC code` or simply hit `F7`. Once everything is in place, a successful upload will look like the image shown below.
257
+
The role of the Portenta Machine Control server will be to use a binary counter programmed with digital outputs parametrized with a sub-counter variable. The sub-counter variable will be defined as `cnt` and cycle within 8-Bit map value. The counter speed will be controlled by `counter_buffer` and `delay_buffer` as a customizable timed factor. We will use the `counter_stack` as the shared Modbus counter variable for the client Portenta Machine Control.
258
+
259
+

260
+
261
+
The `counter_buffer` and `delay_buffer` variables are added using `New Variable` option found within right-clicking on `Global_vars`. The `counter_buffer` can be added as an `automatic` variable, while `delay_buffer` variable has been added initially as a `constant` variable with initial value assigned.
255
262
256
-

263
+
To upload the main PLC code to the Portenta Machine Control, you can either select `Download PLC code` or simply hit `F7`. Once everything is in place, a successful upload will look like the image shown below.
264
+
265
+

257
266
258
267
Upon completing these steps, you will have effectively set up a Portenta Machine Control device to function as a Modbus RTU Server. The following section will guide you on how to configure another Portenta Machine Control as a Modbus RTU Client.
259
268
@@ -302,31 +311,59 @@ In this tutorial's demonstration, the client Portenta Machine Control is configu
302
311
303
312
The image below shows how it should look within the PLC IDE interface:
304
313
305
-

314
+

306
315
307
316
The OBJECT also needs labels to reference it later in the main PLC code. A table displaying the variable names designated for OBJECT can be seen below:
308
317
309
-

318
+

310
319
311
-
The main program below will be used to fetch counter data, control OBJECTS, and manage corresponding OBJECTS. A successful Modbus TCP communication will process previous tasks accordingly.
320
+
The main program below will be used to fetch counter data, control programmable digital I/Os, and manage corresponding digital outputs. A successful Modbus RTU communication will process previous tasks accordingly.
312
321
313
322
```arduino
314
-
counter := counter + 1;
323
+
counter := counter_rec;
315
324
316
-
IF counter >= 500 THEN
325
+
IF counter >= 10 THEN
317
326
DIO_0 := 1;
318
327
END_IF;
319
328
320
-
IF counter >= 1000 THEN
329
+
IF counter >= 20 THEN
330
+
DIO_1 := 1;
331
+
END_IF;
332
+
333
+
IF counter >= 30 THEN
334
+
DIO_2 := 1;
335
+
END_IF;
336
+
337
+
IF counter >= 40 THEN
338
+
DIO_3 := 1;
339
+
END_IF;
340
+
341
+
IF counter >= 50 THEN
321
342
DIO_0 := 0;
322
-
counter := 0;
343
+
DIO_1 := 0;
344
+
DIO_2 := 0;
345
+
DIO_3 := 0;
346
+
server_opCycle := server_opCycle + 1;
323
347
END_IF;
324
348
349
+
// Translate count to binary
350
+
DO_0 := server_opCycle AND 1;
351
+
DO_1 := SHR(server_opCycle,1) AND 1;
352
+
DO_2 := SHR(server_opCycle,2) AND 1;
353
+
DO_3 := SHR(server_opCycle,3) AND 1;
354
+
DO_4 := SHR(server_opCycle,4) AND 1;
355
+
DO_5 := SHR(server_opCycle,5) AND 1;
356
+
DO_6 := SHR(server_opCycle,6) AND 1;
357
+
DO_7 := SHR(server_opCycle,7) AND 1;
325
358
```
326
359
327
-
The `counter` variable serves as a global reference for the client Portenta Machine Control. On the other hand, `counter_rec` is tailored for Modbus, storing the data retrieved from the server Portenta Machine Control. We established this variable when setting up the 'Read Input Registers' Modbus function.
360
+
The `counter` variable serves as a global reference for the client Portenta Machine Control. On the other hand, `counter_rec` is tailored for Modbus, storing the data retrieved from the server Portenta Machine Control which is related to `counter_stack` data from server Portenta Machine Control. We established this variable when setting up the 'Read Input Registers' Modbus function.
361
+
362
+
The client Portenta Machine Control will use four digital programmable outputs and complete digital outputs as a operation indicator. Each time the `counter` marks new tenth value, it will activate corresponding digital programmable output to first digit of the counter value. For example, if the `counter` reaches `10`, the digital programmable output #1 will turn on.
363
+
364
+
Once the `counter` reaches `50` and resets, it will flag that one operation cycle has been completed. This will process will loop and use the digital outputs as a process cycle counter represented in a form of binary counter. This cyclic counter value is stored using `server_opCycle`.
328
365
329
-
Once you have successfully compiled and downloaded the main PLC code, the interface for the client Portenta Machine Control should mirror the image provided below:
366
+
With this, we will compile and upload the main PLC code, the interface for the client Portenta Machine Control should mirror the image provided below:
330
367
331
368

332
369
@@ -342,6 +379,18 @@ The following short clip shows a briefly expected behavior of the example projec
- Run a binary counter using digital outputs as visual indicators, mapped within 8-Bit boundary.
385
+
- Shared Modbus counter variable will increase every time 8-Bit binary counter completes one cycle.
386
+
- Binary counter speed can be controlled modifying buffer variables with desired values.
387
+
388
+
The client Portenta Machine Control will:
389
+
390
+
- Receive server counter information via Modbus protocol.
391
+
- Translate and trigger corresponding programmable digital I/Os.
392
+
- Use complete unit cycle of the programmable digital I/Os and represent total operation cycle with binary counter visualized using digital outputs.
393
+
345
394
## Conclusion
346
395
347
396
In this tutorial, you have learned to configure the workspace environment to work with Modbus RTU using Arduino PLC IDE and verified that Portenta Machine Control has been correctly set up and Modbus RTU communication is effective using an example project that controls Portenta Machine Control device's on-board features such as programmable digital I/Os and dedicated digital outputs based on customized example.
0 commit comments