Hello Foc Community.
I’m using angle control mode through the v2 shield to create a variable resistance lever.
On the Arduino Giga my code works great but the noise is horrible. I found this thread fixing the issue but it isn’t compatible with the shield without jumper wiring to the more optimal timer pins. SimpleFOC on Arduino Giga - BLDC Motor buzzing - #34 by runger
So, I thought id try the R4 Minima as the compatibility hardware chart said it worked for up to 6 pwm (I want to stack thee shields eventually) and i don’t need current sense.
I’m using the dev library as recommended here Arduino Uno r4 (minima and wifi)
However I’m getting an error message;
Setup Started.
—PWM Config—
DRV: pwm pin: 5
DRV: pwm channel: 2
DRV: pwm A/B: B
DRV: pwm freq: 24000
DRV: pwm range: 1000
DRV: pwm clkdiv: 0
—PWM Config—
DRV: pwm pin: 9
DRV: pwm channel: 7
DRV: pwm A/B: B
DRV: pwm freq: 24000
DRV: pwm range: 1000
DRV: pwm clkdiv: 0
—PWM Config—
DRV: pwm pin: 6
DRV: pwm channel: 0
DRV: pwm A/B: B
DRV: pwm freq: 24000
DRV: pwm range: 1000
DRV: pwm clkdiv: 0
DRV: starting timer: 2
DRV: starting timer: 7
DRV: starting timer: 0
DRV: timers started
MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: Failed to notice movement
MOT: Init FOC failed.
FOC init failed!
Here is my code;
#include <SimpleFOC.h>
float step = 0.001; // Step size for increment/decrement
bool increasing = true; // Direction flag: true = increasing, false = decreasing
// motor instance
// driver instance
// BLDCMotor(pole pair number, phase resistance (optional) );
BLDCMotor motor = BLDCMotor(11);
// BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
BLDCDriver3PWM driver = BLDCDriver3PWM(5, 9, 6, 8);
// sensor instance
Encoder encoder = Encoder(3, 2, 500);
// interrupt routine initialisation
void doA() {
encoder.handleA();
}
void doB() {
encoder.handleB();
}
void setup() {
Serial.begin(115200);
SimpleFOCDebug::enable(&Serial);
delay(5000); // connect the serial console within 5s of booting
Serial.println("Setup Started.");
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 20;
// limit the maximal dc voltage the driver can set
// as a protection measure for the low-resistance motors
// this value is fixed on startup
driver.voltage_limit = 20;
// init the sensor
// initialise encoder hardware
encoder.init();
// hardware interrupt enable
encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&encoder);
// init the driver
if (!driver.init()) {
Serial.println("Driver init failed!");
return;
}
// link driver
motor.linkDriver(&driver);
// motor conf
// limiting motor movements
// limit the voltage to be set to the motor
// start very low for high resistance motors
// current = voltage / resistance, so try to be well under 1Amp
motor.voltage_limit = 3.0; // [V]
// set motion control loop to be used
motor.torque_controller = TorqueControlType::voltage;
motor.controller = MotionControlType::angle;
// angle loop controller
motor.P_angle.P = 20;
// use monitoring with serial
// 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 = 0.0; // Rad
delay(1000);
}
void loop() {
// Check the direction and update the value
if (increasing) {
motor.voltage_limit += step; // volts
motor.PID_velocity.limit = motor.voltage_limit;
if (motor.voltage_limit >= 8.0) { // Switch to decreasing if max value reached
increasing = false;
}
} else {
motor.voltage_limit -= step; // volts
motor.PID_velocity.limit = motor.voltage_limit;
if (motor.voltage_limit <= 3.0) { // Switch to increasing if min value reached
increasing = true;
}
}
Serial.println(motor.voltage_limit);
// main FOC algorithm function
motor.loopFOC();
// Motion control function
motor.move();
}
Any advice would be greatly appreciated!
Thank you!