Dual MC33926 PWM problem

Hello,

I am trying to run the motor given on the link (https://www.pololu.com/catalog/product/2286) with Dual MC33926 but I’ve run into several problems. First let me explain my setup:

I am using Dual MC33926 driver with this pin configurations:

EN -------- Arduino Digital 7
M1IN1----- Arduino Digital 4
M1IN2----- Arduino Digital 5
M1D2 ----- Arduino Digital 10 (PWM)
M1D1 ----- Arduino GND 1
GND ------ Arduino GND 2
VDD ------- Arduino 5 V
VIN -------- Power Source (+) 7 V
GND ------- Power Source (-)
M1OUT1 and M1OUT2 to Motor

and I am using this code:

#define stby 7
#define motoryon1 4
#define motoryon2 5
#define motorhiz 10

int incoming=0;
int derece;
void setup(){
  
  pinMode(stby,OUTPUT);
  pinMode(motoryon1,OUTPUT);
  pinMode(motoryon2,OUTPUT);
  digitalWrite(stby,HIGH);
  digitalWrite(motoryon1,HIGH);
  digitalWrite(motoryon2,LOW);
  Serial.begin(9600);
}

void loop(){
  
  if(Serial.available()>0){
    incoming=Serial.read()-'0';
  }
   derece=map(incoming,0,9,0,255);
   analogWrite(motorhiz,derece);
   Serial.println(derece);
   delay(1000);
}

As you can see I am giving a number from Serial port and then mapping it to PWM values. Normally the motor is running but when I watched the signal with an oscilloscope I’ve seen some problems:

  • Firstly my motor is not running until the PWM rate is 120 (assuming full PWM is 255), so it starts to run with high velocity, but I need to start running on slower speeds. When I measure the voltage on lower PWM like 50 I see 0.3-0.5 V but it supposed to be higher when you calculate it with a linear relation (e.g. x/7v = 50/255). On the other hand when the motor is running I can decrease PWM rates to for example 50 and I see voltages like 1.2-1.5 V.

  • Second problem occured when I measured the output signal given from MOUT pins. Here it means the PWM outputs. When I doesnt give a PWM rate from Arduino the voltage output stays at zero as expected. However when I start to run the motor with 1/2 duty cycle. The signal I see has a square wave with its amplitude on 7 V and its base on 2 V which should be 0 V. Well this explains why I measure highter voltages than I expected on different PWM rates but I still doesnt understand why this problem happens. Additionally the wave I see on oscilloscope is not an exact square wave. The rising edge seems a bit leaned.

I will be glad if you can tell me how to fix this problems. Normally I am trying to do position control on my motor with a potantiometer. However It starts to run on high speeds so I get errors like 80-90 degrees, which makes it hard to control with PID or something like that. Thanks for the help already

Hello.

You are using a drive-coast style control, which partially accounts for your performance issues. If you do drive-brake control, by PWMing an INx line instead of a Dx line, you will get a more linear correspondence between PWM and motor speed, and your motor should start spinning at a lower PWM. This also explains why you are seeing 2V on your oscilloscope. During the coast part of the cycle, the pin you are measuring is like a floating pin, so you can’t really expect it to be at any meaningful voltage.

Please note that even with these improvements you might be limited by the quality of your motor.

- Ryan

I tried using PWM on INX pins, it worked better. It seems like I have more control over the speed now. Thanks.

Actually I have another question. Now I am trying to use current sense feedback aswell. I tried to connect it just like the datasheet says.

First I connect FB pin to breadboard then I connect a 150 Ohm Resistor between FB pin and GND and I connect a cable from FB pin to Arduino analog pin 5. However I dont get any data from the pin. When I dont connect through resistor then I see oscillating values.

I used this simple code to read:

#define stby 7
#define motoryon1 10
#define motoryon2 9
#define current 5
unsigned long time;
float sum=0;
int turn=50;
float result;
float akim;
void setup(){
  
  pinMode(stby,OUTPUT);
  pinMode(motoryon1,OUTPUT);
  pinMode(motoryon2,OUTPUT);
  pinMode(current,INPUT);
  digitalWrite(stby,HIGH);
  Serial.begin(9600);
  
  digitalWrite(motoryon1,HIGH);
}

void loop(){
   time=millis();
   
    akim=analogRead(current);
   
 
  Serial.print(akim);
  Serial.print(",");
  Serial.println(time);
  
}

You should not be connecting a pulldown resistor there; the carrier board already has it. Oscillating values sound normal. You may have to average your readings to get meaningful data.

- Ryan

so what is the correct pin mapping on this? I can’t find anything that says how to control the motors using in1 or in2 for pwm as far as reversing the motors. any help?

It might help you to review the Truth Table (Table 6) inside the datasheet for the MC33926 driver, which you can find under the Resources tab of that motor driver’s product page. Generally speaking, setting one of the INx pins HIGH or LOW determines the direction of rotation, while the duty cycle of a PWM signal sent to the other INx pin will determine the speed of rotation in that direction.

-Jon