Page 1 of 1

Delayed Output Off

PostPosted: Wed Jul 21, 2021 12:11 am
by matt_b
Hi,

This is my first post, so hello - I'm currently in the process of rewiring the control cabinet for my CNC router and changing its controller for an AXBB-E. Is it possible to configure a spare output, on the AXBB-E, so that it activates whenever either of the M3/M4 pins are active and then deactivates a configurable number of seconds after the M3 or M4 pins have become inactive?

Matt.

Re: Delayed Output Off

PostPosted: Wed Jul 21, 2021 2:28 pm
by cncdrive
Yes, it is possible with a Macroloop. The loop has to check the M3 and M4 LEDs.
Dezsoe could probably help you with writting a macro quickly.

Re: Delayed Output Off

PostPosted: Thu Jul 22, 2021 10:41 am
by matt_b
Thanks - I'll look into that.

Re: Delayed Output Off

PostPosted: Sun Jul 25, 2021 10:09 pm
by dezsoe
Hi Matt,

Save the following code to a macro and set it as a macroloop. Change the time constant and the output port/pin/active low as you need.

Code: Select all
// ================================================================================================
// Set output if spindle is on and turn it off delayed
// ================================================================================================

bool Spindle = exec.GetLED(50) || exec.GetLED(51);

if (Spindle != lastSpindle)
{
  if (Spindle)
  {
    // Spindle was turned on -> turn on output
    turnOn();
  }
  else
  {
    // Spindle was turned off -> reset timer
    count50ms = 0;
  }
  lastSpindle = Spindle;
}

if (count50ms < offTime)
{
  // Timer is running
  if (++count50ms == offTime)
  {
    // offTiem is reached -> turn off output
    turnOff();
  }
}

// =============================================================================  -- Events --

#Events

// ================================================================================================

// =============== Time constant in 1/20 seconds (20 = 1s)

const int offTime = 20;

// =============== Output port, pin, active low

const int port = 3;
const int pin = 17;
const bool alow = false;

// =============== Variables

static int count50ms = offTime;
static bool lastSpindle = true;

// output functions

// ================================================================================================

// =============== Turn on output

void turnOn()
{
  if (alow)
    exec.Clroutpin(port, pin);
  else
    exec.Setoutpin(port, pin);
}

// =============== Turn off output

void turnOff()
{
  if (alow)
    exec.Setoutpin(port, pin);
  else
    exec.Clroutpin(port, pin);
}

// ================================================================================================