Hi all
Can somebody please help me to understand how this basic function operates.
I generally understand how a TON timer works... but I need to REALLLLY understand how these things work. I think my question really pertains to how 'scan' cycles works, how code is implemented and when inputs are updated.
I'm familiar with the whole, read inputs, execute code, update outputs mantra - but I'm not fully following how this works.
Lets assume I have a program where a TON instance is declared with a PT:= 50ms. Assume my task is operating at 20ms.
Now in my program I call the FB:
tonDelay( IN :=NOT tonDelay.Q);
Output := tonDelay.Q;
Can somebody please explain how the variable: 'Output' ever achieves a result of TRUE.
In my mind: As soon as the program calls the tonDelay and sees that tonDelay.Q is false (timer hasn't yet reached the PT), it keeps tonDelay.IN at TRUE and allows the timer to keep running.
On the next cycle, let's assume the PT of 50ms has elapsed tonDelay is called and tonDelay.Q is TRUE (timer has finished), my understanding is that when this line of code is called:
tonDelay( IN :=NOT tonDelay.Q);
..., the tonDelay.IN condition falls to FALSE, which in turn will set the tonDelay.Q value to FALSE
So how can the following line of code ever fall TRUE:
Output := tonDelay.Q;
By the time it is executed, the timer has set IN to false, which in turn sets Q to false.
Like I said, I think I'm misunderstanding scan cycles and how the code is executed.
Can somebody please spell out to me (in detail... scan by scan if necessary) how each scan works, how inputs are calculated and how outputs are updated.
I'm getting close to understanding, but I'm in need of a wiser sole

Thanks in anticipation