The basic application that has been developed is suitable for simple machine or process application. However, the M221 has many capabilities that make it suitable for more complex application. This section looks at a few of those capabilities.
This Chapter Covers These Topics:
ii. Programming Languages
iii. Using the Ethernet Port
iv. Using the Serial Port
v. Real Time Clock
Templates are a way of creating a standard application that can be used as the basis for any new applications.
Taking the conveyor application that has been created, if an OEM or integrator creates many systems that have the same basic conveyor control system, this application can be saved as a template and used to create all new applications. This saves time recreating the basic application.
When an existing project is used to create a new project, the existing project may be accidentally overwritten when the new project is saved. The template is simply the project stored in a special format which can then be used to create new projects. When the new project is created from a template and saved, a new project must be created; the template cannot be overwritten.
How to Create a Template
With a project loaded, select Save As Template from the Save drop-down menu.
This will save the project as a template. However, it will not be visible on the start page unless it is saved in the correct directory. Templates should be saved to the directory
\Program Files\Schneider Electric\SoMachine Basic\Examples The template will then be visible from the start page.
Exercise - Templates
1. If SoMachine Basic is not running, start it and open the Conveyor Control Application.
2. Save the application as a template file.
i. Drop down the menu next to the save button and select Save as Template from the menu.
ii. Select the directory to save as:
\Program Files\Schneider Electric\SoMachine Basic\Examples
iii. Click the Save button to save the template.
3. Create a new application based on the template.
i. Click the SoMachine Basic icon to go to the start page.
ii. Select the Templates tab on the left hand side.
Select the Conveyor Control template and click the Open Template button.
iii. When the new application has been created, drop down the save selection box.
Note that the Save option is greyed out and the template cannot be overwritten.
Instruction list is a low-level programming language for SoMachine Basic. It uses a single memory location called an accumulator to load and combine values before the result is stored in an object. It is not the easiest programming language but it is the most flexible as results can be achieved that are not possible in other programming languages. However, as SoMachine Basic has the ability to switch between Instruction List and other programming languages some restrictions are placed on this flexibility.
The following is an example of Instruction List program.
When a SoMachine Basic application is downloaded to the M221 Logic Controller, the program is converted to Instruction List as this is what the controller actually processes. This can lead to some programming errors only being discovered when the application is downloaded.
Ladder is a popular programming language as it is similar to electrical diagrams and visually, it is very easy to see what the program is doing. With the addition of in-line status display, it is also very easy to debug.
It consists of a series of program lines or rungs, so called because they look like the rungs of a ladder. To the left of the rung are a set of inputs and conditions that must be solved. To the right of the rung is an object (or objects) defining what to do with the result.
A ladder rung may look something like the following:
Ladder does have some limitations though. It cannot perform all functions due to limitations in the programming rules and it must be converted to Instruction List before it is processed by the logic controller.
Switching Between Languages
There are two ways to switch between languages in SoMachine Basic.
To change the language of a single rung, drop down the language selection box in the rung and choose the required language.
To change all the rungs at the same time, click either the IL > LD button or the LD > IL button.
Using the Ethernet Port
Types of Addressing
The IP address can be configured in one of three ways:
For fixed IP addresses, the address is simply entered into the configuration section, along with the Subnet mask and Gateway if required. For DHCP or BOOTP there must be a DHCP or BOOTP server on the network to give the device its address.
With Fixed IP addressing, the IP address and subnet mask are entered as part of the M221 application configuration. The gateway can also be configured if required.
This means that the M221 has a known IP address but does require management of the IP address if the M221 is on anything but a small network.
Enter the required address details into the configuration form and click the Apply
DHCP uses a DHCP server to manage IP addresses so is much easier to configure within the M221. It is simply a case of selecting the DHCP Radio button.
If there is just one M221 on the network it can be easily identified. Device discovery in the Connection tab will show the network address of the M221 which can be selected to allow the software to connect to the controller.
If there are more controllers, then the network addresses of all the controllers will be visible. Currently it is difficult to distinguish between controllers as they do not announce their device name. The current work-around is to use USB to ensure that the correct controller is being programmed. This will be addressed in a future release of the software.
How to Set the IP Address
The IP address is configured as part of the hardware configuration on the configuration page. Select ETH1 from the Hardware Tree.
The Ethernet configuration will be displayed.
Choose the required options and click the Apply button.
Exercise - Ethernet Connection
1. Find the IP address of the programming computer.
i. If using Windows XP, go to the Start menu select Run.
If using Windows Vista or 7, go to the start menu and click the search box.
ii. Type CMD and press enter.
iii. In the command prompt window enter the command ipconfig.
There may be more than one adapter each with its own configuration. Look for the one that is connected to the network containing the M221. This will most likely be the one labelled "Local Area Connection".
iv. The two numbers required are the IP (or IPV4) address and the subnet mask. Write them in the first two rows of the table below.
|Programming Computer IP Address|
|M221 IP Address|
v. The subnet mask for the M221 will be the same as the subnet mask for the programming computer.
vi. The IP address for the M221 will be in the same IP range as the programming computer. To determine this apply the following rules. Where the subnet mask is not equal to zero, then the IP number must be the same. Where the subnet mask is equal to zero, the IP number will be different and a free number on the network. An example is given below.
|Programming Computer IP Address||192 . 168 . 0 . 4|
|Subnet Mask||255 . 255 . 255 . 0|
|M221 IP Address||192 . 168 . 0 . 101|
vii. Enter your own IP address into the third row of the first table in step (iv).
2. Configure the Ethernet Port.
i. Use the USB cable to connect to the M221 Logic Controller.
ii. Go to the configuration tab and from the Program Tree select ETH1.
iii. Select the Fixed IP address radio button and enter the M221 IP Address and Subnet Mask from the table in step 1(iv) on the previous page. The screenshot below shows the Ethernet address configured from the example table.
If you are on a large network do not continue with the exercise. The steps so far show how to configure the IP address but continuing may cause a duplicate IP address on the network.
iv. Click the Apply button.
3. Download to the M221 controller.
i. Connect to the M221 Logic Controller via USB and download the application.
ii. When the download has completed run the controller.
iii. Disconnect the USB cable
4. Reconnect via Ethernet
i. Connection can be made in two ways. Either:
Connect an Ethernet cable to the Ethernet port on the front of the M221 Logic Controller and an existing switch on the network.
Connect a crossover cable to the Ethernet port on the front of the M221 Logic Controller and plug the other end directly into the Ethernet port of the programming computer.
ii. SoMachine Basic will recognise the Ethernet connection and display the Ethernet address in the Ethernet Devices column.
Select the IP address and click the Login button.
iii. Go to the Programming tab and observe the status of the objects in the program and animation tables to confirm that SoMachine Basic is communicating with the M221 Logic Controller.
5. Program the M221 Logic Controller using the Ethernet connection.
i. Go to the Commissioning tab and logout from the controller.
ii. Go to the Program tab and select Timers from the Program tree
Change the time value for one of the conveyor stop timers.
iii. Go back to the Commissioning tab, make sure the Ethernet connection is still selected and login. Transfer the program as before.
Using the Serial Port
All M221 Logic Controllers are fitted with at least one serial port to allow serial communication to other devices. Those without an Ethernet port will have two serial ports fitted. The serial port uses a RJ45 connector so a special cable is required.
The serial port can be configured for RS232 or RS485 operation using either Modbus or ASCII protocols.
Setting the Parameters
There are several settings that can be configured on the serial port. These are divided into two categories, physical settings and protocol settings.
The physical settings allow the baud rate, parity and number of data and stop bits to be configured. RS232 or RS485 can also be selected here.
The protocol settings allow Modbus ASCII, Modbus RTU or plain ASCII to be selected and protocol specific settings configured for each.
To access the configuration settings, select SL1 (Serial line) from the Hardware Tree on the Configuration tab.
Where fitted, selecting SL2 (Serial line) will configure parameters for the second serial port.
The physical settings allow the physical characteristics of the serial port to be configured. These are the Baud rate, Parity, Data bits and Stop bits. It also allows either RS232 or RS485 to be selected,
If the protocol is set to one of the Modbus options then the Data bits selection will be greyed as this must always be 7 data bits.
Choosing the correct settings will depend on the application. A lower Baud rate for example, will improve communications in a noisy environment but at the cost of slower communication speed. Whatever settings are selected they must match the settings of the device to which the M221 is communicating.
The options for protocol settings will also depend on whether Modbus or ASCII is selected. If either Modbus ASCII or Modbus RTU is selected then the following options will appear:
The response time and time between frames are used for fine-tuning the communications. The main setting is whether the M221 Logic Controller is the master on the network or a slave. If it is a slave then the address is also configurable.
If the ASCII protocol is selected the following protocol options are available:
These settings are for fine-tuning the network and mainly used where interference is causing message loss or corrupted messages.
The serial port uses a RJ45 connector so a special cable is required.
If communicating with a XBT display then the VW3A8306Rxx cable with a RJ45 connector on both ends is required.
If communicating with a computer or printer then the TCSMCN3M4M3S2 cable is required. This has a RJ45 connector on one end and a 9 pin socket on the other.
If a special cable is required then the connections are given in the table below:
|4||Not Connected||D1 (A+)|
|5||Not Connected||D0 (B-)|
|7||Not Connected||Not Connected|
|8||0V Common||0V Common|
If making up a serial cable, all rules concerning RS232/RS485 distance and shielding must be followed to avoid errors or loss of communication. If in doubt, refer to a RS232 or RS485 wiring guide.
Real Time Clock
Setting the Clock
Settings are made in the RTC Management section which is in the Commissioning section of the Commissioning Tree.
There are two modes for setting the clock. The clock can either be set manually to a specific time and date or it can be synchronised to the computer time and date.
Using the Clock
The values for the Real Time Clock are accessible through five system registers which can be used to access the time and date.
|%SW49||Day of the week||xN where N=1 for Monday|
|%SW51||Hour and Minute||HHMM|
|%SW51||Month and Day||MMDD|
|%SW53||Century and Year||CCYY|
These values can be used for time-stamping information and events or measuring event duration.
Comparison blocks may be used to trigger an event at a particular time or on a particular date. For example, comparing %SW51 with a value representing a particular time can trigger an event at that time.
The values are in BCD but by viewing the values in Hexadecimal format, the date and time can be seen.
Exercise - Using the Real Time Clock
1. Create a new application in SoMachine Basic
i. Start SoMachine Basic and create a new application.
ii. Assign the correct controller to match the hardware.
iii. Save the application and give it the name "RTC Example".
2. Create the program.
i. Go to the programming tab and rename the POU, calling it "RTC".
ii. Rename the rung calling it "Time".
iii. Check the current time and add 3-4 minutes. Write this time here.
iv. Add a compare block to the rung and enter the expression %SW51 = 16#nnnn where nnnn is the time written above without any formatting characters. For example if the time now is 10:45, the expression would be %SW51 = 16#1048.
v. Add an output coil and assign the address %Q0.0 so the first output will turn on when the time is reached.
3. Display the values in an animation table.
i. Create an animation table and add the status words for the Real Time Clock; %SW49, %SW50, %SW51 and %SW52.
ii. Click the value displayed in the table and a selection box will allow the format to be change
Choose Hexadecimal for the four values.
4. Connect to the controller and test the application.
5. Change the RTC and test the application again.
6. Reset the M221 Controller clock to the correct time.
Subscribe to Makers India
Get the latest posts delivered right to your inbox