Author Topic: Program Question  (Read 5222 times)

DLUN

  • Newbie
  • Posts: 18
    • View Profile
Program Question
« on: January 26, 2010, 09:28:52 AM »
Will the program execute more than one custom function at  a time. I want to incriment a clock every second. But at the same time in anouther custom function I have a while loop to wait for enter to be pressed. Does this stop my clock counter?

-||------------------------------------------Incriment clock every 0.1s

-||------------------------------------------wait in while loop until enter is pressed then print message.

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Program Question
« Reply #1 on: January 26, 2010, 01:08:11 PM »
No. Custom functions are executed one at a time.

The PLC evaluates your ladder logic program one rung at a time from the top to bottom of your program.

If a custom function is invoked during the evaluation of a ladder logic rung, then the PLC will wait until the custom function completes before continuing to the next rung of the program.

If your custom function "waits" for some event, then execution of the PLC will wait, also.

You should rethink your approach.  If the "enter" key is a discrete input to the PLC, invoke a custom function when this key is pressed:

   Enter                   EnterPressed

----||-----------------------{dCusF}


This is only part of what you need to do, but it should point you in the right direction.

There are sample programs written for TriLogi's HMI interface.  Look for "HMIxxtoyy.PC6".  The HMI hardware looks like a bunch of separate input switches to the PLC. They demonstrate a method to handle input without hanging up the execution of the PLC program. Look for files with names: "HMIxxtoyy.PC6".  

Good luck,

Gary D.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:Program Question
« Reply #2 on: January 26, 2010, 01:34:48 PM »
Thanks Gary for the helpful reply.

Instead of waiting for something to happen and therefore lock up the CPU at a particular custom function, a better way is always to let your custom function check for the event (e.g check comm port data) and if there is no event, quite the C.F. and allows the CPu to come back later in the next scan or use a periodic clock pulse to trigger the custom function. E.g. you can check for the bar code data input from COMM1 every 0.5 second and only if it receives something would you act on it. Otherwise, just return from the custom function so that the CPU can scan the ladder logic and execute other functions.

None of the commands in TBASIC is blocking so unless you use the WHILE...ENDWHILE or endless GOTO the CPU will normally not be locked up in a certain custom function.

Email: support@triplc.com
Tel: 1-877-TRI-PLCS