circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

Issue 140 March 2002
Replacing Relays with Ladder Logic
Part 1: Getting Ready for the Climb

 


by Fred Eady

Climbing the Ladder

Now that you have a good idea of what’s in the black box, I’m ready to make the T100MD888+ flash some of those status LEDs. The software package that comes with the T100MD888+ is impressive. Internet TRiLOGI V.5 is a suite of software tools that enables the T100MD888+ to be monitored and programmed locally or remotely using a standard serial port of a personal computer, your office Intranet, or the Internet.

TRiLOGI is a Java application; the Java run-time environment (JRE) needed to run it is included in the software package. Internet TRiLOGI is based on the client/server principle. Everything that TRiLOGI does, including accessing the T100MD888+, depends on running the TLServer application. TLServer acts as an HTML web server or Java applet with respect to Internet browsers like IE or Netscape. TLServer uses the PC serial port to connect to the T100MD888+ and acts as the message path between a PLC and the client. I’ve pulled out most of the available functionality of the TLServer for you to see in Photo 2.

(Click here To enlarge)

Photo 2—The TLServer provides a means of remotely controlling and monitoring multiple T100MD888+ devices either on a LAN or across the Internet. At least one T100MD888+ must be connected to the PC running the TLServer. The client also can access any other PLC connected to the server-connected PLC via RS-485. There’s even an e-mail function to send alerts or status messages from the PLC.

The client program is the application that allows the ladder logic code to be created and transferred to the server/ PLC anyway you can get it there. The TRiLOGI client runs as either a local Java application or a Java applet. The Java applet allows a remote computer to access the PLC using only a Java-enabled web browser. The local application mode assumes that all of the necessary TRiLOGI software resides on the local PC. For instance, I have one PC running the TLServer and Internet TRiLOGI that is dedicated to the T100MD888+. The server-connected T100MD888+ is attached to the serial port of the server PC. All of the other machines in the lab can access the PLC via their web browsers.

Photo 3 shows a log-in screen pointed at the PC running the TLServer from an arbitrary machine I had. After I’m logged in, the fun begins. Let’s start by writing a simple LED flasher ladder logic program and go through the steps of getting it from the editor screen to the T100MD888+ EEPROM.

(Click here to enlarge)

Photo 3—The only things I need to know are my user name, password, and where the TLServer resides regarding the IP. I added the user “fred” using the Add User box shown in Photo 2.

Like any other programming project, the first thing to do is get organized and define all of the inputs, outputs, and variables up front and then write your code to them. Using the TRiLOGI system, the definitions are predefined in the I/O table. You can also define I/O table items on the fly, like I will probably have to do as I move ahead with the project.

F2 or the Edit pull-down menu will get you to the I/O table. Let’s define input 1 as the normally open start contact. Momentarily closing the start contact (taking input 1 low) should energize an internal relay, which I’ll call run. A contact of the run relay will seal the start contact to keep it active after the start input goes active. I’ll also define a normally closed stop contact to demonstrate how to halt the LED sequencing.

As for output definitions, I’ll define LEDs one through four and assign them in that order to the output pins. I want to flash them starting with LED one and ending with LED four, and then reverse the flash order beginning with LED four. For that strategy to pan out, I’ll need to define one of the counters as a sequencer. I’ll define and use counter one as sequencer one in the I/O table.

A sequencer or counter needs a clock. A 1-s clock should do well here. The clock doesn’t have to be defined in the I/O table because I can select the clock source from the Special Bits panel when I build my ladder logic. All of the I/O table entries I made including the Special Bits panel are shown in Photo 4.

(Click here to enlarge)

Photo 4—This shot is actually a collection of each of the individual panels. The ladder logic labels are just like the #define statements in your C programs.

I put it all together using the six circuits shown in Photo 5. The idea is to get the voltage from the power line at the far left through the contacts to the coils at the opposite end. Closing the normally open start contact at the beginning of circuit one allows power to flow through the normally closed stop contact and energize the run relay. When the run relay is energized, all of its normally open contacts close and vice versa. Therefore, the run contact in parallel with the start contact is closed as long as the run relay is energized.

(Click here to enlarge)

Photo 5—You probably wouldn’t want to be running a motor with this ladder logic program, but it works well for flashing the LEDs on the T100MD888+.

The run contact in circuit one supplies power to the run relay just as it would in a physical hook-up, except the run relay doesn’t physically exist. In circuit two, a second set of normally open run contacts will close at the activation of the run relay in circuit one. The run relay contacts of circuit two supply power to your sequencer counter, which has a 50% duty cycle and a 1-s period.

The sequencer is edge-triggered. At each off-to-on transition of the sequencer one coil, Seq1:X, executes and closes the Seq1:X contact. The normally open Seq1:1 contact is closed first and provides a power path to output 1. Then, Seq1:2 closes for 1 s and so forth all the way through Seq1:8. Because there is no Seq1:9, the sequencer goes inactive and opens all of its contacts until the next off-to-on clock transition. Seq1:X in English translates to sequence one, step x.

Taking the stop input contact active opens the normally closed stop contact, which removes the power path to the run relay. The run relay de-energizes and all of the run contacts that are normally open revert to that state and vice versa.

And that’s just the beginning. TRiLOGI has the capability of mixing code with the relay coils using the TBASIC language. The best way to show you this is to modify the ladder logic program and add a custom function to print the name of each LED as it activates and tell you when they are all off.

Photo 6—The LCD is great for debugging because analog values can be shown in real time. Using my ladder logic-to-C comparison, using the LCD to print messages at certain points of the logic program is akin to using printf statements for debugging C code.

The modified ladder logic is shown in Photo 6. I already anticipated the custom function definitions, as the custom function panel is shown in Photo 4. In Photo 6, each custom function is in parallel with the output coil it represents. Thus, the custom function executes when its output coil is active. The contents of the custom functions are given collectively in Listing 1. I stopped the T100MD888+ to get the LED message shot in Photo 7.

Listing 1—If you tally the outcome, I wrote only four lines of code to provide a real-time visual indication of what my ladder logic program was doing.

 

(Click here to enlarge)

Photo 7—It’s easy to put words on the LCD. With the larger 4 × 20 format, you could hide the PLC and, using the LCD, present an eminence that portrays a more complicated and expensive embedded system.