How to use AS5048A PWM model to do FOC control?

My system is like photo below:

And I try the "getting start " subsection codes of “writing the code” section. I succeed in the Step 1. Testing the sensor, Step 2. Testing the driver + motor combination - open-loop but failed in Step 3. Closed-loop control - torque using voltage with :

MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CCW
MOT: PP check: fail - estimated pp: 39.05
MOT: Zero elec. angle: 5.11
MOT: No current sense.
MOT: Ready.
Motor ready.

and my codes like:

#include  <arduino.h>
#include <SimpleFOC.h>
// motor
BLDCMotor motor = BLDCMotor(7);

// driver
BLDCDriver3PWM driver = BLDCDriver3PWM(9,5,6,8);

// sensor
MagneticSensorPWM sensor = MagneticSensorPWM(2, 12, 4111);

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

// instantiate the commander
// Commander command = Commander(Serial);
// void doTarget(char* cmd) { command.scalar(&motor.target, cmd); }
// void doLimit(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }
// instantiate the commander
Commander command = Commander(Serial);
void doMotor(char* cmd) { command.motor(&motor, cmd); }

void setup() {
  
  // use monitoring with serial 
  Serial.begin(115200);
  // enable more verbose output for debugging
  // comment out if not needed
  SimpleFOCDebug::enable(&Serial);

  // 
  sensor.init();
  sensor.enableInterrupt(doPWM);
  motor.linkSensor(&sensor);

  //
  driver.voltage_power_supply = 12;
  if(!driver.init()){
    Serial.println("Driver init failed!");
    return;
  }
  motor.linkDriver(&driver);

  // aligning voltage
  motor.voltage_sensor_align = 5;

  // set motion control loop to be used
  motor.torque_controller = TorqueControlType::voltage;
  motor.controller = MotionControlType::torque;

  // comment out if not needed
  motor.useMonitoring(Serial);

  // initialize motor
  if(!motor.init()){
    Serial.println("Motor init failed!");
    return;
  }
  // align sensor and start FOC
  if(!motor.initFOC()){
    Serial.println("FOC init failed!");
    return;
  }

  // set the initial motor target
  motor.target = 2; // Volts 

  // add target command M
  command.add('M', doMotor, "Motor");

  Serial.println(F("Motor ready."));
  Serial.println(F("Set the target using serial terminal and command M:"));
  _delay(1000);
}

void loop() {
  // main FOC algorithm function
  motor.loopFOC();

  // Motion control function
  motor.move();

  // user communication
  command.run();
}

what’s the problem?

Hi @ErDong886 , welcome to SinpleFOC!

I would advise strongly against using the PWM mode of the sensor. The speed and accuracy are very low, and it will greatly limit your performance, if you get it working at all.

This sensor has a SPI interface, that will work much better…

Thanks for your reply!!! I will try it soon.