PLCWannabe, the thing that is causing your
CT3.Acc to be reset on a power cycle is the fact that your
POWER_MONITOR Task code block is set to
retentive plus it is
on the 20-second delay at startup. This may sound counter-intuitive at first (like, if the Task is supposed to remember, then shouldn't it remember the Counter's count?). However, the default setting for a Task code block when you first create it is non-retentive. You have to manually set that to retentive either when creating the Task or by later configuring it that way. So, I don't know why you set it to retentive, or even if it really needs to be for your application, nevertheless...
The reason this happens is that internally, there is a system (i.e. hidden) bit in the Task code structure that tells it to
"run termination logic if you are ever disabled." By having your
POWER_MONITOR Task set to retentive, then on a power cycle, it remembers this bit. Thus, when it powers up and you have the
ENTASK programmed with a 20-second delay, the Task is powering up in the disabled state, so it runs termination logic, which resets all the Counters in the Task (among other things).
Also, as
ATU pointed out if you used a
UDCG counter instead of a
CNT, then the count will always be retained regardless of your Task code configuration (retentive or non-retentive) and regardless of your 20-second delay.
So, there are basically 3 different fixes:
- Use a UDCG Counter
- If you keep the 20-second delay, make the Task non-retentive
- Program the ENTASK without the 20-second delay, as you have already discovered