Skip to content

Commit 14d32fc

Browse files
committed
Tutorial content update
1 parent 9781b78 commit 14d32fc

File tree

4 files changed

+71
-17
lines changed

4 files changed

+71
-17
lines changed
Loading
Loading

content/hardware/05.pro-solutions/solutions-and-kits/portenta-machine-control/tutorials/pmc-modbus-tcp-plc-ide/content.md

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ With the necessary prerequisites in place and the tools for Modbus TCP configura
188188

189189
In this example, we will make a minor adjustment to the default example code by using the counter (`cnt`) variable. The counter information will be transmitted, facilitating real-time handshake verification between both Portenta Machine Control devices. For this tutorial, we will assign Ethernet properties manually to each device.
190190

191-
-- TEST SETUP
191+
Through the counter information provided by the 'Modbus TCP Server Portenta Machine Control', the 'Modbus TCP Client Portenta Machine Control' oversees the programmable digital I/Os and digital outputs. Each Portenta Machine Control focuses on a specific function using the elements mentioned earlier. You will learn to set the Modbus TCP role for each Portenta Machine Control device, following the sections dedicated for each specific role.
192192

193193
For those eager to dive right in, the full example project is available for download [here](assets/ModbusTCP_PMC_Example.zip). All crucial configurations and components are incorporated, so it is ready to be compiled and uploaded to the corresponding Portenta Machine Control device.
194194

