Wiki source code of Управление шпинделем по Modbus на примере Sunfar E550
Last modified by writer on 2023/06/06 16:59
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | You need next devises to control the spindle via Modbus: | ||
2 | |||
3 | 1. RS-485 adapter for connecting a frequency converter to a PC; | ||
4 | 1. frequency converter (FC) with support for control via Modbus RTU. | ||
5 | |||
6 | Modbus spindle control setting procedure: | ||
7 | |||
8 | 1. Set FC to the control mode using the Modbus RTU protocol (RS-485) and remember the COM port settings in FC (count of bits per second, data bits, parity and stop bits). | ||
9 | |||
10 | (% class="wrapped" %) | ||
11 | |=(% style="text-align: center; width: 150px;" %)Function code|=(% style="text-align: center; width: 100px;" %)Value|=(% style="text-align: center;" %)Description | ||
12 | |(% style="width:150px" %)F0.00|(% style="width:100px" %)2|Frequency reference source - external data transfer | ||
13 | |(% style="width:150px" %)F0.02|(% style="width:100px" %)0002|Trigger channel selection - serial data port | ||
14 | |(% style="width:150px" %)F4.00|(% style="width:100px" %)0114|Data transfer settings - speed selection: 9600 bps, parity check, Modbus data transfer protocol | ||
15 | |||
16 | (% style="margin-left: 30.0px;" %) | ||
17 | 2.Connect FC to the PC via the RS-485 adapter. You may need to install the driver for the RS-485 adapter for Windows. | ||
18 | |||
19 | (% style="margin-left: 30.0px;" %) | ||
20 | 3. Verify that the adapter in RS-485 was detected by the operating system. Use the Windows Device Manager for this. | ||
21 | |||
22 | (% style="margin-left: 30.0px;" %) | ||
23 | [[image:wndws_Device_Manager.png||data-xwiki-image-style-alignment="center" height="400" width="567"]] | ||
24 | |||
25 | Remember the COM port number of the device. It will be required in the next steps. | ||
26 | |||
27 | (% style="margin-left: 30.0px;" %) | ||
28 | 4. Purchase the "[[MODBUS protocol support>>url:http://pumotix.ru/#soft||shape="rect"]]" option or activate a trial period for this option in the menu "Configuration" → "License Manager" → "Common". | ||
29 | |||
30 | (% style="margin-left: 30.0px;" %) | ||
31 | 5. Enable and configure Modbus in the menu "Configuration" → "Modbus Setup". | ||
32 | |||
33 | Create new Modbus-master. Number of COM port is RS-485 adapter number. The rest of the settings should be exactly the same as in the FC (in the screenshot, an example of a standard configuration of the COM port of Sunfar E500). | ||
34 | |||
35 | [[image:COM_master_example.png||alt="master.png" data-xwiki-image-style-alignment="center" height="300" width="367"]] | ||
36 | |||
37 | You need to add registers to control the FC and read statuses from FC. For example you need to configure registers named **SpindleMode**, **SpindleRPM** and **SpindleStatus** for Sunfar E500. | ||
38 | |||
39 | We recommend using exactly these names, since in the future, registers will be accessed from background operations by their names. | ||
40 | |||
41 | [[image:Modbus_Settings_example.png||data-xwiki-image-style-alignment="center" height="444" width="1000"]] | ||
42 | |||
43 | {{success}} | ||
44 | Register numbers must be specified as decimal values. | ||
45 | {{/success}} | ||
46 | |||
47 | {{warning}} | ||
48 | These values can be indicated in HEX (hexadecimal) in the instructions for the frequency converter. For example, 0x1001, 0x1002 | ||
49 | {{/warning}} | ||
50 | |||
51 | (% style="margin-left: 30.0px;" %) | ||
52 | 6. Create new background operation (macro) through [[the macro manager>>doc:Руководство пользователя.Описание M-кодов.Управление макросами и фоновыми операциями.WebHome]]. | ||
53 | |||
54 | The main task of the background macro is to monitor the current state and spindle speed and send the values to the frequency converter via Modbus. | ||
55 | |||
56 | An example of [[background operation>>doc:Руководство пользователя.Описание фоновых операций.Создание фоновой операции.WebHome]] **modbus_spindle.bm** for ModBus spindle control posted in attachment. This file must be added to background operations list. | ||
57 | |||
58 | **[[Download background operation>>attach:modbus_spindle.zip]]** | ||
59 | |||
60 | {{warning}} | ||
61 | Access to Modbus registers from macros is done by the name of the Modbus register case sensitive! For example, **SpindleRPM** and **SpindleRpm** are different registers. | ||
62 | {{/warning}} | ||
63 | |||
64 | (% style="margin-left: 30.0px;" %) | ||
65 | 7. Enable the background operation. Make sure that the operation has started and is working properly. This will be indicated by the green indicator to the right of the operation name. | ||
66 | |||
67 | (% style="margin-left: 30.0px;" %) | ||
68 | [[image:Macros_Manager_wndw.png||data-xwiki-image-style-alignment="center" height="500" width="681"]] | ||
69 | |||
70 | The spindle should now turn on and off if everything is configured correctly. The spindle speed accordingly must also change at the FC when it changing in PUMOTIX. |