Announcement

Collapse
No announcement yet.

Timer Inside of Loop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    This code works to retain the timer values. Can update Timer.Current as fast as needed. The copy is very fast so very small scan time hit. Much less then even the fastest For Next loop. Would take some typing/cut and pasting. I just can not find a way to use a loop to get to each timer's current value.

    Click image for larger version

Name:	Capture.JPG
Views:	89
Size:	155.1 KB
ID:	127646
    Attached Files

    Comment


    • #17
      I pasted the Copy Data rung 50 times for a copy of 165 values to be copied. Update the 165 values Copy Data every 10ms. Scan time went form 0.0ms to 0.1ms! SOOOO much faster then a For/Next loop. This is on a P1 CPU.

      Comment


      • #18
        You probably would have to not use timer structures and make arrays of timer elements-then loop thru the 'current' array.

        Comment


        • #19
          Too bad you can't set up an array of Timer Structures

          Comment


          • #20
            Thanks all for the responses. I've attached a program that demonstrates how an array inside of a loop works in the Productivity controller (file extension will have to be changed).

            An array of timers is the proper way to accomplish what I'm trying to do. With an array of timers the instruction would have to be in a non-yielding program/task so that every scan time can be cumulatively summed by the timer without missing individual scans. That being said, the attached program intentionally makes the timer loop miss scans by using a one-shot call to a task. The way this seems to work in the Productivity is that every time the call is made to the Maintenance task if the LIGHTSTATUS array bit is on the LAMP_RUN_TIMEMSEC array gets updated with the previous value from that position in the array plus the current scan time. It is effectively summing all the scan times and storing them in the Current Value array. The For Loop in the MAIN task is used to slow the scan time down so that the effects of a varying scan time can be demonstrated. The longer the scan time the more resolution that is lost in the timer current value. Because the Productivity doesn't have yielding tasks/programs, if put in the Run Every Scan folder, scan times shouldn't be lost. There do appear to be truncation/rounding issues with the timer's current values when stored as integers. The loop over the timer does not work except when using the msec time base (I don't know why this is). I'm not advocating that this approach be used, I was just curious as to what was actually going on.
            Attached Files

            Comment


            • #21
              RBPLC, I tried using the Last Scan Interval before I came up with Post #13. I ran a continuous timer along with a Last Scan Time summation. Both should have been equal but there was quite a bit of error. The Last Scan Time always fell behind the continuous timer.

              An array of timers is the proper way to accomplish what I'm trying to do.
              I agree. I just can not get an array of timers. I can set up an array of times.

              Would need to see something like this:
              (Timer), (Timer Number), (Timer Parameter)
              Timer.TimerNum.Time Up
              Timer.TimerNum.Time Down
              Timer.TTimerNum.Reset
              Timer.TimerNum.Current Value

              Comment

              Working...
              X