[RéSOLU] Steppermotor moves erratically when DMX value is ramped up slowly

Toutes les questions sur les cartes By arpschuino
Questions about arpschuino boards
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor moves erratically when DMX value is ramped up slowly

Message par Micropuller »

Whilst the homing seems to be working fine now, I'm still having this problem.

I have one steppermotor that uses an external driver and one that uses a Pololu A4988.
The problem I'm having, is that one of the motors behaves erratically (moves back and forth) when I ramp the DMX value up slowly.
This only happens with the motor that uses the external driver, only when I ramp the DMX value up slowly (from 0-255) and only when I have it configured as uninverted. When I ramp the DMX value up or down quickly there is no problem, when I ramp it down slowly (from 255-0) everything is fine and when I have the motor configured as inverted it's fine both ways, no matter if I ramp the DMX value up or down, slow or quick.

I have tried switching the motors around (so first I connected the motor with the external stepper on output stepper0 and the motor with the A4988 on output stepper1 and after that the other way around) and the problem stayed with the motor with the external driver. So it's not the output port.

It also seems that the motor continues in the direction it stopped. What I mean with that is, when the motor is behaving erratically (going back and forth instead of moving in one direction) and it's last move was clockwise and then I ramp the DMX value up quickly, it continues in that direction (clockwise). But if the last move was counterclockwise and I ramp the value up quickly, it continues in that direction (counterclockwise).
What this means is that, depending on which way the motor was turning when the DMX value reached 0 or 255, when the next move is quick, the motor reverses direction.

I know this might sound pretty confusing (well, it is confusing to me), but I hope some of you might have an idea what is causing this behaviour.
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor moves erratically when DMX value is ramped up slowly

Message par Micropuller »

Maybe this will make it a bit clearer: https://youtu.be/tpsa3cNuhgc

I start bij ramping the DMX value up quickly from 0 - 255. The motor turns clockwise (0:00 - 0:06)
Then I ramp the value down quickly from 255 - 0, The motor turns counterclockwise (0:0 - 0:10)
Again from 0 - 255 quickly, the motor turns clockwise (0:10 - 0:15)
And again from 255 - 0 quickly. The motor turns counterclockwise (0:15 - 0:19)
Then I ramp the value up slowly from 0 - 255. The motor behaves erratically (0:19 - 0:39)
Then I ramp the value down quicly from 255 - 0. The motor turns clockwise (0:39 - 0:44), where it turned counterclockwise before when I ramped it down from 255 - 0.
Then I ramp the value up quicly from 0 - 255. The motor turns counterclockwise (0:44 - 0:50)
Then again from 255 - 0 quickly. The motor turns clockwwise (0:50 - 0:55)
And again from 0 - 255 quickly. The motor turns counterclockwise (0:55 - 0:59)
And again from 255 - 0 quickly. The motor turns clockwise (0:59 - 1:04)
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor moves erratically when DMX value is ramped up slowly

Message par Micropuller »

Just a thought: could it be the signal voltage?
When ramping up, the dir pin is set high and when ramping down the dir pin is set low.
When I measure the voltage at the dir pin when ramping up the DMX value quickly, it's 3V. But when I measure the voltage whilst ramping up the DMX value slowly, I So it could be that the direction is set properly when ramping up quickly (the pin more or less remains high, so the voltage is more constant). But when I measure the voltage barely has time to come up to 3V between steps.
So it could be the dir pin is measuring a low, whilste the pulse is triggered, thus making the motor rotate in the wrong direction.
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor moves erratically when DMX value is ramped up slowly

Message par Micropuller »

I tried boosting the voltage using a level converter, but that didn't help.
Maybe this is also a timing issue?

From the driver manual:
(1) ENA must be ahead of DIR by at least 5μs. Usually, ENA+ and ENA- are NC (not connected).
(2) DIR must be ahead of PUL effective edge by at least 5μs to ensure correct direction
(3) Pulse width not less than 1.5μs
(4) low level width not less than 1.5μs
When I measure the voltage on the dir-port, I get this:

When the motor is uninverted:
When ramping the DMX value from 0 - 255, the signal is at 0V and has to go high
When ramping from DMX value 255 - 0, the signal stays at 0V.

When the motor is inverted:
When ramping the DMX value from 0 - 255, the signal is at 3V and has to go low
When ramping from DMX value 255 - 0, the signal stays at 3V.

So maybe there needs to be a delay between the dir-pulse and the step-pulse?
I guess that is a change that has to be made in the Arpstepper library?
Modifié en dernier par Micropuller le jeu. 19 janv. 2023 03:59, modifié 2 fois.
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor moves erratically when DMX value is ramped up slowly

Message par Micropuller »

I added a couple of delays to the set_direction part in the Arpstepper library. That seems to have solved the issue.
I tried several delay periods. 10 microseconds wasn't enough. 15 microseconds worked, but at 20 microseconds the motor sounds better and it doesn't seem to affect the motor's performance.

Code : Tout sélectionner

