Code to brake motorspeed

Hi!
Im almost finnished with my little project here. :drooling_face:
But there is one thing I havent managed to fix with my little machine.

Heres a little description on how it works now:
Its a little lifter I use for up and down. It can save its position via a rotary encoder on the motor.
And if I for example go up, it then stops at the position it has saved.
My Arduino drives a Curtis motorcontroller via a 0-5V PWM signal that i send from Arduino.
It works fine! But…
Problem is that it does not adjust for the weight that is put on it, so I cant “calibrate” it to come in right everytime.
If I save a position in a lightweight mode, it will stop long before if its loaded heavy. And vice versa. :slightly_frowning_face:
I need something to slow its speed, so that it comes in at same speed everytime just before it reaches its
stop position.

Here I attach the code I currently use.
And I write where I believe the fix-code would be. But I dont know for sure.
I would need something that lowers the speed of my lift 45 pulses before reaching its goal.

If we could fix this somehow you would be my angels! ???

// ---- THIS CODE BELOW STOPS THE MOTOR WHEN IT REACHES ITS SAVED ROTARY ENCODER POSITION
// ---- + and - here below are for the motor to begin its stop 45 pulses before the actual stop, to reduce motor sliding


  {
    if ( UserStopPulseCount != 0 && PulseCount >= UserStopPulseCount - 45 && PulseCount <= UserStopPulseCount + 45 )

HERE IS WHERE I GUESS A CODE FOR BRAKING WOULD BE GOOD   <------

    {
      digitalWrite(controlPin1, LOW);
      digitalWrite(controlPin2, LOW);
      if(okgo==0){
      lcd.setCursor(0, 1);
      lcd.print("Users Stop");
      }
      int valA = digitalRead(HighSpeed1Pin); 
      int valB = digitalRead(HighSpeed2Pin);
      while (valA+ valB>0 && okgo==0){
      Serial.println("Users programmed STOP activated ⛔");
     // Serial.println("HighSpeed1Pin %3d HighSpeed2Pin %f",HighSpeed1Pin,HighSpeed2Pin);
      delay(100);
      valA = digitalRead(HighSpeed1Pin); 
      valB = digitalRead(HighSpeed2Pin);
      }
      okgo=1;
      

    }else{
    okgo=0;  
      }
  }

If you had designed your system based on the torque needed to lift the heavy weight, then you would not have any problem with the light weight. The motor does not have enough torque, which means it does not get enough current to turn the motor properly and may indicate your controller cannot handle the extra current.

Best start over with a new design.

Paul

Paul_KD7HB:
If you had designed your system based on the torque needed to lift the heavy weight, then you would not have any problem with the light weight. The motor does not have enough torque, which means it does not get enough current to turn the motor properly and may indicate your controller cannot handle the extra current.

Best start over with a new design.

Paul

Hi!
No no, I think you have missunderstood the problem.
The engine has well enough power and torque and current to lift its weight.
I know for a fact it can lift like 10 times more than I have tested it with, its way oversized for this project.
And the motorcontroller can provide all current needed.

When the lift goes up without weight, its easier for it to "slide" a bit when stopping. Because there is not resistance at all. So it rolls a bit because there is nothing stopping it but friction.

But when loaded with weight it stops just slightly earlier, because gravity etc, and does not slide that extra centimeter like it does without weight.

This makes a difference in were it stops, its not as accurate as I want it to be altough its OK.
It sends the stop signal at the same time in both cases, but dependent on how its loaded the "slide top stop" will be different.

If I can get it to slow down just right before the stop, it would always have the same speed when coming to its stop-point, and thus get much more precise.

You are correct. I did not understand the problem.

How quickly can you stop the motor? If you used a limit switch near the top of the motion, how quickly can you stop the whole thing?

Paul

You haven't given any details on your motor controller,but most motor controllers have a brake function.
Also have you noticed how an elevator will sometimes go a little past a floor and then reverse to line up with the floor.
I am no coder,but since you already have an encoder it seems like you could do the same thing.