BUT an oscilloscope trace shows a slow PWM frequency of 250Hz! I have included several trace screen shots showing PWM output on pins 11 and 3. I also attached a scope trace of the Arduino/Shield on pin 11 and a another independent Arduino running analogWrite() on its own pin 10. analogWrite() produces 500Hz as expected.
I attached clips of Scope traces which come from Digilent's Analog Discovery, a very nice gadget.
I also attached my sketch. I'm puzzled.
By the way, the robot using the motors has expressed indifference to the PWM frequency.
He just wants his battery charged
Joe
Code: Select all
// similar to Adafruit example
#include <AFMotor.h>
#define blinker 13
AF_DCMotor motor1(1, MOTOR12_8KHZ);
AF_DCMotor motor2(2); // default = MOTOR12_1KHZ
void setup() {
//
Serial.begin(115200);
Serial.println("Motor test!");
pinMode(blinker, OUTPUT);
// turn on motor
motor1.setSpeed(200);
motor1.run(RELEASE);
delay(500);
motor2.setSpeed(200);
motor2.run(RELEASE);
}
void loop() {
uint8_t i;
runCycles(&motor1); //passing object by reference &
runCycles(&motor2);
//////////////////
Serial.println("Complete!");
motor1.run(RELEASE);
motor2.run(RELEASE);
digitalWrite(blinker, HIGH);
delay(500);
digitalWrite(blinker, LOW);
delay(500);
}
void runCycles(AF_DCMotor *pmotor)
{
Serial.print("Forward Up");
digitalWrite(blinker, HIGH);
cycleMotorUp(pmotor, FORWARD);
delay(2000);
Serial.println(" Forward Down!");
digitalWrite(blinker, LOW);
cycleMotorDown(pmotor, FORWARD);
Serial.print("Reverse Up!");
digitalWrite(blinker, HIGH);
cycleMotorUp(pmotor, BACKWARD);
delay(2000);
Serial.println(" Reverse Down!");
digitalWrite(blinker, LOW);
cycleMotorDown(pmotor, BACKWARD);
}
void cycleMotorUp(AF_DCMotor *motor, uint8_t direction)
{
int i;
motor->run(direction);
for (i=0; i<255; i++) {
motor->setSpeed(i);
delay(10);
}
}
void cycleMotorDown(AF_DCMotor *motor, uint8_t direction)
{
int i;
motor->run(direction);
for (i=255; i!=0; i--) {
motor->setSpeed(i);
delay(10);
}
}