Author Topic: user defined function  (Read 6530 times)

kenobe

  • Jr. Member
  • Posts: 66
  • I'm a llama!
    • View Profile
user defined function
« on: September 16, 2008, 07:00:26 AM »
Hello
may I know how to do the following in one user defined function
a) read analog input 1 and store in variable A
b) add 2.5 to variable A
c)  if a>5 then turn on output 1, else turn off output2

thanks

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:user defined function
« Reply #1 on: September 16, 2008, 09:17:25 PM »
Since T100MD does not support floating point, assuming you don't use more than 1 decimal place, then use a fixed point of 1 = 0.1

A = ADC(1)*10   ' every unit represent 0.1
A = A + 25          ' Add 2.5 to A
IF A > 5 THEN
   SETIO OUT1
ELSE
   CLRIO OUT2  ' do you actually mean to turn OFF OUT1 and not OUT2?
ENDIF

Not too difficult isn't it? Note that the output 1 and 2 should be defined as OUT1 and OUT2 in their label name table.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

kenobe

  • Jr. Member
  • Posts: 66
  • I'm a llama!
    • View Profile
Re:user defined function
« Reply #2 on: September 16, 2008, 10:34:45 PM »
Thank you very much for your fast response.
but I have one question.

should the statement be

IF  a>50 ? instead of if A>5

Thanks

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:user defined function
« Reply #3 on: September 17, 2008, 12:18:24 AM »
Yeah you are right  :)
Email: support@triplc.com
Tel: 1-877-TRI-PLCS