Unexepected PWM frequency at 250Hz

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

Moderators: adafruit_support_bill, adafruit

Unexepected PWM frequency at 250Hz

Postby joemcder » Tue Mar 12, 2013 6:28 pm

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 113 times
AdafruitMotorShield-M2(25%duty)AnalogWrite(25%).JPG
AdafruitMotorShield-M2(25%duty)AnalogWrite(25%).JPG (124.47 KiB) Viewed 113 times
AdafruitMotorShield-M2(50%duty).JPG
AdafruitMotorShield-M2(50%duty).JPG (118.72 KiB) Viewed 113 times
Last edited by adafruit_support_rick on Wed Mar 13, 2013 7:49 pm, edited 1 time in total.
Reason: please use [CODE] tags
joemcder
 
Posts: 5
Joined: Thu May 28, 2009 4:43 pm



Return to Arduino Shields from Adafruit

Who is online

Users browsing this forum: mibignistinly and 6 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [105]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]