Spindle ramp delay implementation
Moderators: TomKerekes, dynomotion
-
- Posts: 78
- Joined: Tue Mar 30, 2021 8:07 am
Spindle ramp delay implementation
I have a simple open loop spindle interface that need a 5 second delay while it ramps up before commencting motion.
Is there a simple way to introduce this? I've tried adding Delay_sec(5); inside the spindle jog ccw.c file, but that doesn't work, presumably because the motion is running in a parallel thread and isn't waiting while that completes.
I've looked everywhere I can think of, but can't find an example of how this is done.
Any help would be much appreciated.
Is there a simple way to introduce this? I've tried adding Delay_sec(5); inside the spindle jog ccw.c file, but that doesn't work, presumably because the motion is running in a parallel thread and isn't waiting while that completes.
I've looked everywhere I can think of, but can't find an example of how this is done.
Any help would be much appreciated.
Re: Spindle ramp delay implementation
Hello . Maybe this will help
ClearBit(SPINDLECW_BIT); // Spindle On
DoPC(PC_COMM_HALT); // Gcode Stop
Delay_sec (PauseRUN); // Pause
DoPC(PC_COMM_EXECUTE); // Gcode Run
ClearBit(SPINDLECW_BIT); // Spindle On
DoPC(PC_COMM_HALT); // Gcode Stop
Delay_sec (PauseRUN); // Pause
DoPC(PC_COMM_EXECUTE); // Gcode Run
- TomKerekes
- Posts: 2529
- Joined: Mon Dec 04, 2017 1:49 am
Re: Spindle ramp delay implementation
Hi Roger,
Do you have the Spindle Actions configured to "Exec/wait" ?
Do you have the Spindle Actions configured to "Exec/wait" ?
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Spindle ramp delay implementation
Hi Tom.
I wanted to ask you if I did the right spindle delay?
Or can there be problems?
I wanted to ask you if I did the right spindle delay?
Or can there be problems?
- TomKerekes
- Posts: 2529
- Joined: Mon Dec 04, 2017 1:49 am
Re: Spindle ramp delay implementation
Hi Tarasevih,
No that shouldn't be necessary or recommended.
No that shouldn't be necessary or recommended.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 78
- Joined: Tue Mar 30, 2021 8:07 am
Re: Spindle ramp delay implementation
Thanks for that Tom, I've now got that working. I had found those commands, but also found these which looked more promising...
StopCoordinatedMotion();
ResumeCoordinatedMotion();
... but those didn't work.
For those following along, you need to copy this file...
KFlopToKMotionCNCFunctions.c
... from the 'C' to the C Programs folder to the KMotionCNC folder.
You also need these lines in your OnCWJog.c program before you can use
DoPC(PC_COMM_HALT); // Gcode Stop
and
DoPC(PC_COMM_EXECUTE); // Gcode Run
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
I just copied the TMP 10 from another example, I presume that's ok to use here too.
So for completeness, here's my program now...
#include "KMotionDef.h"
#include "DenfordSpindleDefs.h" //Just copied and modifiec from SpindleDefs.h and SPINDLE_RAMP_DELAY defined
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
int *css_mode = &persist.UserData[PC_COMM_CSS_MODE]; // Mode 1=Normal RPM mode. 2=CSS
// desired speed is passed from KMotionCNC in variable KMVAR
// save in user variable STATEVAR whether it was off, CW, or CCW (0,1,-1)
// save in user variable SPEEDVAR the last desired speed
main()
{
float speed = *(float *)&persist.UserData[SPEEDVAR]; // value stored is actually a float
float LastState = persist.UserData[STATEVAR]; // get last state
DoPC(PC_COMM_HALT); // Gcode Stop
if (LastState==-1)
{
// if spindle was CCW now we want CW
// spin down
Delay_sec(SPINDLE_RAMP_DELAY); //Allow time for it to stop first
ClearBit(SPINDLECW_BIT);
ClearBit(SPINDLECCW_BIT);
Jog(SPINDLEAXIS,0);
while (!CheckDone(SPINDLEAXIS)) ;
}
// turn spindle on CW and ramp to new speed
SetBit(SPINDLECW_BIT);
LastState = 1; // Add string
if (*css_mode != 2)
{
// spindle is already on, so ramp to new speed
if (USE_POS_NEG_VOLTAGE)
Jog(SPINDLEAXIS,speed * FACTOR * LastState);
else
Jog(SPINDLEAXIS,speed * FACTOR);
printf("Denford Jogging Spindle %f counts/sec\n",speed * FACTOR);
}
persist.UserData[STATEVAR] = 1; // remember we are CW
Delay_sec(SPINDLE_RAMP_DELAY); //Allow time for it to stop first
DoPC(PC_COMM_EXECUTE); // Gcode Run - carry on now we've allowed time to ramp up spindle
}
StopCoordinatedMotion();
ResumeCoordinatedMotion();
... but those didn't work.
For those following along, you need to copy this file...
KFlopToKMotionCNCFunctions.c
... from the 'C' to the C Programs folder to the KMotionCNC folder.
You also need these lines in your OnCWJog.c program before you can use
DoPC(PC_COMM_HALT); // Gcode Stop
and
DoPC(PC_COMM_EXECUTE); // Gcode Run
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
I just copied the TMP 10 from another example, I presume that's ok to use here too.
So for completeness, here's my program now...
#include "KMotionDef.h"
#include "DenfordSpindleDefs.h" //Just copied and modifiec from SpindleDefs.h and SPINDLE_RAMP_DELAY defined
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
int *css_mode = &persist.UserData[PC_COMM_CSS_MODE]; // Mode 1=Normal RPM mode. 2=CSS
// desired speed is passed from KMotionCNC in variable KMVAR
// save in user variable STATEVAR whether it was off, CW, or CCW (0,1,-1)
// save in user variable SPEEDVAR the last desired speed
main()
{
float speed = *(float *)&persist.UserData[SPEEDVAR]; // value stored is actually a float
float LastState = persist.UserData[STATEVAR]; // get last state
DoPC(PC_COMM_HALT); // Gcode Stop
if (LastState==-1)
{
// if spindle was CCW now we want CW
// spin down
Delay_sec(SPINDLE_RAMP_DELAY); //Allow time for it to stop first
ClearBit(SPINDLECW_BIT);
ClearBit(SPINDLECCW_BIT);
Jog(SPINDLEAXIS,0);
while (!CheckDone(SPINDLEAXIS)) ;
}
// turn spindle on CW and ramp to new speed
SetBit(SPINDLECW_BIT);
LastState = 1; // Add string
if (*css_mode != 2)
{
// spindle is already on, so ramp to new speed
if (USE_POS_NEG_VOLTAGE)
Jog(SPINDLEAXIS,speed * FACTOR * LastState);
else
Jog(SPINDLEAXIS,speed * FACTOR);
printf("Denford Jogging Spindle %f counts/sec\n",speed * FACTOR);
}
persist.UserData[STATEVAR] = 1; // remember we are CW
Delay_sec(SPINDLE_RAMP_DELAY); //Allow time for it to stop first
DoPC(PC_COMM_EXECUTE); // Gcode Run - carry on now we've allowed time to ramp up spindle
}
-
- Posts: 78
- Joined: Tue Mar 30, 2021 8:07 am
Re: Spindle ramp delay implementation
This works fine when pressing RUN, but it switches from Single Step to continuous when the spindle starts. It also starts executing the program when manually starting the spindle. What's the best way to avoid this happening?
Clearly OnCWJog.c is common to continuous running, spindle start and single stepping, so I need to be able to ask what mode it's in. Then I can either leave out the PC_COMM_HALT and delay, or I'll need a way to return from the single step without causing it to run continuously. Maybe I could just avoid the PC_COMM_EXECUTE command if it's single stepping?
Either way, I need a test in OnCWJog.c to find out whether it's running continuously or in single step mode. I'm sure there's an easy way to do this, but I can't see it at the moment.
Clearly OnCWJog.c is common to continuous running, spindle start and single stepping, so I need to be able to ask what mode it's in. Then I can either leave out the PC_COMM_HALT and delay, or I'll need a way to return from the single step without causing it to run continuously. Maybe I could just avoid the PC_COMM_EXECUTE command if it's single stepping?
Either way, I need a test in OnCWJog.c to find out whether it's running continuously or in single step mode. I'm sure there's an easy way to do this, but I can't see it at the moment.
Last edited by RogerFroud on Tue Jul 13, 2021 9:23 pm, edited 1 time in total.
- TomKerekes
- Posts: 2529
- Joined: Mon Dec 04, 2017 1:49 am
Re: Spindle ramp delay implementation
That's why I did not recommend doing it that way.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Spindle ramp delay implementation
Hi Tom ! Do you have any recommendations on how to pause program execution to start the spindle?
PC_COMM_EXECUTE - also launches the program from the button OnCW which is not acceptable.
Maybe some example.
Regards Taras.
PC_COMM_EXECUTE - also launches the program from the button OnCW which is not acceptable.
Maybe some example.
Regards Taras.
- TomKerekes
- Posts: 2529
- Joined: Mon Dec 04, 2017 1:49 am
Re: Spindle ramp delay implementation
Configure the Spindle Actions to "Execute/wait" and add any needed delays to your spindle programs.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.