News:

  • September 29, 2026, 01:30:12 PM

Login with username, password and session length

Author Topic: Domore timer issue.  (Read 8743 times)

amos

  • Full Member
  • ***
  • Posts: 39
Domore timer issue.
« on: January 18, 2024, 10:16:44 PM »
I have a program with a several for next loops. I am still working on the program. I noticed lately that the timers are not timing proper. They seem to count 1/10 slower than they should. What could be the problem? The timers are before any for next loops. Also how serious is the warning W331? W331 Asynchronous instruction DLRX used in code-block with 3 yielding instructions (NEXT at @47  NEXT at @125  NEXT at @171) . The for next loops loop not over 24 times at the most. maximum scan time is 9.8 ms.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3847
    • Host Engineering
Re: Domore timer issue.
« Reply #1 on: January 19, 2024, 08:53:54 AM »
Loops in PLCs are usually not good.  You have to make sure you understand how the PLC scan works, along with loops.

Your code block is probably yielding.  This is how I/O scans can be "fast" but still allow looping.  Your timers MUST execute EVERY scan in order to time correctly.  You probably have your tmr/loops in a code block outside of $Main.

$Main defaults to NEVER yield, so all loops will execute completely, and your TMRs would hence always execute every PLC scan.  But other code bocks default to yield every 100uSec - that means that if a loop takes longer than that, the PLC scan will continue with the next code block and finish the I/O ladder scan (realtime control is critical).  The very next PLC scan, when it hits this looping code block again, it continues at the for/next loop, skipping all your TMR boxes, hence they do not time.  This is why that warning exists.

If you click on the W331 Program Check rule, then hit the F1 key or hit the Item Help button, you will see some explanation.

Help topic DMD0231 Code Block Overview explains it some more.

There are some power point training slides that help explain the plc scan behavior when using loops.
https://hosteng.com/FAQFiles/TechSlides/TechTrainingSlides01.html
Go there and look at presentation #8 - Instruction Set (Program-Looping)

Your solution may to just change the .TimeSlice of your code block to 65535 (special value that means never yielding) - but this could greatly slow down your I/O scan if the loops are huge or nested.  Otherwise, you may need to separate your looping logic from your timing/control logic in different code blocks, utilizing the fact that your looping code block may take many PLC scans to "finish".

PLCs are meant to scan I/O and execute logic.  Long loops, while permitted, can cause long scan times or possibly watchdog timeouts.  Looping in PLC logic can be done, but not like in normal programming languages.

If you need more help, please explain what you are doing with your loops and hopefully we can figure out how to make it work.

amos

  • Full Member
  • ***
  • Posts: 39
Re: Domore timer issue.
« Reply #2 on: January 19, 2024, 11:24:36 AM »
Thank you for your reply.
  My next question would have been how the for next loops work on the PLC. I am quite familiar how loops work in basic. I could see that in the PLC it doesn't seem to be the same. The program is collecting data from various locations and it was replication of the same code with a different index. Program was over 12000. 'not sure what that number means'. With the for next loops doing the same thing is now 4230.  I see 'timeslice = 100' . What does that represent? I figured that was never hit. But with your explanation it seems to work different than I assumed.
  Ok I changed the program default yield from 100us to 10000us and the scan time did not change so I restarted the PLC now the scan time is 18.8 ms. The timers time proper now.
   Thank you for the help

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 702
  • Hmmm...
    • Host Engineering, Inc.
Re: Domore timer issue.
« Reply #3 on: January 19, 2024, 01:54:31 PM »
There is a set of animated slides I did that will help you understand Programs, Tasks, looping, and yielding.
1. Goto hosteng.com
2. In the left column under Training Slides, click on All Do-more PLCs
3. Click on and download the PowerPoint slide presentation #7 called Programs VS Tasks

These are animated, so when you pull them up in PowerPoint, do a slide show.

The last few slides are on yielding.
There are two types of people in the world; those that can extrapolate from incomplete data sets.