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