In the folder C Programs there are many examples with functions for (;;) and Delay_sec() and others, excluding the correct sequential execution of other functions. There are only 7 threads allocated for the user.
Please explain and give examples of simultaneous use of different C programs in the same stream in real time and without delay.
I also ask you to clarify in detail the operation and scope of the WaitNextTimeSlice() function.
Organization of C programs in the context of threads.
Moderators: TomKerekes, dynomotion
-
- Posts: 39
- Joined: Wed May 03, 2023 12:54 am
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Organization of C programs in the context of threads.
Sorry I don't understand the question. What are you trying to do?In the folder C Programs there are many examples with functions for (;;) and Delay_sec() and others, excluding the correct sequential execution of other functions. There are only 7 threads allocated for the user.
Please explain and give examples of simultaneous use of different C programs in the same stream in real time and without delay.
This waits until the beginning of the Threads next Time Slice. See here. Useful when some code should be executed at some periodic rate (multiple of 90us sample times). Or to provide execution of ~40us of code without the possibility of interruptions.I also ask you to clarify in detail the operation and scope of the WaitNextTimeSlice() function.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 39
- Joined: Wed May 03, 2023 12:54 am
Re: Organization of C programs in the context of threads.
I understand how the WaitNextTimeSlice() function works.
How to apply it correctly? Before the start of the desired function or inside it or after it or inside the brackets { }? And also how many lines of code does it work on?
How to apply it correctly? Before the start of the desired function or inside it or after it or inside the brackets { }? And also how many lines of code does it work on?
-
- Posts: 39
- Joined: Wed May 03, 2023 12:54 am
Re: Organization of C programs in the context of threads.
And two more questions.
1. What is the difference between the Halt and FeedHoldStop functions ?
2. I want to duplicate with an external CycleStart/Halt button. I understand how to pass button commands to KMotionCNC. But I don't know how to read the status of Halt and CycleStart from KMotionCNC ?
1. What is the difference between the Halt and FeedHoldStop functions ?
2. I want to duplicate with an external CycleStart/Halt button. I understand how to pass button commands to KMotionCNC. But I don't know how to read the status of Halt and CycleStart from KMotionCNC ?
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Organization of C programs in the context of threads.
Like any function it can be placed anywhere where code is executed.I understand how the WaitNextTimeSlice() function works.
How to apply it correctly? Before the start of the desired function or inside it or after it or inside the brackets { }?
The function doesn't operate on any lines of code. It waits till the beginning of the next time slice then returns. Please read my previous response.And also how many lines of code does it work on?
What is 'FeedHoldStop '? To access the Help Manuals for a description of a button click 'Help' then click the button.What is the difference between the Halt and FeedHoldStop functions ?
There is a define in KFLOP called JOB_ACTIVE which can be used to determine if GCode is executing or not.I want to duplicate with an external CycleStart/Halt button. I understand how to pass button commands to KMotionCNC. But I don't know how to read the status of Halt and CycleStart from KMotionCNC ?
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 39
- Joined: Wed May 03, 2023 12:54 am
Re: Organization of C programs in the context of threads.
That is, this function loops code execution inside itself until the next time slice?The function doesn't operate on any lines of code. It waits till the beginning of the next time slice then returns.
In other words, in the code:
Code: Select all
main()
{
for(;;)
{
function 1();
WaitNextTimeSlice();
function 2();
WaitNextTimeSlice();
function 3();
WaitNextTimeSlice();
function 4();
WaitNextTimeSlice();
}
}
Do I understand correctly?
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Organization of C programs in the context of threads.
YesThat is, this function loops code execution inside itself until the next time slice?
Yes. Assuming none of those functions take longer than ~40us to execute.Each function will be repeated at intervals = (# User Threads + 1) * TIMEBASE * 4 ?
Do I understand correctly?
You can check these things yourself using Time_sec() which has 20ns resolution. WaitNextTimeSlice also returns the time.
Function names can not contain spaces.
When showing your code its nice to indent your code in a consistent manner to make it more readable. See here. And Video:
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.