Plugin loop frequency

If you have a question about the software please ask it here.

Plugin loop frequency

Postby beefy » Mon Sep 12, 2016 11:07 pm

I would like to better understand the plugin loop frequency.

The plugin loop is supposed to run at 25 times per second. Would it be more accurate to say the delay BETWEEN plugin loop runs is 1/25th second.

Example if the code in my plugin loop took 2/25th second to run, would the total time between loops be 2/25th PLUS 1/25th (delay between loops), giving a total time of 3/25th second for one loop cycle.

Guess what I'm saying is it's not possible for the loop to run at 25 times a second if the code in the loop itself took longer than 1/25 second.

Likewise for macro loops which run at 20 times per second. Is 1/20th second a delay between loop runs ??

Keith.
beefy
 
Posts: 402
Joined: Mon Sep 05, 2016 10:34 am

Re: Plugin loop frequency

Postby cncdrive » Tue Sep 13, 2016 12:07 am

Yes, the wait time is 1/25Hz at the end of each loop. There is a fixed wait time (Thread.Sleep) at the end of the thread loop.
It is just a simple Thread running in the UCCNC.exe and calling the plugin dll once in every loop.
You could create your own same kind of Threads in the plugin and then if you want you can code it in a way to measure time at the end of the loop and then skip only when the time expired and that way you can have a loop which always runs at e.g. 25Hz except if your code execution requires more time than the 1/25Hz.
To skip if your code executes for more than the loop target time may be possible or may be not, depending on your code.
If all single lines of your code requires less than 1/25Hz then you can place time check codes and skip if the expired time is already greater or you could make a sequence of execution of the lines etc., but if it is an acceptable solution to skip in the middle of the job again depends on what your code is doing, what it's job is.
Ofcourse the 25Hz in this case was just an example you can code your own Thread loop to any frequency/time interval you want with the constraint of minimum 1msec time, because Thread.Sleep has that resolution.
Also please keep in mind that Windows is not a realtime system, so very short time intervals may be not very precise ... you can make it more precise with highering the Thread priority,
but take care to not set it too high at least not in the development process, because if you do you may need to reset your computer in case your Thread locks up for any reasons/mistakes in the development process and sucks up all of your CPU time.
cncdrive
Site Admin
 
Posts: 3384
Joined: Tue Aug 12, 2014 11:17 pm

Re: Plugin loop frequency

Postby beefy » Tue Sep 13, 2016 3:30 am

Thanks very much Balazs, especially for all the extra information you included.

My main reason for asking at the moment was that some time ago I was writing a plugin with serial communication. A plugin loop would send a serial packet and based on the baud rate I wasn't sure if there'd be time for all the bytes to be sent and subsequent bytes to be received from a device. Now I know that outside of the loop there's 1/25th second. If that's not enough time I could just skip every other loop.

Cheers,

Keith.
beefy
 
Posts: 402
Joined: Mon Sep 05, 2016 10:34 am


Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 6 guests