Page 1 of 1

WaitUntil()

Posted: Mon Jul 11, 2022 10:31 am
by IvanSiberia
What is the difference between the Delay_sec() function and the WaitUntil() function?

Re: WaitUntil()

Posted: Mon Jul 11, 2022 4:29 pm
by TomKerekes
Delay_sec delays for a specified amount of time. WaitUntil delays until a specified time. Its like delay for 1 hour vs wait until 6:00AM.

HTH

Re: WaitUntil()

Posted: Tue Jul 12, 2022 10:36 am
by IvanSiberia
will the stream switch work while paused?

Code: Select all

double Time_current;
double Time_start;


Time_start=WaitNextTimeSlice();

while(1){


delay(100);
}


 delay(double  ms){
     
     Time_start=WaitNextTimeSlice();
      
   while ((Time_start - Time_current)) < ms){

			WaitNextTimeSlice();  // stream while pause
		};


} 

Re: WaitUntil()

Posted: Tue Jul 12, 2022 5:34 pm
by TomKerekes
I don't understand the question. KFLOP uses simple preemptive multi-tasking,

Use Time_sec() to get the current time in seconds

The math is backwards

Please indent your code for readability.

Re: WaitUntil()

Posted: Thu Jul 14, 2022 12:03 pm
by IvanSiberia

Code: Select all

#include "KMotionDef.h"

double Time_start;
double Time_current;

void delay(double sec);

void main()
{

delay(0.01);
}

delay(double  ms){
    
     Time_current=WaitNextTimeSlice();
     
      double delta = Time_current - Time_start;
      	
				while (delta < ms){
				
					Time_current=WaitNextTimeSlice();
				    delta =  Time_current - Time_start;
				
				           WaitNextTimeSlice();
				
				}		
} 
will there be an effect from WaitNextTimeSlice();. I want not to wait for time, but to give the flow.

Re: WaitUntil()

Posted: Thu Jul 14, 2022 4:30 pm
by TomKerekes
I don't understand the question.

It would be helpful to know what you are trying to do?

Why not use the existing functions Delay_sec() or WaitUntil()?

WaitNextTimeSlice(); waits until the beginning of the Threads next Time Slice. To just get the Time use Time_sec();

Your program never sets Time_start;

ms is normally used for milliseconds. But you are using it as seconds.

In general timing by a User Thread in software will not be perfect because Threads execute for ~50us and then stop executing for some period of time (ie ~130us for one Thread). If the Time expires while the Thread is stopped it will not be detected until the Thread resumes execution. This could extend the time by up to 130us.


Please indent your programs properly when asking other to help.