Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Change pmw frequency DRV8835?


#1

Hi,

I have problems driving a lego PF motor 8883 as discussed here.

Now please tell me how can I change the raspberry library to operate at 125khz PWM, asynchronous current recycling default 20khz?

Thanks!
Martin


#2

Hello, Martin.

You can change the PWM frequency used in the Python library for the DRV8835 Dual Motor Driver Kit for Raspberry Pi by modifying the values for _max_speed and the pwm clock speed (wiringpi.pwmSetClock()) in pololu_drv8835_rpi.py. The Raspberry Pi PWM clock has a base frequency of 19.2 MHz. You can use the following formula to figure out the values for the clock divisor and range counter to get your specific frequency:

PWM\ frequency = {19.2\ Mhz \over (clock\ divider \times range)}

- Amanda


#3

Thanks for the support!
Ok so it was like that and I tried with 1 and 150 which should then result in 128kHz, however it wouldn’t drive the motor. I switched back to the old L298N which got it running. Too bad I can’t use the DRV8835 as it’s better in soo many ways than L298N, however if the motor won’t run due to OCP is engaging I have not much use for it.

Not any ways to disable OCP?

Thanks!


#4

No; there is no way to disable the DRV8835’s over-current protection feature.

We looked at your thread on the Electrical Engineering Stack Exchange forum again and realized that the extra capacitors on the DRV8835’s VM and VCC lines could be causing the issue. In our experience with the DRV8835, we’ve noticed that the motor driver is sensitive to extra capacitance, so you might consider removing those capacitors to see if that helps the problem.

- Amanda


#5

Thanks for the support!

I guess you mean the capacitator on the motor lego 8883? Or how would i disable the capacitator on the driver DRV8835?


#6

I’m referring to the capacitors that you mentioned adding in your Stack Exchange post.

- Amanda


#7

oh sorry that’s not mine, I was only referring to it as I’m having the same problem. I’m using your Drv8835 kit for Raspberry pi ootb.
However, the post suggests that the Lego motor has additional capacitators to reduce noise, maybe I can disable those.


#8

Hi,
So I remover the capacitator but nothing happened. Been elaborating with Vin and got it working stochasticly.
I finally understood that I need to run install on setup.py again in order for the values in the formula above to change :slight_smile:

Just to be clear, is range in your formula above the variable _max_speed from pololu_drv8835_rpi.py? That number can change depending on the value you enter e.g. in motors.motor2.setSpeed(484)? ( wiringpi.pwmSetClock(2) ) is more static in that sence in isn’t set at runtime in my code?

PWM frequency=19.2 Mhz(clock divider×range)

What would you say about these drivers, except for accepting higher Vin are the better than the DRV8835 which seem a bit edgy?

Dual TB9051FTG Motor Driver for Raspberry Pi (Assembled)
#2762

Pololu Dual MC33926 Motor Driver for Raspberry Pi (Assembled)
#2756

Dual MAX14870 Motor Driver for Raspberry Pi (Assembled)
#3759

Thanks!


#9

Yes; the range counter I mentioned in my first post would be the maximum speed range (as shown here in Python library for the DRV8835 dual motor driver kit for the Raspberry Pi). None of the functions in pololu_drv8835_rpi.py change _max_speed's value, including functions setting the motor speed. That variable is used to assign a constant called MAX_SPEED and is not used anywhere else in the library.

I am not quite sure what you are asking here. Can you please rephrase the question?

Your question is pretty broad. What exactly are you looking for in a motor driver? I suggest looking at the product pages for the motor drivers you listed for differences. More details can be found in their datasheets linked under the “Resources” tab as well. You might also find the general specifications under the “Specs” tab helpful in determining which motor driver is best suited for your motor and application.

- Amanda


#10

With max_speed set to default 480 and wiringpi.pwmSetClock(2) I got the motor running with Vin=5V. Increasing Vin I had to lower Vin and with Vin=11V I got it running with max_speed set to 10; a higher max_speed value only resulting in beeping. So I guess higher Vin requires higher PMW frequency.

I’m trying to ask how setting 'motors.motor1.setSpeed(speed) for instance in example.py at runtime, affects the PMW frequence and how it is relataed to max_speed? Not really sure what I’m after here or if it makes sense.

Anyway, I got it running :slight_smile:
Thanks for the support!


#11

The PWM frequency is just one component of a PWM signal. The other part of the PWM signal to consider is the duty cycle. The setSpeed functions set the duty cycle of the PWM signal where the maximum speed requests a 100% duty cycle (or full speed). The PWM frequency specifies how fast the PWM completes a cycle. You can find a lot of online resources containing more in-depth details on how the two components affect the PWM signal to your motor.

- Amanda


#12

Thanks Amanda, then it makes sense and the small Lego PF-motor seems sensitive to PWM frequency and only accepts 100% duty cycle.
/M