Help with a delay on a direction switch for a vfd

I need help with the delay on a direction switch that is connected to a VFD on a lathe
The problem i habe now with the existing switch is that if i change direction too fast the vfd is freewheeling for a while before it changes direction.
If i add a small delay before i change direction the brake steps in and brakes the spindle to zero before direction change.
I need the delay to only work when i change direction fast, otherwise the switch should work as normal.
Have been sitting here for hours now with no luck solving it.

#include <millisDelay.h>
const int RelayForward = 3;
const int RelayReverse= 4;
const int RelayBrake = 5;
const int Relay4 = 6;
const int SWForward = 7;              // the number of the pushbutton pin
const int SWReverse = 8;              // the number of the pushbutton pin
int buttonStateForward = 0;              // variable for reading the pushbutton status
int buttonStateReverse = 0;              // variable for reading the pushbutton status
millisDelay ButtonForwardDelay;
millisDelay ButtonReverseDelay;

void setup() {
  // put your setup code here, to run once:
   pinMode(RelayForward, OUTPUT);
   digitalWrite(RelayForward, HIGH);
   pinMode(RelayReverse, OUTPUT);
   digitalWrite(RelayReverse, HIGH);
   pinMode(RelayBrake, OUTPUT);
   digitalWrite(RelayBrake, HIGH);
   pinMode(Relay4, OUTPUT);
   digitalWrite(Relay4, HIGH);
   pinMode(SWForward, INPUT_PULLUP); // PULLUP for add 5v to pin without hardware prevent pin from floating between HIGH and LOW
   pinMode(SWReverse, INPUT_PULLUP); // PULLUP for add 5v to pin without hardware prevent pin from floating between HIGH and LOW
   ButtonForwardDelay.start(3);  // start a 3 millisec delay
   ButtonReverseDelay.start(3);  // start a 3 millisec delay

}

void loop() {
  // put your main code here, to run repeatedly:
   buttonStateForward = digitalRead(SWForward);// read the state of the pushbutton value:
   // check if the pushbutton is pressed. if it is, the buttonState is LOW:
   if (buttonStateForward == LOW) {// pin is pressed and connected to GND so it will be LOW
      if (ButtonForwardDelay.justFinished()) {
         digitalWrite(RelayForward, LOW);                    // remove 5v from pin so relay in1 will be 0v and this make relay on
         digitalWrite(RelayBrake, LOW);
         Serial.println(ButtonForwardDelay.justFinished());
         ButtonReverseDelay.start(3000);  // start a 3sec delay
      }
   } else {
      digitalWrite(RelayForward, HIGH);                   // add 5v to arduino pin so relay in1 will be 5v and this make relay off
      digitalWrite(RelayBrake, HIGH);
      //ButtonForwardDelay.start(0);
   }

   buttonStateReverse = digitalRead(SWReverse); // read the state of the pushbutton value:
   // check if the pushbutton is pressed. if it is, the buttonState is LOW:
   if (buttonStateReverse == LOW) {                    // pin is pressed and connected to GND so it will be LOW
      if (ButtonReverseDelay.justFinished()) {
         digitalWrite(RelayReverse, LOW);                  // remove 5v from pin so relay will be 0v and this make relay on
         digitalWrite(RelayBrake, LOW);
         ButtonForwardDelay.start(3000);  // start a 3sec delay
      }
   } else {
      digitalWrite(RelayReverse, HIGH);                 // add 5v to arduino pin so relay will be 5v and this make relay off
      digitalWrite(RelayBrake, HIGH);
      //ButtonReverseDelay.start(0); 
   }
}

Please supply a link to the library you included.

Robban:
I need help with the delay on a direction switch that is connected to a VFD on a lathe
The problem i habe now with the existing switch is that if i change direction too fast the vfd is freewheeling for a while before it changes direction.
If i add a small delay before i change direction the brake steps in and brakes the spindle to zero before direction change.
I need the delay to only work when i change direction fast, otherwise the switch should work as normal.
Have been sitting here for hours now with no luck solving it.

What you really want to do is measure the time between one switch transitioning from ON to OFF and the other transitioning from OFF to ON. If that time is below a threshold you can insert a delay (or a delta delay) before reversing. This can easily be done with the millis() function.

I actually did this for my lathe which runs off of a treadmill motor because the result of not waiting until the motor stopped was a burnt Power MOSFET in the controller (just saying...). In my case I used a state machine because I was monitoring other things as well. If I get a chance I'll try to give you more details later.

ToddL1962.
Thank you for the hint, i was trying to make it harder than it really was.

I work for company that manufactures and sells VFDs and 28 years experience. What VFD are you using?
Normally it should be possible to change direction. Drive decelerates to 0, changes direction and accelerates. Maybe it's a matter of setting some parameters.

Hi,
What model Arduino controller are you using?

Tom.... :slight_smile:

Its an old Danfoss 3006 vfd, im using a Nano

Arnoud,
I will check the settings on the vfd. I should be able to DC Brake the motor, it says so in the manual.
The lathe is fitted with a brake on the motor, thats why i wanted a delay so that the motor brake will help slow it down before a direction change.
This is only an issue when im threading because i have to put it in reverse at the end of the thread (Using metric threads)