WaitUntil()
Moderators: TomKerekes, dynomotion
-
- Posts: 30
- Joined: Fri Jun 17, 2022 11:21 am
WaitUntil()
What is the difference between the Delay_sec() function and the WaitUntil() function?
- TomKerekes
- Posts: 2680
- Joined: Mon Dec 04, 2017 1:49 am
Re: WaitUntil()
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
HTH
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 30
- Joined: Fri Jun 17, 2022 11:21 am
Re: WaitUntil()
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
};
}
- TomKerekes
- Posts: 2680
- Joined: Mon Dec 04, 2017 1:49 am
Re: WaitUntil()
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.
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.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 30
- Joined: Fri Jun 17, 2022 11:21 am
Re: WaitUntil()
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();
}
}
- TomKerekes
- Posts: 2680
- Joined: Mon Dec 04, 2017 1:49 am
Re: WaitUntil()
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.
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.
Tom Kerekes
Dynomotion, Inc.