Author Topic: How do I set a relay permanently using a custom function?  (Read 15986 times)

DLUN

  • Newbie
  • Posts: 18
    • View Profile
How do I set a relay permanently using a custom function?
« on: February 01, 2010, 09:12:02 AM »
Hello.

I have been trying to set a trip related relay using a custom function that is run every half a second.

The code is as follows:

If C> P ' trip condition
SetBIT Relay[2],15 ' trip relay
ENDIF

in latter logic I have the relay set to latch and activate a Master reset function.

However, it seems that the relay contact never closes outside the custom function.

Can you tell me what I am doing wrong?

Thank you and best regards.

Joel Moore

  • Full Member
  • Posts: 128
    • View Profile
Re:How do I set a relay permanently using a custom function?
« Reply #1 on: February 01, 2010, 02:32:06 PM »
Two possibilities come to mind:

1) You're not referencing the correct relay with your SetBit call.  But this should be obvious if you monitor the PLC and see which relay is turning on.  I prefer to use SETIO and CLRIO instead since it's much clearer.

2) You're resetting the relay somewhere else in the ladder.  Nothing gets committed until the scan of the ladder is complete.  So if on rung #5 you run your custom function but on rung #10 another custom function (or traditional ladder rung) is clearing that relay then the relay will never get set.  

bongofury

  • Newbie
  • *
  • Posts: 10
  • I'm a llama!
    • View Profile
Re:How do I set a relay permanently using a custom function?
« Reply #2 on: February 01, 2010, 05:47:14 PM »
Try this in your {dCusF} to experiment with:

C=2
P=1
if C>P
setioTripRelay
endif

Create a relay named TripRelay first.
You will need to provide a latch contact for it to stay latched.

Good Luck, Dave

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3177
    • View Profile
    • Internet Programmable PLCs
Re:How do I set a relay permanently using a custom function?
« Reply #3 on: February 02, 2010, 03:24:07 PM »
Also to be sure that this part of the code fragment was indeed executed:

If C> P ' trip condition
  SetBIT Relay[2],15 ' trip relay
  PAUSE
ENDIF

If the PLC pauses after SETBIT you know that it is executed. Now go online monitoring and check if the relay you want to set (it should be relay bit #32 since it is the bit 15 of second relay[] array).

If the relay is set, then release the PLC from PAUSE state by clicking on the PAUSE button. If the relay bit #32 goes off you know it has been turned off somewhere.

Note that if you use a MASTER RESET to reset the PLC, everything is cleared including the relays.

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