Hi All,
I’ve got a stepper motor I’m trying to use with simpleFOC library, setup:
-Motor: 200 PPR stepper motor
-Controller: Arduino Uno (ATMega328P)
-Driver: 4x BTS7960 (40A 25V Integrated Half-bridge driver+MOSFET)
+I have successfully used the Arduino “stepper” library to drive this exact configuration with classical stepper motor commutation and it works great.
I can get the motor spinning with simpleFOC in openloop angle/velocity, but the motion is rough, there’s a once per revolution thump, and (in angle mode) when the motor stops it sometimes (depending on the angle I stop at) makes a periodic thumping/clicking noise. I am using openloop modes for now because I figured I should get it working first with that.
My app is listed below.
// Open loop motor control example
#include <SimpleFOC.h>
// BLDC motor & driver instance
StepperMotor motor = StepperMotor(64, 3);
StepperDriver4PWM driver = StepperDriver4PWM(5, 6, 9, 10);
// 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);
}
void doVelocity(char* cmd) {
command.scalar(&motor.velocity_limit, cmd);
}
void setup() {
// set enable lines high
pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT);
digitalWrite(1, 1); digitalWrite(2, 1); digitalWrite(3, 1); digitalWrite(4, 1);
driver.voltage_power_supply = 5;
driver.voltage_limit = 5;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
motor.voltage_limit = 4; // [V]
// limit/set the velocity of the transition in between
// target angles
motor.velocity_limit = 2 * 3.141592; // [rad/s] cca 50rpm
// open loop control config
motor.controller = MotionControlType::angle_openloop;
// init motor hardware
motor.init();
// add target command T
command.add(‘T’, doTarget, “target velocity”);
command.add(‘L’, doLimit, “voltage limit”);
command.add(‘V’, doVelocity, “movement velocity”);
motor.useMonitoring(Serial); // strange compiler error without this
motor.target = 2 * 3.141592;
Serial.begin(115200);
Serial.println(“Motor ready!”);
Serial.println(“Set target position [rad]”);
_delay(1000);
}
void loop() {
// open loop velocity movement
// using motor.voltage_limit and motor.velocity_limit
// to turn the motor “backwards”, just set a negative target_velocity
//motor.move(target_velocity);
motor.move();
// function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!
motor.monitor();
// user communication
command.run();
}