@@ -250,6 +250,7 @@ IF counter_buffer >= delay_buffer THEN
250250
cnt := 0;
251251
END_IF;
252252
counter_buffer := 0;
253+
counter_stack := counter_stack + 1;
253254
END_IF;
254255
255256
// Translate count to binary
@@ -261,9 +262,19 @@ DO_4 := SHR(cnt,4) AND 1;
261262
DO_5 := SHR(cnt,5) AND 1;
262263
DO_6 := SHR(cnt,6) AND 1;
263264
DO_7 := SHR(cnt,7) AND 1;
265+
266+
IF counter_stack > 50 THEN
267+
counter_stack := 0;
268+
END_IF;
264269
```
265270

266-
The task running on the Portenta Machine Control server increments a basic counter, which resets once it hits `2750`. To begin the compilation and uploading of the code to the Portenta Machine Control, either choose the `Download PLC code` option or hit `F7`. An image illustrating a successful upload can be seen below.
271+
The main role of the Portenta Machine Control server is to operate a binary counter, programmed using digital outputs determined by a sub-counter variable, `cnt`. This variable operates within an 8-Bit value range. The counter's speed is modulated through `counter_buffer` and `delay_buffer`, using as adjustable timing parameters. For the client Portenta Machine Control, the shared Modbus counter variable known as `counter_stack` is used.
272+
273+
![Arduino PLC IDE - Portenta Machine Control Server Global Variables](assets/pmc_plcide_server_mainCode.svg)
274+
275+
To integrate the `counter_buffer` and `delay_buffer` variables, access the `New Variable` option by right-clicking on `Global_vars`. While `counter_buffer` can be designated as an `automatic` variable, `delay_buffer` was originally defined as a `constant` variable with a set value.
276+
277+
For deploying the main PLC code to the Portenta Machine Control, choose `Download PLC code` or simply press `F7`. With everything set up correctly, a successful upload should resemble the following image.
267278

268279
![Arduino PLC IDE - Portenta Machine Control Server Main Code](assets/pmc_plcide_server_mainCode.svg)
269280

@@ -321,32 +332,67 @@ void setup()
321332

322333
The `ip(192, 168, 1, 1)` represents the IP address of the Modbus TCP Master Portenta Machine Control. While you can modify the Internet Protocol properties as needed, it is essential to make sure the `subnet` aligns with that of your computer.
323334

324-
TODO EXPLAIN USED ONBOARD ELEMENTS OF THE PMC
335+
Next, set up a variable to store the counter data received from the server Portenta Machine Control. Navigate to the `Input Reg.` tab in the Modbus function configuration menu. From there, define a variable named `counter_rec` to save the data transmitted via the protocol.
336+
337+
Refer to the subsequent image for a visual guide to the desired configuration:
325338

326-
The image below shows how it should look within the PLC IDE interface:
339+
![Arduino PLC IDE - Portenta Machine Control Client Modbus Function of the Node (Input Reg.)](assets/pmc_plcide_client_modbusFunctionConfig_reg.png)
327340

328-
![Arduino PLC IDE - Portenta Machine Control Client OBJECT Table](assets/pmc_plcide_client_ledSet.svg)
341+
For the purposes of this tutorial, the client Portenta Machine Control has been set up to use digital programmable I/Os and digital outputs.
329342

330-
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:
343+
The image below provides a glimpse of its appearance within the PLC IDE interface:
331344

332-
![Arduino PLC IDE - Portenta Machine Control Client OBJECT Table](assets/pmc_plcide_client_relaySet.svg)
345+
![Arduino PLC IDE - Portenta Machine Control Client Digital Outputs Table](assets/pmc_plcide_device_localDO.png)
333346

334-
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.
347+
These elements also needs labels to reference it later in the main PLC code. A table displaying the variable names designated for digital programmable I/Os can be seen below:
348+
349+
![Arduino PLC IDE - Portenta Machine Control Client Digital Programmable I/O Table](assets/pmc_plcide_device_DIO.png)
350+
351+
The main program below will be used to fetch counter data, control programmable digital I/Os, and manage corresponding digital outputs. A successful Modbus TCP communication will process previous tasks accordingly.
335352

336353
```arduino
337-
counter := counter + 1;
354+
counter := counter_rec;
338355
339-
IF counter >= 500 THEN
356+
IF counter >= 10 THEN
340357
DIO_0 := 1;
341358
END_IF;
342359
343-
IF counter >= 1000 THEN
360+
IF counter >= 20 THEN
361+
DIO_1 := 1;
362+
END_IF;
363+
364+
IF counter >= 30 THEN
365+
DIO_2 := 1;
366+
END_IF;
367+
368+
IF counter >= 40 THEN
369+
DIO_3 := 1;
370+
END_IF;
371+
372+
IF counter >= 50 THEN
344373
DIO_0 := 0;
345-
counter := 0;
374+
DIO_1 := 0;
375+
DIO_2 := 0;
376+
DIO_3 := 0;
377+
server_opCycle := server_opCycle + 1;
346378
END_IF;
379+
380+
// Translate count to binary
381+
DO_0 := server_opCycle AND 1;
382+
DO_1 := SHR(server_opCycle,1) AND 1;
383+
DO_2 := SHR(server_opCycle,2) AND 1;
384+
DO_3 := SHR(server_opCycle,3) AND 1;
385+
DO_4 := SHR(server_opCycle,4) AND 1;
386+
DO_5 := SHR(server_opCycle,5) AND 1;
387+
DO_6 := SHR(server_opCycle,6) AND 1;
388+
DO_7 := SHR(server_opCycle,7) AND 1;
347389
```
348390

349-
The `counter` serves as a universal variable for the client Portenta Machine Control. Conversely, `counter_rec` is the Modbus variable that stores data fetched from the server Portenta Machine Control. We defined this variable when configuring the 'Read Input Registers' Modbus function.
391+
The `counter` variable acts as a universal reference for the client Portenta Machine Control. While, `counter_rec` is specifically defined for use with Modbus transactions, capturing data from the server Portenta Machine Control that relates to the `counter_stack` data. This particular variable was established during the 'Read Input Registers' Modbus function setup.
392+
393+
For operational indications, the client Portenta Machine Control will employ four digital programmable outputs, complemented by the full suite of digital outputs. Every time the `counter` registers a multiple of ten, the corresponding digital programmable output tied to that counter's first digit will be engaged. As an example, when the `counter` value reaches `10`, digital programmable output #1 gets activated.
394+
395+
When the `counter` achieves a value of `50` and then resets, it marks the end of an operational cycle. This mechanism is recurrent, with digital outputs representing the process cycle count in the form of a binary counter. The repeating counter value is stored in the `server_opCycle`.
350396

351397
The complete workspace interface for client Portenta Machine Control should resemble the following image once the main PLC code has been successfully compiled and downloaded to the client Portenta Machine Control:
352398

@@ -360,14 +406,22 @@ You can access the complete example project [here](assets/ModbusTCP_PMC_Example.
360406

361407
Set both Portenta Machine Control devices running with the corresponding main PLC code with the hardware setup explained in [this section](#hardware-setup). You will be able to observe the following results on client Portenta Machine Control periodically:
362408

363-
-- TEST RESULTS
364-
365-
For a visual representation of this behavior, refer to the following clip:
366-
367409
![Modbus TCP Example PLC IDE Project Result](assets/pmc_plcide_example_result.gif)
368410

369411
In the clip, the left window represents the Modbus TCP Client Portenta Machine Control, while the right window shows the Modbus TCP Server Portenta Machine Control.
370412

413+
The server Portenta Machine Control is tasked to:
414+
415+
- Run a binary counter, using digital outputs as visual cues, all encapsulated within an 8-Bit range.
416+
- Increase the shared Modbus counter variable whenever the 8-Bit binary counter finishes a cycle.
417+
- Tune the binary counter's pace by altering buffer variables to match preferred timing factors.
418+
419+
On the other hand, the client Portenta Machine Control will:
420+
421+
- Retrieve server-side counter data using the Modbus protocol.
422+
- Decode and trigger the appropriate programmable digital I/Os.
423+
- Harness the complete cycle of the programmable digital I/Os to denote the cumulative operation cycles, displayed through digital outputs in binary counter format.
424+
371425
## Conclusion
372426

373427
In this tutorial, you have learned how to configure the workspace environment for Modbus TCP using the Arduino PLC IDE and Portenta Machine Control.

0 commit comments

Comments
 (0)