WaitUntil()

Moderators: TomKerekes, dynomotion

Post Reply
IvanSiberia
Posts: 30
Joined: Fri Jun 17, 2022 11:21 am

WaitUntil()

Post by IvanSiberia » Mon Jul 11, 2022 10:31 am

What is the difference between the Delay_sec() function and the WaitUntil() function?

User avatar
TomKerekes
Posts: 2680
Joined: Mon Dec 04, 2017 1:49 am

Re: WaitUntil()

Post by TomKerekes » Mon Jul 11, 2022 4:29 pm

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
Regards,

Tom Kerekes
Dynomotion, Inc.

IvanSiberia
Posts: 30
Joined: Fri Jun 17, 2022 11:21 am

Re: WaitUntil()

Post by IvanSiberia » Tue Jul 12, 2022 10:36 am

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
		};


} 

User avatar
TomKerekes
Posts: 2680
Joined: Mon Dec 04, 2017 1:49 am

Re: WaitUntil()

Post by TomKerekes » Tue Jul 12, 2022 5:34 pm

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.
Regards,

Tom Kerekes
Dynomotion, Inc.

IvanSiberia
Posts: 30
Joined: Fri Jun 17, 2022 11:21 am

Re: WaitUntil()

Post by IvanSiberia » Thu Jul 14, 2022 12:03 pm

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.

User avatar
TomKerekes
Posts: 2680
Joined: Mon Dec 04, 2017 1:49 am

Re: WaitUntil()

Post by TomKerekes » Thu Jul 14, 2022 4:30 pm

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.

Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply