Sunbic

Execute function/program once when PLC boots up

10 posts in this topic

Hey, this is driving me nuts. I have set up a TCP/IP chain communication between a CJ2 and multiple devices. I figured I could use the P_On to reset these communications and all of its data. In essence, it all has to be reset when the PLC does the power off/power on maneuver.

It works well.. except that when I switch to monitor mode the P_On blinks. Switching from program mode to monitor and viceversa causes the program to lose the P_On signal, so everything keeps resetting whenever someone connects to the PLC, and it's not like there's a hundred signals to choose from - as far as I know this is the only one I could use. That's the way it has to work, but it needs to be something that becomes active when the PLC boots up and essentially remains unaltered as long as the PLC is on.

Share this post


Link to post
Share on other sites

Put the desired code in a separate task with properties set for Operation Start.

Place a rung right before the END[001] of the task using  P_On followed by the TKOF[821] instruction that references the Task number.

Example shows this applied to task 0.

Capture.JPG

1 person likes this

Share this post


Link to post
Share on other sites

When you switch to program mode the PLC software stops processing - back to monitor mode and it starts processing again. Nothing you can do about that.

1 person likes this

Share this post


Link to post
Share on other sites

Or you can tie code to the first scan flag, not the always on flag.  P_On is always true.  There is a different variable for first cycle.

1 person likes this

Share this post


Link to post
Share on other sites

You could use this method using an H memory area retentive bit.

The code will only be processed at the very first power up in RUN.

From then on it will NEVER be scanned unless you manually reset H0.0.

Capture.JPG

1 person likes this

Share this post


Link to post
Share on other sites
On 20/2/2017 at 9:55 PM, Crossbow said:

Or you can tie code to the first scan flag, not the always on flag.  P_On is always true.  There is a different variable for first cycle.

I know, I tried - it didn't work. It's clear this behavior is tied to the process of the PLC, so I thought P_On was better suited for this situation. It's implied that it remains true as long as the PLC is on, but turns out it doesn't either, so no flag works here (as far as I know - I tried others).

On 20/2/2017 at 10:45 PM, BITS N BYTES said:

You could use this method using an H memory area retentive bit.

The code will only be processed at the very first power up in RUN.

From then on it will NEVER be scanned unless you manually reset H0.0.

Yes, this is it. I had the same idea yesterday - albeit using a DWORD channel, but I didn't like the idea of starting the program with a comparation. Thanks also for taking the time to make the pictures.

I'm going to try whenever I can and I'll update with the result. I'll also try your other option, that's an interesting feature that I've never used.

Edited by Sunbic

Share this post


Link to post
Share on other sites

For the record, none method works.

58b01b8e647eb_Sinttulo.png.fad69ad11aa86

I replaced the W bit with an H bit, it worked as expected, but nothing else does. Every instruction gets reset when switching to PROGRAM mode, no matter the flag that is executing them. The H didn't flicker and those timers jumped from 0 to their original values back and forth switching. And since the processing mode overrides the flag, moving the code to a separate task does not work either.

Edited by Sunbic

Share this post


Link to post
Share on other sites

TIMER and COUNTER instructions are ALWAYS reset when transitioning from RUN or MONITOR to PROGRAM.

There is an IOM bit A500.12 that can be set in the PLC setup to prevent this occurring but I would NOT recommend using it.

If you wish to have retentive timers then use one of the PLC Clock Pulse Bits to increment a D memory location.

Example below increments D100 every second. Note the @ before ++ for a rising edge trigger.

Capture.JPG

Edited by BITS N BYTES

Share this post


Link to post
Share on other sites

At first, I thought that there was no way to have a bit act differently when the machine is powered down vs when the PLC is switched to program and then back to Mon/Run.  However, after some thinking, I came up with this:

 

This is the only way that I can think of to do this.  In the main task, add this code:

w8rYbam7dwZMAAAAABJRU5ErkJggg==

This will turn the bit on when the PLC scans for the first time.  Make sure to use a retentive bit like H0.00 as shown. 

Then add the Power Failure Task as shown below:

1zXjVmVDt8gAAAABJRU5ErkJggg==

In the Power Failure Task, add this code:

dlsiZubh2eAAAAAASUVORK5CYII=

 

If I am thinking correctly, the top rung will set the bit on and it will stay on until the power is turned off on the PLC.  Then the last rung will run when power is turned off and this will turn off H0.00.  Then when power is turned back on, the bit will be turned back on by the First Scan flag.  Switching from Run/Mon to program and back will not turn off H0.00.  Let me know if it works.  It should....

 

Note that you have to enable the Power Off interrupt and set a power off detection time on the Timings tab of the PLC settings.

You may also want to change the normally open first scan flag (first rung above) to normally closed.  Then it will provide a leading edge signal on H0.00.

Share this post


Link to post
Share on other sites
On 24/2/2017 at 4:41 PM, Michael Walsh said:

If I am thinking correctly, the top rung will set the bit on and it will stay on until the power is turned off on the PLC.  Then the last rung will run when power is turned off and this will turn off H0.00.  Then when power is turned back on, the bit will be turned back on by the First Scan flag.  Switching from Run/Mon to program and back will not turn off H0.00.  Let me know if it works.  It should....

Note it does work; when you set on a retentive bit it stays unmodified (unlike the former P_On). The problem goes beyond the starting flag though. It looks like I just can't use timers here.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now