Internet PLC Forum

General => Technical support => Topic started by: Mark York on July 18, 2005, 01:13:49 PM

Title: T Basic statements
Post by: Mark York on July 18, 2005, 01:13:49 PM
I just purchased a T100MD1616+ PLC.
I'm really new to Basic programming but have done a ton of ladder. I'm trying to compare the value of data in one data register to another and if it is less than turn on a bit. I don't know if it's possible but have been playing with the following code without sucess (any ideas?)
IF DM[1] < DM[2]
THEN RELAY 5
ENDIF
Also it doesn't appear that Basic functions are allowed to be inserted before an output coil (like an in-line comparison) am I right?
Thank you
Mark
Title: Re:T Basic statements
Post by: support on July 18, 2005, 01:32:55 PM
To execute any TBASIC statement you need to trigger a custom function. The custom function contains the TBASIC statements and can appear as a coil to any ladder logic statement. You can choose the differentiated form (aka one-shot function, most commonly used and execute the function only once when the ladder condition goes from OFF to ON).

To perform comparision in TBASIC and to turn ON a relay, what you should do is to understand the TBASIC statements for turning on and off a relay. Easiest to use is the SETIO and CLRIO command. You need to define a label name for the relay that you wish to turn ON and OFF. E.g. Relay #1 can be called RLY1, then:

   IF DM[1] < DM[2]
         SETIO RLY1
   ELSE
         CLRIO RLY1
   ENDIF

This will be the first start. Try to go through those sample programs in the "TRiLOGI\TL5\usr\samples" folder to understand how the ladder+BASIC program works. I am sure you will like it once you understand how it works. It is a lot easier and more power than pure ladder logic language.
Title: Re:T Basic statements
Post by: EDGAR on July 18, 2005, 01:58:49 PM
TRY IT THIS WAY AND SEE IF IT WORKS

IF DM[1] < DM[2] THEN
SETBIT RELAY[1],5
'CLRBIT RELAY[1],5
ENDIF

RELAY 5 ON BANK ONE THE RELAYS GO FROM 0 TO 15 PER BANKS SO IF YOU WANT TO TURN ON RELAY 18 THEN YOU GO SETBITRELAY [2],1 THE SAME TO CLEAR CLRBIT RELAY[2],1

EXAMPLE:
B1 = 0 TO 15; B2 = 16 TO 31 BUT PROGRAMICALLY WILL BE 0 TO 15 TOO WHAT MAKE THE DIFFERENCE IS THE BANK NUMBER 1,2,3,4 AND SO ON. SETBIT RELAY[B2],1 = TURN ON RELAY 18 REMEBER WE START FROM 0 SO RELAY 16 IN REAL TERM IS 17 + 1 = #18 ON BANK 2

USE THE SETBIT TO ENERGIZE USE CLRBIT TO DE-ENERGIZE
I HOPE YOU GET IT...