I'm working on DRV8873 to drive a brushed DC motor. The problem is the pin I should connect the PWM from microcontroller.

DRV8873 datasheet

There is two digital inputs that control the outputs but I don't exactly know which one of them is PWM input?


3 Answers 3


It looks like this mode has a couple different modes actually, so you should read over them to see which one works good for you. Probably PWM mode. See section It says there,

The inputs can be set to static voltages for 100% duty cycle drive, or they can be pulse-width modulated (PWM) for variable motor speed. When using PWM mode (MODE = 1), switching between driving and braking typically is best. For example, to drive a motor forward with 50% of its maximum revolutions per minute (RPM), the IN1 pin is high and the IN2 pin is low during the driving period. During the other period in this example, the IN1 pin is high and the IN2 pin is high.

Based off of this, I would hook up IN1 to PWMxH and IN2 to PWMxL if you have those sorts of pins on your chip. It would be nice to know what one you are using. Look at Table 4, Figure 36 for some explanations for how this chip is set up too. Data sheets for these things usually have lots of information that will answer your questions, you just need to read through it, especially the parts about controlling it.

  • \$\begingroup\$ I'v already read that document. I want to use it in PWM mode. But nowhere in that datasheet mentioned about connecting PWM (that was built in microcontroller) to the device. I mean IN1 or IN2. \$\endgroup\$
    – parisa-far
    Feb 12, 2020 at 11:34

According to the datasheet both EN/IN1 and PH/IN2 can take a PWM signal input of maximum 100kHz which propagates to the output if the driver is configured correctly.

There is 3 different modes for this driver, it looks like you are interested in the "PWM" mode. To enable the PWM mode, you'll need to connect MODE pin to VDD:

Mode Pin Connected to VDD

(Page 14, Table 3)

Then, assuming nSPLEEP pin is high (connected to VDD) and DISABLE pin is low (connected to ground), you should be able to toggle IN1 and IN2 inputs to get OUT1 and OUT2 toggling with the same logic:

IN1/2 Truth Table

(Page 15, Table 5)

And as long as your PWM signal has the same logic-levels as the motor driver (using the same DVDD rail which can only be 5V for this driver), you should see the expected result from the previous table.

  • \$\begingroup\$ Thank you for your answer. I think you are right. I'll try it in the same way you told. \$\endgroup\$
    – parisa-far
    Feb 12, 2020 at 13:01

This is an old question, but the chip is still widely used and I don't think existing answers are satisfactory. They focus on chip modes instead of control methods.

Most important is that where you connect PWM is entirely up to you, it depends on the control method you want to use. While control methods and modes of operation are tightly related, they are not the same concepts. Here are your options:

Mode 0, PH/EN

In this mode you can use either Sign-Magnitude or Locked Anti-Phase control.

For Sign-Magnitude you connect PWM to EN pin and some other GPIO to PH pin. The duty cycle on EN will define speed 0..Max, and the logic level on PH will define direction. Note, that the motor is switched between drive and high-side recirculation.

For Locked Anti-Phase you connect EN to GPIO and send high level to it. The PWM is connected to PH input and the duty cycle defines both speed and direction -Max..+Max. In this case the motor is switched between active drive forward and active drive in reverse.

Mode 1, PWM

In this mode you need two PWM signals to drive motor in any direction with variable speed. You still have two control methods available to you, but they are much harder to implement, since inputs change their function between forward and reverse drive:

Magnitude Forward: IN1 = 1, IN2 = PWM
Magnitude Reverse: IN1 = PWM, IN2 = 1

For Locked Anti-Phase control you need two synchronized PWM signals, one direct and one inverted. You can actually use one signal and a simple inverter logic chip.

In PWM mode you also have alternative option for Magnitude control. Instead of switching between drive and brake you can now switch between drive and coast (open FETs):

Forward: IN1 = PWM, IN2 = 0
Reverse: IN1 = 0, IN2 = PWM

Mode 2, Independent

In this mode you have full control over voltage levels on the outputs. Basically, IN1 defines output 1 and IN2 defines output 2. This is convenient for independent unidirectional control of two motors or solenoids.

Having said that, you can connect a single motor too, then use same control methods as in Mode 0. However you will have to implement corresponding logic table in your software.

Also, if you have a spare PWM output, you can connect it to DISABLE input of the DRV8873. Then you will be able to use all control methods available in Mode 1. You will need 3 pins total and your software will be even more complicated.


I would strongly suggest reading this excellent blog by Andras Tantos to get better idea how different modes work and find some additional control methods you can use in independent drive mode.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.