Quantcast
Channel: Seeedstudio Forum
Viewing all articles
Browse latest Browse all 6612

Grove I2C Motor Driver v1.3 - Frequency Change Not Working

$
0
0
Hello.
I am trying to create a PC fan controller for which the optimal frequency is ~25 kHz. I have a Seeeduino Lotus v1.0 plugged into I2C motor driver v1.3b. I am able to change my fan speed easily, but my frequency is way too low. With an oscilloscope I measure my frequency at only 30.12 Hz. I have tried changing PWMFrequencySet from 0x84 to 0x01 and 0xFF. I've also tried changing "Frequence" from 0x00 to 0xFF. I am seeing no change in frequency at all. Am I calling the function incorrectly? Please help.

This is my code:

Code: #include <Wire.h>

#define MotorSpeedSet             0x82
#define PWMFrequenceSet           0x01  //default 0x84
#define DirectionSet              0xaa
#define MotorSetA                 0xa1
#define MotorSetB                 0xa5
#define Nothing                   0x01
#define EnableStepper             0x1a
#define UnenableStepper           0x1b
#define Stepernu                  0x1c
#define I2CMotorDriverAdd         0x0f   // Set the address of the I2CMotorDriver

void setup()  {
  Wire.begin(); // join i2c bus (address optional for master)
  delayMicroseconds(10000);
  Serial.begin(9600);
  Serial.println("setup begin");
}

void loop()  {
  // the following code sent commands to motor driver to drive DC motor
  while(1)  {
    Serial.println("sent DC speed 100");

    delay(50);
    MotorSpeedSetAB(50,100);//defines the speed of motor 1 and motor 2;
    delay(50); //this delay needed
    MotorDirectionSet(0b1010);  //"0b1010" defines the output polarity, "10" means the M+ is "positive" while the M- is "negtive"
                                // make sure M+ and M- is different polatity when driving DC motors.
    delay(50);
    MotorPWMFrequenceSet(0x01);
    delay(5000); 
    //MotorDirectionSet(0b0101);  //0b0101  Rotating in the opposite direction
    delay(5000);
  }
}

//////////////////////////////////////////////////////////////////////
//Function to set the 2 DC motor speed
//motorSpeedA : the DC motor A speed; should be 0~100;
//motorSpeedB: the DC motor B speed; should be 0~100;

void MotorSpeedSetAB(unsigned char MotorSpeedA , unsigned char MotorSpeedB)  {
  MotorSpeedA=map(MotorSpeedA,0,100,0,255);
  MotorSpeedB=map(MotorSpeedB,0,100,0,255);
  Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
  Wire.write(MotorSpeedSet);        // set pwm header
  Wire.write(MotorSpeedA);              // send pwma
  Wire.write(MotorSpeedB);              // send pwmb   
  Wire.endTransmission();    // stop transmitting
}

//set the direction of DC motor.
void MotorDirectionSet(unsigned char Direction)  {     //  Adjust the direction of the motors 0b0000 I4 I3 I2 I1
  Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
  Wire.write(DirectionSet);        // Direction control header
  Wire.write(Direction);              // send direction control information
  Wire.write(Nothing);              // need to send this byte as the third byte(no meaning) 
  Wire.endTransmission();    // stop transmitting
}

//set the prescale frequency of PWM, 0x03 default;
void MotorPWMFrequenceSet(unsigned char Frequence)  {   
  Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
  Wire.write(PWMFrequenceSet);        // set frequence header
  Wire.write(Frequence);              //  send frequence
  Wire.write(Nothing);              //  need to send this byte as the third byte(no meaning) 
  Wire.endTransmission();    // stop transmitting
}


Statistics : Posted by sirhannick • on Mon Jan 19, 2015 5:32 am • Replies 7 • Views 234

Viewing all articles
Browse latest Browse all 6612

Trending Articles