05.05.2014 Views

csmstr - Omega Engineering

csmstr - Omega Engineering

csmstr - Omega Engineering

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

WRITING EXPRESSIONS<br />

COMPARING VALUES<br />

value by a floating-point value, the integer will be converted to floating-point before the<br />

division is carried out. However, there will be some situations where you want to force a<br />

conversion to take place.<br />

For example, suppose you are adding together three integers that represent the levels in three<br />

tanks, and then dividing the total by the tank count to obtain the average level. If you use an<br />

expression such as (Tank1+Tank2+Tank3)/3 then your result may not be as accurate as you<br />

demand, as the division will take place using integer math, and the average will not contain<br />

any decimal places. To force Crimson to evaluate the result using floating-point math, the<br />

simplest technique is to change the 3 to 3.0, thereby forcing Crimson to convert the sum to<br />

floating-point before the division is performed. A slightly more complex technique is to use<br />

syntax such as float(Tank1+Tank2+Tank3)/3. This invokes what is known as a “type cast”<br />

on the term in parentheses, manually converting it to floating-point.<br />

Type casts may also be used to convert a floating-point value to an integer value, perhaps<br />

deliberately giving-up some precision from an intermediate value before storing it in a PLC<br />

register. For example, the expression int(cos(Theta)*100) will calculate the cosine of an<br />

angle, multiply this value by 100 using floating-point math, and then convert it to an integer,<br />

dropping any digits after the decimal place.<br />

COMPARING VALUES<br />

You will quite often find that you wish to compare the value of one data with another, and<br />

make a decision based on the result. For example, you may wish to define a flag formula to<br />

show when a tank exceeds a particular value, or you may wish to use an if statement in a<br />

program to execute some code when a motor reaches its desired speed. The following<br />

comparison operators are provided…<br />

OPERATOR PRIORITY EXAMPLE<br />

Equal To Group 7 Data == 100<br />

Not Equal To Group 7 Data != 100<br />

Greater Than Group 6 Data > 100<br />

Greater Than or Equal To Group 6 Data >= 100<br />

Less Than Group 6 Data < 100<br />

Less Than or Equal To Group 6 Data

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!