Unexepected PWM frequency at 250Hz

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
joemcder
 
Posts: 5
Joined: Thu May 28, 2009 5:43 pm

Unexepected PWM frequency at 250Hz

Post by joemcder »

I have an Adafruit motor shield attached to a UNO and a pair of small DC motors. When I run a modified version of Adafruit's Motor test the motors cycle speed up/down and forward/reverse as expected.

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);
  }
}
Attachments
AdafruitMotorShield-M1(60%duty).JPG
AdafruitMotorShield-M1(60%duty).JPG (114.44 KiB) Viewed 478 times
AdafruitMotorShield-M2(25%duty)AnalogWrite(25%).JPG
AdafruitMotorShield-M2(25%duty)AnalogWrite(25%).JPG (124.47 KiB) Viewed 478 times
AdafruitMotorShield-M2(50%duty).JPG
AdafruitMotorShield-M2(50%duty).JPG (118.72 KiB) Viewed 478 times
Last edited by adafruit_support_rick on Wed Mar 13, 2013 8:49 pm, edited 1 time in total.
Reason: please use [CODE] tags

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Unexepected PWM frequency at 250Hz

Post by adafruit_support_bill »

Hmmm. I'll have to check into that...

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”