Page 1 of 1

Wait for spindle

PostPosted: Mon Jun 13, 2022 2:30 am
by rojhan
From viewtopic.php?f=4&t=3909
I wanted a way to reduce the spindle spinup delay, especially if I wasn't going to full speed. M3 delay was 9 seconds to be safe.

By using the spindle ready output as an input to the BOB, I was able to wait "only long enough", with the benefit of being able to change spindle speeds between MOPs that used the same tool.

M3 delay is set for zero, and my MOP template from CamBam adds the macro after the spindle/M3 command.

Code: Select all
// Wait for spindle to reach requested speed


const int pin_spindle=11;     // Input pin for spindle ready
const double fail_seconds=10; // Max time to wait for ready

bool ready=AS3.GetLED(pin_spindle);
bool fail=false;
double start_time=DateTime.Now.Ticks;
double elapsed=0;

if(!AS3.Getbuttonstate(114))  // Check for M3
  {
  exec.AddStatusmessage("Spindle is not running. No spindle delay needed.");
  return;
  }

if(ready)
  {
  Thread.Sleep(500);  // Debounce to allow the spindle status to change if already running
  ready=AS3.GetLED(pin_spindle);
  }
if(ready)
  {
  exec.AddStatusmessage("Spindle is already ready.");   
  return;
  }

exec.AddStatusmessage("Waiting for spindle.");
while(ready==false)
  {
  elapsed=(DateTime.Now.Ticks-start_time)/10000000;
  if(elapsed>fail_seconds)   
    {
    exec.AddStatusmessage("Spindle took too long to be ready.");
    exec.Callbutton(130);
    fail=true;
    break;
    }
  else     
    ready=AS3.GetLED(pin_spindle);
  }
if(!fail)
  exec.AddStatusmessage("Spindle is at requested speed.");

Re: Wait for spindle

PostPosted: Mon Jun 13, 2022 3:14 am
by cncdrive
We've added this functionality was added to the next release of the UCCNC, however it requires a spindle encoder or index sensor to measure the speed of the spindle.
You can set the tolerance % and a time constant for stable spindle speed.
For example you set 90% and 1seconds and programming S1000 then the controller will wait for the speed to reach 900 RPM and if the RPM is above 900RPM for 1seconds then it continues the g-code execution after and M3 or M4 or S command.

Re: Wait for spindle

PostPosted: Mon Jun 13, 2022 4:15 am
by rojhan
cncdrive wrote:We've added this functionality was added to the next release of the UCCNC, however it requires a spindle encoder or index sensor to measure the speed of the spindle.
You can set the tolerance % and a time constant for stable spindle speed.
For example you set 90% and 1seconds and programming S1000 then the controller will wait for the speed to reach 900 RPM and if the RPM is above 900RPM for 1seconds then it continues the g-code execution after and M3 or M4 or S command.


Could the functionality be extended using the concepts in the macro? Rather than UCCNC measuring RPM, just specify a "spindle ready" input pin for the VFDs that support it.

Re: Wait for spindle

PostPosted: Wed Jun 29, 2022 10:36 am
by Battwell
use a while loop at the end of your m3 macro to wait for the at speed signal to go active.