Lukasz_Poland
Member
OP
In my plc is something like that. Could you tell me where is the problem?
[Scan 1, line N] oneshotbits := (last_scans_mb0 XOR mb0) AND mb0;
[Scan 1, line N+1] last_scans_mb0 := mb0;
[... finish Scan 1 ...]
[... start Scan 2 ...]
[Scan 2, line N] oneshotbits := (last_scans_mb0 XOR mb0) AND mb0;
From the Siemens help:
In my plc is something like that. Could you tell me where is the problem?
Yes, because we need to think about digital PLCs as being devices that change over time.
The problem is that our code (your code, my code, perhaps @Rob...'s code*) uses the expression [mb0] (%MB0) in two separate lines of code, and the evaluated result of that expression [mb0] can change between the execution of those two lines.
Consider these three lines, executed across two scans:
[Scan 1, line N] oneshotbits := (last_scans_mb0 XOR mb0) AND mb0;
[Scan 1, line N+1] last_scans_mb0 := mb0;
[... finish Scan 1 ...]
[... start Scan 2 ...]
[Scan 2, line N] oneshotbits := (last_scans_mb0 XOR mb0) AND mb0;
The solution is straightforward; do you see it?
- If a bit in mb0 is 0 at the time of [Scan 1, line N],
- then its corresponding bit in [oneshotbits] will be 0,
- BUT if that bit in mb0 changes over the next few microseonds to 1 before the evaluation of [Scan 1, line N+1],
- then the value of the corresponding bit in last_scans_mb0 will be 1!
- And so, at [Scan 2, line N],
- that bit will be 1 in BOTH [last_scans_mb0] and [mb0],
- and the the XOR will evaluate to 0 for that bit
P.S. Siemens makes the more or less the same mistake in the evaluation of the .Q bit of its IEC timer object for TOFs an TONs.
* @Rob...'s example code in Post #4 used [ew0] for the value of mb0, so he may have already fixed the problem.
Hello
I have got a problem with positive edge from "system clock memory byte" in Tia Portal. I would like to change byte"system clock memory" to another byte but it should be "positive edge byte"
I saw that function with XOW and AW but it was in STL language and I dont know how to write it in SCL.
Sorry for my poor English.
I think works fine.
Thanks