Scan Time v Timer Operation
I had started draughting this up earlier before Ron's reply, but was interrupted before I could finish it off and make a screenshot. So I'll post it now anyway, before bedtime...
just the cowboy said:
...If a TON is on a output branch and rung is true.
The next branch has a XIC contact off of that .DN bit to an OTE
The PRE = 0 ACC= 0 should the XIC in the branch open on that scan or the next scan?...
The next scan.
just the cowboy said:
...With timer at PRE=0 thought it should be true on that scan...
No. The DN bit will be set true on the next scan.
jdbrandt said:
...because your timer is set to 0...As soon as the timer rung conditons go true, the DN will be true.
No. The DN bit will be set true on the next scan.
just the cowboy said:
...Thats what I thought but the output DOES turn on for a split second...
...If I had to guess it is only 1 scan BUT it does come on.
Yes, the OTE is set for one scan because the first TON DN bit is set true and the second TON DN bit will not be set true until the next scan.
i.e. the XIO instruction for T4:6/DN bit before the OTE will remain true for one scan, after TON T4:6 EN bit is set true.
It has to do with how the timer instruction is updated and how it evaluates.
The timer is only processed and updated on each scan. When the rung-condition-in to the timer instruction is true for the first time, it sets the enable (EN) bit true, and the timer timing (TT) bit true. It does not evaluate if the PRE is equal to the ACC. Also, an 8-bit time stamp is recorded for the accumulator value (ACC). The scan then moves on from the timer instruction. So while the scan is elsewhere, the timer instruction is not updating the ACC value. When the scan comes back around to the timer instruction for the second time, and it's rung-condition-in is still true, the timer instruction records a second time stamp. The new time stamp value is compared with the old time stamp value and the ACC value of the timer is increased by the difference between the time stamps. The instruction then evaluates if the PRE is equal to the ACC for the first time.
Likewise, if the PRE equals zero, the first scan does not yet evaluate if the PRE is equal to the ACC. When the scan comes around the second time, the instruction evaluates if PRE is equal to ACC, but only if PRE is not equal to zero. If the PRE is equal to zero, it sets the done (DN) bit immediately. So this takes an extra scan after the enable to set the done bit true.
Sometimes, depending on timing, the ACC can actually be updated to 1, even though the PRE is equal to zero and the done bit was set on the second scan. This is because the instruction will still record the second time stamp and compare and update the ACC value, even though the evaluation is saying the PRE is equal to zero, so set the done bit true. When the PRE is zero, the evaluation is ignoring the ACC value altogether, but the instruction can still update it.
Knowing that...
Operation of a timer when the PRE = non zero value
First scan with the rung-condition-in true
EN bit set true
TT bit set true
First time stamp for the ACC is recorded
PRE = ACC is not evaluated
DN bit is false
Second scan with the rung-condition-in true
EN bit is still true
TT bit is still true
Second time stamp is recorded, compared and ACC updated
PRE = ACC is evaluated false
DN bit is false
Subsequent scans with the rung-condition-in true
EN bit is still true
TT bit is still true
Subsequent time stamps are recorded, compared and ACC updated
PRE = ACC is evaluated false
DN bit is false
Eventually, scan with the rung-condition-in true
EN bit is still true
TT bit is still true
Time stamp is recorded, compared and ACC updated
PRE = ACC is evaluated true
DN bit is set true
TT bit is set false
---------------------------------------------
Operation of a timer when the PRE = 0
First scan with the rung-condition-in true
EN bit set true
TT bit is set true
First time stamp for the ACC is recorded
PRE = ACC is not evaluated
DN bit is false
Second scan with the rung-condition-in true
EN bit is still true
TT bit is still true
Second time stamp is recorded, compared and ACC updated
PRE = 0 is evaluated true
DN bit is set true
TT bit is set false
So the timer instruction does not evaluate PRE = ACC on the first scan when it is enabled. This is because the instruction is designed on the basis of having a non zero PRE value. So it waits by default until it has two comparable time stamps before starting to evaluate PRE = ACC.
So when you set PRE = 0, and the timer is enabled, it does not initially account for this 0 value, and must by design wait until the next scan before evaluating PRE = 0, and then set the done bit true.
In the attached, I used your logic with "Test Single" mode to pause the scan cycle when the timer EN bit was set. You can see the DN bit of the timer is not yet set and the XIO beneath is still true, making the OTE true. On the next "Go Single Scan", the timer DN bit is set and the XIO instruction will go false, setting the OTE false.
Regards,
George