I´m using Space Vector PWM. If this helps you here are my Code.
#include <SimpleFOC.h>
#define INH_A 6
#define INH_B 9
#define INH_C 11
#define INL_A 7
#define INL_B 10
#define INL_C 12
#define EN_GATE 8
#define M_PWM 3
#define M_OC 4
#define OC_ADJ 5
#define MOVE 13
#define _MON_TARGET 0b1000000 // monitor target value
#define _MON_VOLT_Q 0b0100000 // monitor voltage q value
#define _MON_VOLT_D 0b0010000 // monitor voltage d value
#define _MON_CURR_Q 0b0001000 // monitor current q value - if measured
#define _MON_CURR_D 0b0000100 // monitor current d value - if measured
#define _MON_VEL 0b0000010 // monitor velocity value
#define _MON_ANGLE 0b0000001 // monitor angle value
// motor instance
BLDCMotor motor = BLDCMotor(4,0.4,300,0.01);
// driver instance
BLDCDriver6PWM driver = BLDCDriver6PWM(INH_A, INL_A, INH_B,INL_B, INH_C, INL_C, EN_GATE);
// InlineCurrentSensor constructor
// - shunt_resistor - shunt resistor value
// - gain - current-sense op-amp gain
// - phA - A phase adc pin
// - phB - B phase adc pin
// - phC - C phase adc pin (optional)
InlineCurrentSense current_sense = InlineCurrentSense(0.05, 12.22, A0, A1, A2);
// Hall sensor instance
// HallSensor(int hallA, int hallB , int cpr, int index)
// - hallA, hallB, hallC - HallSensor A, B and C pins
// - pp - pole pairs
HallSensor sensor = HallSensor(21, 20, 19, 4);
// Interrupt routine intialisation
// channel A and B callbacks
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}
// commander interface
Commander command = Commander(Serial);
void onMotor(char* cmd){ command.motor(&motor, cmd); }
void onMotion(char* cmd){ command.motion(&motor,cmd); }
void setup() {
// monitoring port
Serial.begin(115200);
//motor.KV_rating = 300; // rpm/volt - default not set
//Monitroing commands
motor.useMonitoring(Serial);
SimpleFOCDebug::enable(NULL);
//display variables
motor.monitor_variables = _MON_TARGET | _MON_VEL | _MON_ANGLE | _MON_VOLT_Q;
// downsampling
motor.monitor_downsample = 10; // default 10
// check if you need internal pullups
sensor.pullup = Pullup::USE_INTERN;
// maximal expected velocity
//sensor.velocity_max = 1000; // 1000rad/s by default ~10,000 rpm
// initialise encoder hardware
sensor.min_elapsed_time = 0.0001; // 100us by default
sensor.init();
// interrupt initialization
// enable hall sensor hardware interrupts
sensor.enableInterrupts(doA, doB, doC);
// hardware interrupt enable
// sensor.enableInterrupts(doA, doB, doC);
motor.linkSensor(&sensor);
// DRV8302 specific code
pinMode(MOVE,OUTPUT);
digitalWrite(MOVE,LOW);
// M_OC - enable over-current protection
pinMode(M_OC,OUTPUT);
digitalWrite(M_OC,LOW);
// M_PWM - enable 6pwm mode (can be left open)
pinMode(M_PWM,OUTPUT);
digitalWrite(M_PWM,LOW);
// OD_ADJ - set the maximum over-current limit possible
// Better option would be to use voltage divisor to set exact value
pinMode(OC_ADJ,OUTPUT);
digitalWrite(OC_ADJ,HIGH);
// configure driver
driver.voltage_power_supply = 24;
driver.init();
motor.linkDriver(&driver);
// link current sense and driver
current_sense.linkDriver(&driver);
// choose FOC modulation
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// set control loop type to be used
motor.controller = MotionControlType::velocity;
// voltage torque control mode
//motor.torque_controller = TorqueControlType::voltage;
// controller configuration based on the control type
// default P=0.5 I = 10 D =0
motor.PID_velocity.P = 0.01;
motor.PID_velocity.I = 0.1;
motor.PID_velocity.D = 0;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PID_velocity.output_ramp = 2000;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.05;
// setting the limits
// maximal velocity of the position control
motor.velocity_limit = 500; // rad/s - default 20
// angle loop controller
//motor.P_angle.P = 20;
// since the phase resistance is provided we set the current limit not voltage
// default 0.2
motor.current_limit = 20; // Amps
// angle loop velocity limit
//motor.velocity_limit = 1000;
// power supply voltage
//motor.voltage_power_supply = 12;
// default voltage_power_supply
//motor.voltage_limit = 24;
// use monitoring with serial for motor init
// monitoring port
Serial.begin(115200);
// comment out if not needed
motor.useMonitoring(Serial);
// initialize motor
motor.init();
// init current sense
current_sense.init();
// link motor and current sense
motor.linkCurrentSense(¤t_sense);
// align encoder and start FOC
motor.initFOC();
// set the initial target value
motor.target = 10;
// define the motor id
command.add('M',onMotor, "my motor motion");
command.add('T',onMotion,"motion control");
_delay(1000);
}
void loop() {
// iterative setting FOC phase voltage
digitalWrite(MOVE, HIGH);
motor.loopFOC();
digitalWrite(MOVE, LOW);
// iterative function setting the outer loop target
// velocity, position or voltage
// if target not set in parameter uses motor.target variable
motor.move();
//Monitoring values
//motor.monitor();
// user communication
command.run();
}