Problems with limit switch reverse

Hello,

I have been trying to programm a simple routine with Tic500 and Arduino Mega.
Tic500 in advanced settings, Pin configuration with RC: Limit Switch Reverse

The programmed routine should drive a stepper motor to work at a given speed and for a given time.
After this, the motor should go to home.

The problem is in the fic.goHomeReverse() function. Instead of being active up to the limit switch is pushed it only lasts active few seconds and after this the programm continues within the loop.

This is the Code:

#include <Tic.h>
#include <SoftwareSerial.h>

SoftwareSerial ticSerial(10,11);
TicSerial tic(ticSerial,14);

uint32_t targetVelocity = 3500000; // [pulses/10.000s]
uint32_t targetTime = 5000;       // [ms]

void resetCommandTimeout()
{
  tic.resetCommandTimeout();
}

 void delayWhileResettingCommandTimeout(uint32_t targetTime)
{
  uint32_t start = millis();
  do
  {
    resetCommandTimeout();
  } while ((uint32_t)(millis() - start) <= targetTime);
}

void setup() {

  ticSerial.begin(9600);
  delay(20);
  Serial.begin(9600);
  delay(20);

  tic.haltAndSetPosition(0); 
  tic.exitSafeStart();
  tic.resetCommandTimeout();
  tic.energize();
  delay(1000);
}

void loop() {

  tic.resetCommandTimeout();
  tic.energize();
  delay(1000);
  Serial.println("LOOP");
  tic.setTargetVelocity(targetVelocity);
  delayWhileResettingCommandTimeout(targetTime);
  tic.setTargetVelocity(0);
  delayWhileResettingCommandTimeout(1000);
  delay(2000);
  tic.goHomeReverse();
  }

I have also tryed to set a delay after tic.goHomeReverse(), but the only difference was that the active time of Home Reverse becomed exactly the delay time set. If I push the limit switch before the delay ends, the motor is stopped once the delay ends.

Hope you can help me, I am totally blocked…

Thanks in advance

Hello.

The homing commands can be interrupted by other commands, so if you want the code to wait for the homing procedure to finish, you can add a loop like this after calling the goHomeReverse() function:

  while(tic.getHomingActive()){
    delayWhileResettingCommandTimeout(10);
  }

By the way, it looks like you have some delays of 1000ms and 2000ms in your code, without using the delayWhileResettingCommandTimeout() function. Please note that the Tic’s command timeout feature is configured to trigger after 1 second by default, so unless you changed this setting in the “Input and motor settings” tab of the Tic Control Center, then you will get some command timeout errors.

Brandon

1 Like