hkim121397
 
I am currently running an alternating blinking program and I implemented a counter so that it can keep count of the # of cycles.
 
My issue is that the count value never stays when stopping/starting the PLC. %MW0 for some reason stays constantly at 0, while other addresses reset.
 
In the OpenPLC Editor, I have the count variable set to "retain". Would this be standard procedure, or are there additional steps that I should take?
 
I have persistent storage enabled and the board on RUN mode. I have the start up and stop/start runtime logs attached.
[203128%2F9176182%2Fmceclip0]
 
[203128%2F9176075%2Fmceclip0]
Reply 0 0
thiagoralves
There seems to be a bug with %MW0. Try moving it to %MW1 and see if it works
Reply 0 0
hkim121397
There seems to be a bug with %MW0. Try moving it to %MW1 and see if it works
When I use any other %MWx address, the count variable just resets and starts counting from 0 again
Reply 0 0
thiagoralves
What does your program look like? How about your persistent storage configuration? What is the update time on it?
Reply 0 0
hkim121397
I'm fairly new to PLC's (and OpenPLC, at that). I've been using the editor via ladder logic and would just upload the .st file to runtime.
 
[203128%2F9176542%2Fmceclip0]
 
Persistent storage configuration is at default (10s polling rate)
Reply 0 0
thiagoralves
The problem with your program is that even after loading the correct value of the count_val variable, it is immediately replaced with zero in the first scan cycle, as that's the CV output value of your CTU0 block.
Reply 0 0
hkim121397
My confusion there is that in the editor sim, the counter counts up fine.
 
Is there some sort of function block that would be able to store the value with each iteration and could be used for runtime to refer to?
 
If not, is there another way?
Reply 0 0
thiagoralves
The counter should be able to count just fine as well on the runtime, as you can probably see in the monitoring page. What won't happen is that, after stopping the runtime and starting again, the count resumes where it has stopped, because of your logical mistake in storing the variable. You're storing the output of the CTU block, not its internal count value. Therefore, when the program starts again, the CTU internal count is reset to zero, and your saved variable is set to zero as well. If you want to restore the internal CTU count when the program starts, you can use a CTUD block instead of a simple CTU. This block allows you to load an initial count value: https://infosys.beckhoff.com/english.php?content=../content/1033/tcplclib_tc2_standard/74402059.html&id=
Reply 0 0
hkim121397
 
I have a follow up question. I am using a CTUD as recommended, and I am using some move blocks to store the counter value.
 
However, the move block at the first rung only holds the value when it's disabled. I'm a little confused as to how its operating in this case. When it is enabled, it keeps at the last value it received and only starts to update itself again when it is disabled.
 
[203128%2F9183737%2Fmceclip0]
Reply 0 0
thiagoralves
I think you're facing another logic problem again. The EN pin works as a "Delete" key. When EN is disabled, the block is deleted. The runtime skips the execution of the block entirely, as if it didn't exist. So, in your case, whatever value was on count_val continues in there, as if the MOVE block didn't exist. The problem appears to be what follows that rung. Even if load_mem is true, moving cycle_count to count_val, you immediately after replace count_val with the CV output of your CTUD0 block (which most likely is zero on the first cycle), and then move this count_val (probably zero) back to cycle_count. So, by the end of the scan cycle, you end up with cycle_count as zero, instead of the initial value it came with.
Reply 0 0
Reply