Motor shield frequency control
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- 062400
- Posts: 5
- Joined: Sat Dec 22, 2018 2:38 am
Motor shield frequency control
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 ?
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield frequency control
The motor shield library uses the Adafruit_MS_PWMServoDriver library for low-level control of the PCA96985 chip. That library has a setPWMFreq() function.Can the motor shield’s PWM frequency bet set or changed after issuing an begin() command?
https://github.com/adafruit/Adafruit_Mo ... er/utility
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)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
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
#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
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield frequency control
Not sure why that would not work. What exactly are you trying to accomplish? Most DC motors run better at higher PWM frequencies.
- 062400
- Posts: 5
- Joined: Sat Dec 22, 2018 2:38 am
Re: Motor shield frequency control
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
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
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield frequency control
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.For some reason the motor shield library limits the frequency to about 1600Hz even though the tb6612 can go to 100KHz.
https://cdn-shop.adafruit.com/datasheets/PCA9685.pdf
Please be positive and constructive with your questions and comments.