Motor changes speed while sending a steady PWM signal

Hi everyone

new to motor controls with Arduino and started playing with it lately

using:
IBT_2 H-bridge motor controller
Arduino MEGA
Need For Power 24V vibration motor
2*12 V batteries in line to create 24V

I was able to control my motors using the analogWrite command until I have noticed something weird: when the motor works it runs at a changing speed even if the code supplies only one PWM value

for example:
If I supply a PWM signal of 160 the motor controller will be outputting what seems to be a randomly changing voltage between 17.5V-18.2V

I can also hear and see the motor running at different speeds according to the different voltages

const int m1_Vib_Right_Pin = 11; //output PIN - right vibration motor PWM signal
const int m2_Vib_Left_Pin = 12;  //output PIN - left vibration motor PWM signal
int m1_Vib_Right_PWM = 160; //output VALUE - PWM value to vib motor
int m2_Vib_Left_PWM = 160;  //output VALUE - PWM value to vib motor




void setup() {
  Serial.begin(115200);

  pinMode(m1_Vib_Right_Pin , OUTPUT);
  pinMode(m2_Vib_Left_Pin , OUTPUT);


}

void loop() {
  // put your main code here, to run repeatedly:
  analogWrite(m2_Vib_Left_Pin, m2_Vib_Left_PWM);
  analogWrite(m1_Vib_Right_Pin, m1_Vib_Right_PWM);
  
}

Is this normal? how do I minimize the speed changes during work?
tried also switching to a different type of motor controller with all other parts of the system intact and the problem had repeated itself.

Does it happen with only 1 motor connected?

Please provide specs / links for the devices you are using.

Is load of the motor constant?

to johnerrington
motor controller - IBT-2 H-Bridge with Arduino – Dr Rainer Hessmer

motor - Need-For-Power Motor - Micro DC Motors

I have checked it with only 1 motor connected and the problem still occurs

to Smajdalf
Not sure if the load is constant, the motor's body is held by a metal band to an arm and is spinning with nothing connected to it but the weights that make the vibration.

Will a changing load affect my output voltage? I am not using any type of encoder/ HALL sensor

It is possible. More load -> higher current requirement -> more voltage drop in power supply -> lower motor voltage -> lower speed.

void loop() {
  // put your main code here, to run repeatedly:
  analogWrite(m2_Vib_Left_Pin, m2_Vib_Left_PWM);
  analogWrite(m1_Vib_Right_Pin, m1_Vib_Right_PWM);
 
}

You shouldn’t be performing the analogWrite so often. It can have side effects. Try

void loop() {
  // put your main code here, to run repeatedly:
  analogWrite(m2_Vib_Left_Pin, m2_Vib_Left_PWM);
  analogWrite(m1_Vib_Right_Pin, m1_Vib_Right_PWM);
  delay(100);
}

barbumble:
to johnerrington

motor controller - IBT-2 H-Bridge with Arduino – Dr Rainer Hessmer

motor - Need-For-Power Motor - Micro DC Motors

I have checked it with only 1 motor connected and the problem still occurs

to Smajdalf

Not sure if the load is constant, the motor's body is held by a metal band to an arm and is spinning with nothing connected to it but the weights that make the vibration.

Recall the science/physics class about spinning weights/gyroscope? Ever ride a bicycle or a motor cycle. What happens when you turn a spinning wheel/weight? It takes force to make it tuen. The motor, in your case, has to supply that force and that makes it work harder/run slower.
Paul

@Paul_KD7HB has oversimplified a bit.

The motor has INERTIA. So it takes force to change its speed.

Also the mass is eccentric so the motor needs to supply power continuously for the energy conversion
electrical energy - mechanical energy.

Neither of these would cause a changing speed.

If SOMETHING (eg another strong vibration) made it easier or harder for the motor because of interference that could cause the speed to change

which is why i asked if it happened with just a single motor connected.

@aarg has hit the nail on the head. when you

analogWrite(m2_Vib_Left_Pin, m2_Vib_Left_PWM);

you are setting a timer to generate the pwm. It will get so far - but then you are starting it again.

And the pwm is normally at around 480 or 960 Hz - so your loop is executing faster than the timer can generate a pulse.

another +1 to add to your collection aarg! ..and a +1 to the OP for starting a very interesting discussion!

If AVR Arduino is used the frequent analogWrite should not cause problems because the timers update only once per cycle. Unless Arduino SW screws this somehow.