WhyD register increases 2 times when timer is activated

Join Date
Feb 2023
Location
Romania
Posts
11
Hello,

I have a Xinje PLC XC3, where I have the attached program in memory..I don't understand why D1 register increases by 2 instead of 1, every 3 seconds (10 ms * 300 = 3 seconds for timer T298 to activate)

I expect the instruction

ADD K1 D1 D1

to add 1 to register D1 every 3 seconds, but instead I see it increasing by 2

Register D0 however increases by 1 every 3 seconds..as expected

Regards

1.png
 
It seems to me that T298 is stopping on for more than one scan
I don't know what M3995 is but perhaps put a not T298 in the rung this will reset the timer after it times out on the next scan also you could use the pulse (UP Arrow) contact just like you have on the next rung. if you are trying to just increment a word every 3 seconds then it seems simple

ANDNOT T298 OUT T298 K300
AND T 298 ADD K1 D1 D1

here is a screenshot of a number of ways to add a number every 3 seconds this is done in Mitsubishi which is almost the same as your system difference is the ADD instruction is just +.

Recip Timer.png
 
PLCs are about time (not timers), and the scan cycle is the clock.

Once each scan cycle, all program instructions, rungs and branches are processed in order, starting at top left and going left to right, and top to bottom. If the processing reaches the end of a branch, it goes back to the most recent beginning of that branch and processes all parallel branches having the same beginning and end points.

The scan cycle then repeats.

Say we are watching the PLC in slow motion, counting scan cycles.

  • T298 has not yet expired
  • T299 is reset because the T298 output bit is 0
    • The T299 output bit is 0
  • The rising edge/pulse instruction is waiting for a rising edge of the T298 output bit.
  • D1 and D0 both have values of 0.
Then, on scan cycle N, while evaluating rung@0, T298 has reached or exceeded the 3s (300cs) preset time since the previous scan cycle N-1, so the T298 output transitions from 0 to 1.

On the next rung@5, during that same scan cycle 1, T298 being 1 starts the T299 timer and also increments D1 by 1. The preset time of T299 is 0. But what does that mean?

  • Case 1: does T299 expire immediately, i.e. during the current scan cycle N at rung@5, so the T299 output bit changes to 1 for the rest of the current scan cycle N?
  • Case 2: does T299 not expire until the next scan cycle N+1, so the T299 output bit keeps its value of 0 during the rest of current scan cycle N?
I don't know the answer, i.e. I don't know which case is matches the timer implementation in that PLC, a priori (I don't even know this PLC).

But if you run those two cases forward in you head, i.e. evaluate the logic left-to-right and top-to-bottom for the rest of the current scan cycle, and then die one or two more scan cycles, and then compare the resulting values of D1 from those two cases, I suspect you will know the answer.

The scan cycle is the clock.
 
Last edited:
Another couple of questions to ask are these: does the PLC care a whit what I want or expect it to do, or does it mercilessly and inexorably do exactly what I told it to do?

Try these questions as well:

  • Given the code as shown, is there any way for D1 to increment by more than 1 in a single scan cycle?
  • If D1 were incremented by 1 during both of two successive scan cycles, would we see the intermediate value, or would the second increment on the second scan cycle follow so closely in time after the first that we would only see D1 change from X to X+2?
 
hello, it's nice to see your prompt reply
T299 with preset time 0 is meant to imply activation of T299 during the same cycle

but I guess that's where the D1 gets incremented 2 times, in current cycle T299 is started with 0 and maybe only during the next cycle it is compared to the preset time ?

My understanding was that if preset time is 0 then it is activated in the same cycle..

Does anyone know if output from PLC can be sent to a file, so that I can examine it cycle by cycle ?
 
Xinje is virtually a clone of the Mitsi well it's firmware & programming is, like numurous others out there.
Reset of a timer is not a good idea it is better to use the not contact of the timer in the enable along with any other enable logic.
If the timer enable is still on then it may not reset the timer bit until the next scan it will depend on how they implement the reset i.e. is it resetting the accumulated value or the timer contact ? I will do some tests on Mitsi.
Also I suspect that the op is using a second timer T299 with a constant of 0 as the timer value it is probable that it needs at least one other scan to trigger the T299 contact so it will reset after two scans i.e. first scan that T298 is on it enables the timer, second scan acc & preset is same so T 299 contact comes on.
There is no need to use two timers as just putting the Not contact in the timer enable along with any other logic will do exactly as required.
If it needs to be a reciprical timer i.e. always runs & resets when time is up it only needs the not timer in there.
 
Last edited:
My understanding was that ...
Please understand that I do not mean this rudely, but in order to get your attention and to save you a lot of trouble down the road, please allow me some bluntness: this quote, right above here, is the "root cause" in this thread, and in oh so many others.

My understanding is that "The PLC cares not a whit ...," ;), with two consequences:

  • That understanding has never led me astray;
  • That understanding overrides any other understanding that I may have, no matter how treasured (sniff!).
