0

Motor shield frequency control
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Motor shield frequency control

by 062400 on Thu Jan 24, 2019 12:01 am

Can the motor shield’s PWM frequency bet set or changed after issuing an begin() command? Can the bridge output be set to a constant ‘on’, that is a PWM = 0 ?

062400
 
Posts: 5
Joined: Sat Dec 22, 2018 2:38 am

Re: Motor shield frequency control

by adafruit_support_bill on Thu Jan 24, 2019 6:04 am

Can the motor shield’s PWM frequency bet set or changed after issuing an begin() command?

The motor shield library uses the Adafruit_MS_PWMServoDriver library for low-level control of the PCA96985 chip. That library has a setPWMFreq() function.
https://github.com/adafruit/Adafruit_Mo ... er/utility

Can the bridge output be set to a constant ‘on’, that is a PWM = 0 ?

0% PWM duty cycle would be off. If you want it ON, you need a 100% PWM duty cycle. For that, just set the speed to maximum (255)

adafruit_support_bill
 
Posts: 71765
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor shield frequency control

by 062400 on Thu Jan 24, 2019 7:09 pm

After reading a post that indicated the library is located in a sub-directory of the MotorShield location I found that and created the following code:


#include <Adafruit_MotorShield.h>
#include <Wire.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); //shield default address is 0x60
Adafruit_DCMotor *LF = AFMS.getMotor(1); //Left front is motor 1
Adafruit_MS_PWMServoDriver AFS = Adafruit_MS_PWMServoDriver();


void setup() {
AFMS.begin(); //start motor shield at the default frequency
LF->setSpeed(64); // 25% dc
LF->run(FORWARD); //
AFS.setPWMFreq(200);
}

void loop() {}

The compiler does not object to the code (finnaly) but the PWM frequency remains at the default (~1600Hz) ignoring the setPWMFreq command. Any suggestions??

Thanks

062400
 
Posts: 5
Joined: Sat Dec 22, 2018 2:38 am

Re: Motor shield frequency control

by adafruit_support_bill on Thu Jan 24, 2019 8:07 pm

Not sure why that would not work. What exactly are you trying to accomplish? Most DC motors run better at higher PWM frequencies.

adafruit_support_bill
 
Posts: 71765
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor shield frequency control

by 062400 on Fri Jan 25, 2019 12:31 am

If the code looks correct, why would the result be that the frequency does not change? Could you set a shield up and confirm or deny my result?

As to your question: I would prefer a much higher frequency of chopping. For some reason the motor shield library limits the frequency to about 1600Hz even though the tb6612 can go to 100KHz. I am wanting to characterize the driver and motor’s dynamic response using a random binary sequence. This information will alow for designing a EMC filter to decouple the PWM’s di/dt common mode noise from the power supply. The Arduino’s susceptibility to this noise is grossly misunderstood and a proper filter should solve much of the ills our community suffers from when using PWM to control power loads.

I guess I can set the on and off using setSpeed() and delays.

Thanks

062400
 
Posts: 5
Joined: Sat Dec 22, 2018 2:38 am

Re: Motor shield frequency control

by adafruit_support_bill on Fri Jan 25, 2019 7:01 am

For some reason the motor shield library limits the frequency to about 1600Hz even though the tb6612 can go to 100KHz.

The PCA9685 which is actually generating the PWM has an upper limit if 1.6KHz. If you want to work with higher PWM frequencies, we have the TB6612 available separately as a breakout which can be driven using the Ardiuno PWM pins.
https://cdn-shop.adafruit.com/datasheets/PCA9685.pdf

adafruit_support_bill
 
Posts: 71765
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.