bool ArpStepper::set_direction()
{
  bool sens;
  if (m_nbr_pas>0)                  sens=LOW + m_inverted;
  else                              sens=HIGH - m_inverted;
  
  if (sens != m_previous_sens)      m_change_sens = 1;
  else                              m_change_sens = 0;
  
  m_previous_sens = sens;
  #ifdef __AVR__
    digitalWriteFast(m_dir,sens);
   delayMicroseconds(20);
    
  #else
    digitalWrite(m_dir,sens);
    delayMicroseconds(20);
    
  #endif  
  return  m_change_sens;
}
Jacques
Messages : 267
Enregistré le : dim. 31 oct. 2021 19:37

Re: Steppermotor moves erratically when DMX value is ramped up slowly

Message par Jacques »

interesting, thank you for this great work! I had not encountered this problem, which arises only with certain drivers, until now.
Note that the DIR command is not a pulse but a state (high or low) of the pin.
The problem with the delay is that it will add up as many times as there are steppers. for 8 motors, it will be 160us and I fear that it will end up slowing down the steppers and also the general execution of the code.
So I propose this modification so that it only takes place once at the time of the change of direction and not at each impulse:

Code : Tout sélectionner

bool ArpStepper::set_direction()
{
  bool sens;
  if (m_nbr_pas>0)                  sens=LOW + m_inverted;
  else                              sens=HIGH - m_inverted;
  
  if (sens != m_previous_sens)
  {
    m_change_sens = 1;
    #ifdef __AVR__
      digitalWriteFast(m_dir,sens);
    #else
      digitalWrite(m_dir,sens);
    #endif
    delayMicroseconds(20);  
  }      
  else
  {
    m_change_sens = 0;
  }    

  m_previous_sens = sens;
  return  m_change_sens;
}
I also made the same modification in the continuous() function:

Code : Tout sélectionner

bool ArpStepper::continuous()
{
  //end_of_pulse();
  #ifdef __AVR__
    digitalWriteFast(m_pull,LOW);
  #else
    digitalWrite(m_pull,LOW);
  #endif    
  if(m_must_refresh_pos_order==true)
  {
    m_must_refresh_pos_order=false;
    bool sens;
    if(m_inverted)
    {
      if (m_val<(m_resolution/2)+1)     sens=HIGH;// + m_inverted;
      else                              sens=LOW;// - m_inverted;
    }
    else
    {
      if (m_val<(m_resolution/2)+1)     sens=LOW;// + m_inverted;
      else                              sens=HIGH;
    }
    
    if (sens != m_previous_sens)
    {
      m_change_sens = 1; 
      #ifdef __AVR__
        digitalWriteFast(m_dir,sens);
      #else
        digitalWrite(m_dir,sens);
      #endif 
      delayMicroseconds(20);/////////////////////////////////////////////////       
    }      
    else                              
      m_change_sens = 0;
   
    m_previous_sens = sens;
  }
 
  if (m_val_speed>0)
    return step_plus(m_val_speed);    

  else 
    return 0;  
}
As I told you, I couldn't do any tests until next week, but I want to get back to it in depth!
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor moves erratically when DMX value is ramped up slowly

Message par Micropuller »

I tried it and unfortunately it didn't work.
As far as I can see (measure), if the motor is uninverted and the DMX value is ramped up, the dir pin is pulled high every time a step is made (when I ramp up the DMX value really slowly, you can count the individual steps). Between steps, the dir pin is low. What I think is, that if there is not enough time between the dir signal and the pulse signal, the dir pin could still be low (doesn't have enough time to go low and then high again) when the pulse signal comes in, so the motor moves in the wrong direction.
At least, that is my theory.
Jacques
Messages : 267
Enregistré le : dim. 31 oct. 2021 19:37

Re: Steppermotor moves erratically when DMX value is ramped up slowly

Message par Jacques »

hmm, this behavior is not normal.
The DIR pin should be high or low and only change when there is a change in direction.
I need to do some tests with the oscilloscope, I should be able to do it at the end of the week.
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor moves erratically when DMX value is ramped up slowly

Message par Micropuller »

This is what I measure when the motor takes one step forward (DMX value increases by one).
Channel 1 = step pin.
Channel 2 = dir pin.
400 steps/revolution
number of revolutions: 27
WhatsApp Image 2023-01-23 at 20.49.32.jpeg
WhatsApp Image 2023-01-23 at 20.49.32.jpeg (255.91 Kio) Vu 2094 fois
WhatsApp Image 2023-01-23 at 20.49.32 (2).jpeg
WhatsApp Image 2023-01-23 at 20.49.32 (2).jpeg (268.74 Kio) Vu 2094 fois
WhatsApp Image 2023-01-23 at 20.49.32 (1).jpeg
WhatsApp Image 2023-01-23 at 20.49.32 (1).jpeg (240.7 Kio) Vu 2094 fois
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor moves erratically when DMX value is ramped up slowly

Message par Micropuller »

I think I have found the problem (and it was completely my fault).
I had pulse- and dir- connected to V+ and pulse+ and dir+ to the pulse and dir pins.
This was all because I was trying to use the Arpstepper with both the A4988 and an external drive.
I was using a bridge that I have been using with another DMX-stepper converter, but that board breaks out V+ instead of Gnd.
Now I have pulse- and dir- connected to Gnd and pulse+ and dir+ connected to the pulse and dir pins and the erratic movements at slow speed seem to have gone (I also removed the delays in the code).
Répondre