0
$\begingroup$

Following my last question which confirmed that you can change the logic on a PLC while it is running, I'm now trying to understand the timings with which this happens.

Say that a PLC is sent a command to update its logic (I'm assuming that this can be done without using the PLC programming software, but could be wrong), and that the new, pending program code is stored in an area of memory which program execution then switches to when all of the new logic has been downloaded onto it. My questions are this:

1) Does a command need to be sent to switch to the new logic, or does this happen automatically once it has been downloaded?

2) Will the PLC switch to the new logic at the start of the next scan cycle (i.e. before that scan cycle's input scan), or at the start of the logic scan.

3) Would it always be that the new logic takes effect the scan cycle after it has finished being downloaded, or could there be a delay? I am trying to look for timing relationships between the networking data and the updated PLC logic, so need to be strict.

If anyone knows of any documentation for commands to update a PLC's logic while it is still running could they please point me to it?

Many thanks.

$\endgroup$
1
  • $\begingroup$ This is a good and detailed question, but more context would be helpful. What exactly are you trying to accomplish? If you're just debugging/tweaking logic while online, that's normal. But as Chuck said, downloading logic is not a precision operation. $\endgroup$ – Dan A. Nov 9 '16 at 20:41
2
$\begingroup$

Preface - I don't know of any way to program or download a PLC without using the associated programming software. Industrial PLCs are not cheap and generally not open source (that is, there is no API or other documentation on how to implement your own version of their programming software).

As mentioned in an answer your earlier question, the changes you are allowed to make without stopping the controller are generally limited to what is referred to as a "word for word" change, which means you can typically only replace one hard-coded constant for another.

So, to your questions:

  1. Like I mention above, you're generally changing one address with one address, or the contents of one register with one new register. There can be a list of changes like this, but that's the scope of what you're allowed to do. Changing logic, or the flow of the PLC, usually requires restarting. The changeover happens at the end of downloading, but I don't know this happens or what the trigger looks like; as I mentioned there's no explicit definition (that I've seen) of what the packet structure looks like for downloading software.

  2. I don't know what you mean when you call "logic scan" and "scan cycle" as two different terms. I don't think the change would happen mid-scan, but I could be wrong.

  3. I don't know if there could be a delay. Simple PLC code I work on has a sweep time of 10-15ms, complex PLC code has a sweep time of 30-40ms. This is a negligible amount of time relative to the amount of time to download new code, even if it IS just a word-for-word change. That word-for-word change may take 2-3 seconds to download, but that's maybe 100 cycles of the PLC.

I don't know what you're trying to do, but there shouldn't be any time where you're relying on downloading and re-downloading PLC code down and expecting to get timing accuracy down to the individual sweep cycle. Get an I/O card and toggle a switch, or write a message and toggle a bit, etc., if you need timing that close.

More background on what you're trying to do would be helpful. From your questions, "I'm looking for timing relationships between the networking data and the updated PLC logic" - again, I don't know WHY you care about this, downloading is a horrible way to switch code (that's what a switch statement is for, or a state machine), but what I would do would look like this pseudo-code:

loopCount = loopCount+1;
myConst = 5;
TCP_WRITE(loopCount, myConst);

You continuously read messages coming off the PLC. Each message gets 1) a number that increments every sweep, and 2) a number that is fixed.

You update the PLC code to change myConst from 5 to 6 or anything else, download the change, and see how many cycles elapse between when you push download and when myConst changes. You can have multiple constants, change them all, and see if they all update simultaneously or if loopCount increments between updates.

But again, seriously, don't expect to ever be able to reliably download logic to the individual sweep precision.

$\endgroup$
1
$\begingroup$

I'm not sure I agree with Chuck, or maybe I'm just not following what he's saying, so I'll have a go.

First of all, these questions might be easier to handle with a particular controller in mind, but I'll answer them assuming we're dealing with something mainstream such as Siemens or Allen-Bradley.

You can most definitely write an entire new module with hundreds of lines of codes and sometimes even create new variables and DB's (depending on processor) or extensively modify an existing module while a PLC is online and running, with negligible impact to the cycle time.

The timing of this will be the PLC will continue to loop through its typical scan/task assignment in parallel with the download. After download is finished there's going to be some sort of error checking / handshake to make the code is downloaded and complete. Some PLC's let you download the change, then test it, such as Allen-Bradley. And conversely you can remove it from test but leave it in the controller. Others, however, will immediately put it into effect when you download the change. Regardless of what initiates it, it will happen seemlessly, possibly between cycles, or perhaps if a module is updated prior to it being called in that scan/task cycle, it may call the new one. That depends on the controller.

A possible scenario: Cycle 1 (running old logic, downloading in parallel)
Cycle 2 (running old logic, downloaded finishes during scan)
Cycle 3 (running new logic)

But regardless, if your concern is if there's a delay in the scan cycle or if the processing is somehow interfered with during download, I would say no in most cases.

$\endgroup$
1
  • $\begingroup$ But I do agree with Chuck and mentioned in the earlier post making PLC changes are almost exclusively done through an ide that hides a lot of what were discussing in the background. I don't know of a plc that this wouldn't be the case. Maybe CoDeSys based PLC's still would have enough public information to make something yourself but I see no benefit and a high risk with thst. $\endgroup$ – DrTarr Nov 9 '16 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.