Does anyone know if output from PLC can be sent to a file, so that I can examine it cycle by cycle ?

This may come close to confirming what is going on. Also, I strongly suspect D2 and D0 will always have exactly the same value after the last rung, or at least always increment on the same scan cycle.
1.png
 
Not sure about the Xinje as many clones/copies of the Mitsubishi FX range do not support all the abilities of the Mitsi.
Some cloned type FX units do not allow changes to the PLC parameters, only have 232 coms no 422 which is standard on Mitsi.
There may be a way of doing it by using some "M" bits from say M0 to M500
This will give you 500 scans of data, but you would need to do indirect addressing again not sure if Xinje supports that.
it would require a bit of code.
I will try to code something but unsure if your PLC will work with the instructions needed I have noticed that your ADD is the equivelent of + in Mitsi ladder but there may be other instructions like ADDP This is called +P in mitsi the P on the end means pulse i.e. only does it for one scan if the contact driving it stays on If you put the contact T298 with the Up arrow in it then it will not matter if it stays on for one extra scan.
 
Just looked at the specs for the FX range & T192 to T199 are for interrupts (well in the real FX) not sure this applies to your PLC, try using T0 to T191 (100ms timebase) so K30 for 3 seconds or T200 to T245 for 10ms timebase
Also instead of using T199 to reset T198 just use T198 coil to do it as it would have already added the D
Just tried your logic but if M3995 stays on then it will keep incrementing every 3 seconds
 
Last edited:
No idea what you are using M3995 bit for but i have done it in such a way that if that bit is on then the timer self resets in other word when M3995 is on then the timer triggers every 3 seconds (I have used a lower timer number these are normal speed timers i.e. 100ms so K30 gives 3 seconds)
So M3995 on D1 will increment every 3 seconds and in reset because I have a NOT T 10 in the enable if M3995 is off the timer will reset & will not add any value to the D1

Recip Timer.png
 
hello again

basically what I wanted to find was a solution to increase a register (D) every 1 second

So, I combining a timer and a counter seems to be a good solution

regards

2.png
 
Not sure what M 3995 is in your PLC but for a timer to work correctly it needs to go false, resetting a timer may cause it to be true for at least one scan, just using the Txxx oneshot (contact with up arrow) like you used on the final rung to add 1 to D2 this would work but there is no need for the second timer, if you need to add something every 3 seconds or what ever time you wish then remove M3995 & place a Normally closed contact of the timer in it's place what happens is because the timer has not timed out Txx contact is not true so by using the not contact the timer runs, after the timer times out Txx contact goes true, as the next rung is the add, it adds one to the D register, carries on through the rest of the program goes back to the start & when it scans the timer rung Txx N/C contact is true so the result is false resetting the timer.
I think you need to get your head round how a PLC runs the logic for example it is a loop, in most cases can only process one instruction at a time & does that by scannig the logic left to right top to bottom per rung. I'm wondering why you are using timers in the High end range these generally 10ms & designed for interrupt processing not for normal use.
Why not just try the following
NOT T10 OUT T10 K30
AND T10 [ADD K1 D1 D1]
It is as simple as that.
 
Not sure what M 3995 is in your PLC ..


My fear is that M3995 and T198 does things other than counting up that one Dword.


Especially if M3995 stays ON one extra scan to cause a double count. Considering that, then T198 could have other uses too.


The OP's latest post about moving the ADD to another rung with a OSR I think is the better way.



However:



If the OP was OEM programming then maybe they wanted that Dword to count "Scans High" and not "Done's"


I would check the usage of that Dword and see what how it is used.
 

Similar Topics

I am attempting to reject a bottle If the label fails. The rejection works fine at normal line speed but at low speed the rejector fires (air...
Replies
35
Views
1,180
Hi everyone, I am working on a project that needs to expose the SV (Set Value) of a temperature controller to a SCADA system. SCADA <-...
Replies
4
Views
170
I'm pretty new to PLC's, so forgive me if I use the wrong terminology and whatnot. We have an issue at work where we have a flow meter that is...
Replies
10
Views
304
I would like to copy register N61:131 thru N61:147 into ST252:0 I keep failing What happens is I copy into ST252:0,1, 2 etc. What am i missing...
Replies
18
Views
607
Hello Siemens experts. I am trying to register a GSDML file for an Endress & Hauser's Profinet IO over APL (Profile 4.0) compliant device. TIA...
Replies
2
Views
214
Back
Top Bottom