GM3506 BLDC and AS5048A motor just oscillates

Hello!

I finally have gotten my Storm32 V1.32 board working with my setup and have moved on to the code. To give some details about my setup I am using a iPower GM3506 motor and a AS5048A magnetic encoder (3 wire set up). The code below is what I tried piecing together (first time doing this):

//Motor 0 Pins

const int MOT0_PhA = PB1;

const int MOT0_PhB = PB0;

const int MOT0_PhC = PB7;

//Encoder Pins PWM

const int ENC1 = PC0;

const int ENC2 = PC1;

const int ENABLE_PIN = PA4;

//Poles of motor

const int pole_pair = 11; 

float target = 1.0;

// Setting up sensors 

MagneticSensorPWM sensor = MagneticSensorPWM(PC0, 5, 935);

void doPWM(){sensor.handlePWM();};

// Motor init

BLDCMotor motor = BLDCMotor(pole_pair);

// BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));

BLDCDriver3PWM driver = BLDCDriver3PWM(MOT0_PhA, MOT0_PhB, MOT0_PhC, ENABLE_PIN);

void serialLoop() {

  static String received_chars;

  while (Serial.available()) {

    char inChar = (char) Serial.read();

    received_chars += inChar;

    if (inChar == '\n') {

      target = received_chars.toFloat();

      Serial.print("Target =  ");

      Serial.println(target);

      received_chars = "";

    }

  }

}

void setup() {

  Serial.begin(115200);

  // initialise magnetic sensor hardware

  sensor.init();

  // comment out to use sensor in blocking (non-interrupt) way

  sensor.enableInterrupt(doPWM);

  _delay(1000);

  // driver config

  // power supply voltage [V]

  driver.voltage_power_supply = 12;

  driver.init();

  // link the motor and the driver

  motor.linkDriver(&driver);

  // limiting motor movements

  motor.voltage_limit = 4;   // [V]

  motor.velocity_limit = 12; // [rad/s] cca 50rpm

 

  // open loop control config  

  motor.controller = MotionControlType::velocity_openloop;

  // init motor hardware

  motor.init();

}

void loop() {

  motor.move(target);

  Serial.print(sensor.getAngle());

  Serial.print("\t");

  Serial.println(sensor.getVelocity());

}

The issue I am having is the motor powers on and begins oscillating a very small amount (ex: going form 0 degrees to 3 back to 0). Not really sure where to begin to troubleshoot but any help would be greatly appreciated!

Never mind, figured out the issue.

Hey @DGAQ, glad you’ve found it!

For the sake of the future users, could you please share what the problem was and how you solved it? :smiley:

Yes, will do! A pretty simple mistake of typing in the wrong pin for one of the motor pins :sweat_smile:

Also, how did you put the code in a window view? Was unsure how to do that.

I am also using similar motor/encoder units (GM6208 with AS5048A encoder). But the PWM signal does not change when the motor rotates. Did you need to mount an external magnet to get a signal? Or did it work out-of-the-box for you?