Hello,
Recent questions made me curious if/how the library can support more than one motor on a 3PWM timer set. I used STM32F767 and wrote a simple open loop for the six timers supporting PWM on a single timer per set.
It appears that any timer combination is limited to only three motors at a time. Adding any fourth motor regardless of the channel halts the MCU within the
driver.init();
step, and thus the whole MCU hangs.
Is there a hard limit on three instances of the driver, or this is some inherent bug just applicable to STM32?
Below is the code I used for Nucleo-144 STM32F767ZI
Any input would be highly appreciated. I can test whatever you discover/change/fix.
Open loop motor control example for six motors.
Please uncomment any motor after the init to trigger the hangup.
Perhaps I’m doing something wrong?
#include <SimpleFOC.h>
BLDCMotor motor1 = BLDCMotor(1);
BLDCMotor motor2 = BLDCMotor(1);
BLDCMotor motor3 = BLDCMotor(1);
BLDCMotor motor4 = BLDCMotor(1);
BLDCMotor motor5 = BLDCMotor(1);
BLDCMotor motor6 = BLDCMotor(1);
BLDCDriver3PWM driver1 = BLDCDriver3PWM(PE9, PE11, PE13); //T1
BLDCDriver3PWM driver2 = BLDCDriver3PWM(PA5, PB3, PB10); //T2
BLDCDriver3PWM driver3 = BLDCDriver3PWM(PA6, PA7, PB0); //T3
BLDCDriver3PWM driver4 = BLDCDriver3PWM(PD12, PD13, PD14); //T4
BLDCDriver3PWM driver5 = BLDCDriver3PWM(PA1,PA2, PA3); //T5 (CH2,CH3,CH4)
BLDCDriver3PWM driver6 = BLDCDriver3PWM(PC6,PC7, PC8); //T8
//target variable
float target_velocity = 2;
float target_voltage = 5;
float maxVelo = 20; //rad/s
float maxVolt = 2;
//int analog_read_A0 = 0;
//int analog_read_A1 = 0;
unsigned long prev = 0;
unsigned long current = 0;
unsigned long threshold = 500;
void setup() {
driver1.voltage_power_supply = 12;
driver2.voltage_power_supply = 12;
driver3.voltage_power_supply = 12;
driver4.voltage_power_supply = 12;
driver5.voltage_power_supply = 12;
driver6.voltage_power_supply = 12;
driver1.pwm_frequency = 15000;
driver2.pwm_frequency = 15000;
driver3.pwm_frequency = 15000;
driver4.pwm_frequency = 15000;
driver5.pwm_frequency = 15000;
driver6.pwm_frequency = 15000;
//driver.enable_active_high = false; // Reverse logic driver, low is enable
// driver init creates a hangup for more than 3 drivers
//driver1.init();
driver2.init();
driver3.init();
driver4.init();
///driver5.init();
driver6.init();
//motor1.linkDriver(&driver1);
motor2.linkDriver(&driver2);
motor3.linkDriver(&driver3);
motor4.linkDriver(&driver4);
//motor5.linkDriver(&driver5);
motor6.linkDriver(&driver6);
//motor1.voltage_limit = target_voltage; // [V]
motor2.voltage_limit = target_voltage; // [V]
motor3.voltage_limit = target_voltage; // [V]
motor4.voltage_limit = target_voltage; // [V]
//motor5.voltage_limit = target_voltage; // [V]
motor6.voltage_limit = target_voltage; // [V]
//motor1.velocity_limit = target_velocity; // [rad/s] cca 50rpm
motor2.velocity_limit = target_velocity; // [rad/s] cca 50rpm
motor3.velocity_limit = target_velocity; // [rad/s] cca 50rpm
motor4.velocity_limit = target_velocity; // [rad/s] cca 50rpm
//motor5.velocity_limit = target_velocity; // [rad/s] cca 50rpm
motor6.velocity_limit = target_velocity; // [rad/s] cca 50rpm
//motor1.controller = MotionControlType::velocity_openloop;
motor2.controller = MotionControlType::velocity_openloop;
motor3.controller = MotionControlType::velocity_openloop;
motor4.controller = MotionControlType::velocity_openloop;
//motor5.controller = MotionControlType::velocity_openloop;
motor6.controller = MotionControlType::velocity_openloop;
//motor1.init();
motor2.init();
motor3.init();
motor4.init();
//motor5.init();
motor6.init();
_delay(500);
prev = millis();
current = millis();
}
void loop() {
//motor1.voltage_limit = target_voltage;
motor2.voltage_limit = target_voltage;
motor3.voltage_limit = target_voltage;
motor4.voltage_limit = target_voltage;
//motor5.voltage_limit = target_voltage;
motor6.voltage_limit = target_voltage;
//motor1.move(target_velocity);
motor2.move(target_velocity);
motor3.move(target_velocity);
motor4.move(target_velocity);
//motor5.move(target_velocity);
motor6.move(target_velocity);
}
Cheers,
Valentine