Hi There
I’m tryin to make a setup, where I controll a GM3506 BLDC motor with the TMC 6300 motor
The code can be compiled, but the motor just makes a weird noice, move back and forth very quick and does not really do anything. I think it is maybe something to to with my motor driver, but I’m not sure. Can anyone PLEASE help me?
I have connected the pins on the tmc6300 to the Arduino pins
const int phU_h = 5;
const int phU_l = 6;
const int phV_h = 9;
const int phV_l = 10;
const int phW_h = 3;
const int phW_l = 11;
Also there is connected 5V to VIO and GND GND
This is what the serial print says
MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CW
MOT: PP check: fail - estimated pp: 14.06
MOT: Zero elec. angle: 2.23
MOT: No current sense.
MOT: Ready.
Motor commands sketch | Initial motion control > torque/voltage : target 2V.
1.0000 1.0000 -0.0329 0.7191
1.0000 1.0000 -0.2727 0.7121
1.0000 1.0000 0.2640 0.7191
1.0000 1.0000 0.3684 0.7191
1.0000 1.0000 -0.0946 0.7121
1.0000 1.0000 -0.3737 0.7121
1.0000 1.0000 -0.2988 0.7121
1.0000 1.0000 -0.2178 0.7121
1.0000 1.0000 -0.2556 0.7121
Here is my code:
#include <SimpleFOC.h>
const int phU_h = 5;
const int phU_l = 6;
const int phV_h = 9;
const int phV_l = 10;
const int phW_h = 3;
const int phW_l = 11;
const int encoder_J = A3;
// instantiate motor
// BLDCMotor( pole_pairs , ( phase_resistance, KV_rating optional) )
BLDCMotor motor = BLDCMotor(11);
// instantiate driver
// BLDCDriver6PWM( int phA_h, int phA_l, int phB_h, int phB_l, int phC_h, int phC_l, int en)
// - phA_h, phA_l - A phase pwm pin high/low pair
// - phB_h, phB_l - B phase pwm pin high/low pair
// - phB_h, phC_l - C phase pwm pin high/low pair
// - enable pin - (optional input)
BLDCDriver6PWM driver = BLDCDriver6PWM(phU_h,phU_l, phV_h,phV_l, phW_h,phW_l);
// instantiate sensor
// MagneticSensorPWM(uint8_t _pinPWM, int _min_raw_count, int _max_raw_count)
// - _pinPWM: the pin that is reading the pwm from magnetic sensor
// - _min_raw_count: the minimal length of the pulse (in microseconds)
// - _max_raw_count: the maximal length of the pulse (in microseconds)
MagneticSensorPWM sensor = MagneticSensorPWM(encoder_J, 4, 904);
Commander command = Commander(Serial);
void onMotor(char* cmd){ command.motor(&motor, cmd); }
void setup() {
pinMode(encoder_J, INPUT);
pinMode(phU_h, OUTPUT);
pinMode(phU_l, OUTPUT);
pinMode(phV_h, OUTPUT);
pinMode(phV_l, OUTPUT);
pinMode(phW_h, OUTPUT);
pinMode(phW_l, OUTPUT);
// init sensor
// initialize magnetic sensor hardware
sensor.init();
// link the motor to the sensor
motor.linkSensor(&sensor);
// init driver
// pwm frequency to be used [Hz]
driver.pwm_frequency = 20000;
// power supply voltage [V]
driver.voltage_power_supply = 10;
// Max DC voltage allowed - default voltage_power_supply
driver.voltage_limit = 10;
// daad_zone [0,1] - default 0.02 - 2%
driver.dead_zone = 0.05;
// driver init
driver.init();
// enable driver
driver.enable();
// link the motor to the driver
motor.linkDriver(&driver);
// aligning voltage [V]
motor.voltage_sensor_align = 3; // default 3V
// enable monitoring
// use monitoring with the BLDCMotor
Serial.begin(9600);
// monitoring port
motor.useMonitoring(Serial);
// configure motor
// set control loop type to be used
motor.controller = MotionControlType::torque;
// contoller configuration based on the control type
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
motor.PID_velocity.D = 0;
// default voltage_power_supply
motor.voltage_limit = 10;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.01;
// angle loop controller
motor.P_angle.P = 20;
// angle loop velocity limit
motor.velocity_limit = 50;
// initialize motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// set the inital target value
motor.target = 1;
// define the motor id
command.add('A', onMotor, "motor");
// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
Serial.println(F("Motor commands sketch | Initial motion control > torque/voltage : target 2V."));
_delay(1000);
}
void loop() {
// FOC execution
// FOC algorithm function
motor.loopFOC();
// motion control loop
// velocity control loop function
// setting the target velocity or 2rad/s
motor.move();
// monitor variables
// monitoring function outputting motor variables to the serial terminal
motor.monitor();
// read user commands
command.run();
}