Home Page of Triangle Research International - The Programmable Controller (PLC) Specialist

World's first Ladder Logic PLC programmable via the Internet using only a web-browser!!

  Order On-line with Secure Socket Layer
(8:00am to 6:00pm PST)

E, H and M-series Programmable Logic ControllersLadder + Basic Programming SoftwarePLC Application Photos and Users' Application NotesContact Information, Distributor List and Testimonialdiscussions.gif (727 bytes)How to Place Order on-line or Off-Line
Click one of the above links

THE TBASIC LANGUAGE COMPONENTS

Download TRILOGI Software with TBASIC

1. Integer Variables

The TBASIC compiler in TRiLOGI Version 4.0 supports full 32-bit integer computations. All integer constants are treated as 32-bits and there are 26 variables (A to Z ) that are 32 bits in length. These variables can represent numbers between -231 to +231. The remaining system variables and data memory DM[n] are all 16-bit variables which means that they can only store numbers between -32768 to +32767. These 16-bit variables are:

DM[1]..DM[4000] (Total = 4000), input[n], output[n], relay[n], timerbit[n], ctrbit[n], timerPV[n],ctrPV[n], HSCPV[n], (High Speed Counter). TIME[n], DATE[n].

However, all numeric computations in TBASIC are carried out in 32-bit signed integers, regardless of the bit-length of the variables involved in the numerical expression. All variables used in TBASIC are "GLOBAL variables - this means that all these variables are shared and accessible by any of the 128 custom functions.

2. Integer Operators

a) Arithmetic Operators: +, -, *, /, MOD

b) Bit-wise Logical Operators:

Symbol Operation Example
& logical AND IF input[1] & &H02 ...
| logical OR output[1] = A | &H08
^ Exclusive OR A = RELAY[2] ^ B
~ logical NOT A = ~timerPV[1]

c) Relational Operators : Used exclusively for decision making expression in statement such as IF expression THEN ..... and WHILE expression ....

Symbol Operation Example
= Equal To IF A = 100
<> Not Equal To WHILE CTR_PV[0]<> 0
> Greater Than IF B > C/(D+10)
< Less Than IF TIME[3] < 59
>= Greater Than or Equal To WHILE X >= 10
<= Less Than or Equal To IF DM[I] <= 5678
AND Relational AND IF A>B AND C<=D
OR Relational OR IF A<>0 OR B=1000

3. String Data

A string is a sequence of alphanumeric characters (8-bit ASCII codes) which collectively form an entity. A string constant may contain from 0 to 70 characters enclosed in double quotation marks. e.g.

"TBASIC made PLC numeric processing a piece of cake!"

"$102,345.00"

TBASIC supports a maximum of 26 string variables A$, B$ ... Z$. Each string variable may contain from 0 (null string) up to a maximum of 70 characters.

4. String Operators

a) Assignment Operator: A string variable (A to Z, DM and system variables, etc) may be assigned a string expression using the assignment statement:

A$ = "Hello, Welcome To TBASIC"

Z$ = MID$(A$,3,5)

b) Concatenation Operators: Two or more strings can be concatenated (joined together) simply by using the "+" operator. e.g.

M$ = "Hello " + A$ + ", welcome to " + B$

If A$ contains "James", and B$ contains "TBASIC", M$ will contain the string: "Hello James, welcome to TBASIC.

c) Comparison Operators: Two strings may be compared for equality by using the function STRCMP(A$,B$). However, the integer comparator such as "=", "<>", etc cannot be used for string comparison.

5. TBASIC Statements and Functions

Most of the statements and functions of the powerful TBASIC language is tabulated below together with brief explanations for their purposes.

Command Purpose
ABS(x) To return the absolute value of x
ADC(n) To return the value from the A/D Converter #n.
ASC(x$,n) To return the ASCII code for the nth char. of x$.
CALL n To call another Custom Function CusFn #n.
CHR$(n) To convert a number n into its corresponding ASCII character. n must be between 0 and 255)
CLRBIT v,n To clear the Bit #n of the integer variable v to '0'.
FOR ... NEXT To execute a series of instructions for a specified number of times in a loop.
GetCtrSV (n)

GetTimerSV (n)

Return the Set Value (S.V) of Counter or Timer #n.
GETHIGH16(v) returns the upper 16-bit of a 32-bit integer variable
GOTO @ n To branch unconditionally to a specified line with label @n within the present Custom Function.
HEX$(n) To return a hexadecimal string expression of n.
HEXVAL(x$) To convert hexadecimal number in string x$.
HSTIMER n To define PLC Timer #1 to #n as “High Speed Timers” (HST) with time-base of 0.01s.
HSCDEF ch, fn,v Enable and set up parameters for the High Speed Counters channel ch.
HSCOFF ch Disable High Speed Counter #ch
IF .. THEN .. ELSE .. ENDIF To make a decision regarding program flow based on the result returned by an expression
INPUT$(ch) To get a string from communication port ch.
INTRDEF ch, fn,e Enable Interrupt Input channel ch and the interrupt service routine CusFn # fn
INTROFF ch Disable Interrupt Input channel ch.
LEN(x$) To return the number of characters in x$.
LOAD_EEP(addr) To obtain16-bit integer value from the EEPROM.
LSHIFT i,n To shift 1 bit to the left the 16-bit integer variable I,
MID$(x$,n,m) To extract a string of m characters from x$, beginning from the nth character
PAUSE To set a breakpoint for executing the CusFn
PIDdef ch, lmt, P,I,D To set up the parameters for a Proportional, Integral and Derivative (PID) Controller function.
PIDcompute

(ch,E)

Computes the output for the error E using the P,I,D value set by the PIDdef command.
PRINT# n x$;.. y; z.... To send the string formed by parameter list (x$; y; z) to communication port # n.
PMON ch

PMOFF ch

PMON enables Pulse Measurement Function at channel #ch. PMOFF disables the channel
PULSEFREQUENCY

PULSEPERIOD

PULSEWIDTH

Return in Hz the frequency of the last input pulse ; Return in milli-seconds the width and period of the input pulses arriving at channel ch.
REFRESH To immediately refresh of the physical outputs.
RESET To perform a software reset of the PLC
RETURN Unconditionally return to the caller function.
REM (or ') Put explanatory remarks in the program.
RSHIFT i,n To shift the integer variable i 1 bit to the right.
SAVE_EEP data, addr To store a 16-bit integer data in the user's definable EEPROM address addr.
SETBAUD ch, baud To set the communication “Baud Rate” of the PLC's serial channel #ch
SETBIT v,n To set the bit #n of the integer variable v to '1'.
SetCtrSV n, val

SetTimerSV n, val

Change the Set Value (S.V,) of the Counter #n or Timer #n to value
SETDAC n, x To set D/A converter #n to x
SETTHIGH16 v,d To assign the upper 16-bit of a 32-bit variable v
SETPWM n, x, y To set PWM channel #n with duty cycle x%.
STEPCOUNT(ch) Track the number of steps sent since STEPMOVE.
STEPSPEED ch, pps, acc Set the speed pps and acc for the PLC's stepper motor controller (pulse-generator) channel #ch.
STEPMOVE ch, count, r Activate the stepper motor pulse generator channel #ch to output count number of pulses.
STEPSTOP Immediately terminate Stepper controller #n
STR$(n) Convert the number n into a string expression.
STRCMP(A$, B$) Comparison of two strings: A$ and B$.
STRUPR$(A$) To return all upper-case copy of A$.
STRLWR$(A$) To return all-lower-case copy of A$.
TESTBIT (v,n) To return the logic state of bit #n of the variable v.
WHILE expression .... ENDWHILE To execute a series of statements in a loop as long as a given condition is true.
VAL(x$) To return a value of a number in the string x$.

 

mailbox.gif (1651 bytes)    
Email : info@tri-plc.com

Home of Programmable Logic Controllers (PLC)   
TRi Home Page

wpe1C.jpg (2003 bytes)
Contact Us

© Copyright 2001 Triangle Research International, Inc
All Rights Reserved