Hi @NINAD_RAGIT . For the control of two gimbal motors you will need 4 TB6612s because we need 3 half H-bridge per motor. This is a trick because those drivers are done for DC motors driving and not for the control of BLDC motors. This way one of the two driving board is fully used while the second one is only half used.
Hi Group,
I am a complete noob and new member and found my way here while trying to figure out how to drive a small gimbal motor. I got the L298N and I’ve wired everything up just like Antun_Skuric’s example above and loaded that code as well.
But the motor won’t spin. I hope I might resurrect this discussion from a while ago to find some help. Can anybody here take a minute to look at this?
I hope I can get some clues to how to get this running. Here is the motor I’m hooking up…
I copied @Antun_Skuric 's code above, activating OUTPUT for pin 8 (see below). I think I wired everything correctly, but with power nothing happens. For my project I just need to figure out how to get the gimbal to spin with continuous rotation at various speeds. There must be more that I need to configure here. I don’t understand all the brushless motor specifications, but this one has 14 poles, KV 80 and with 6-14v operating voltage.
Any tips would be greatly appreciated!
// Open loop motor control example for L298N board
#include <SimpleFOC.h>
#define IN1 11
#define IN2 10
#define IN3 9
#define IN4 8
// BLDC motor & driver instance
// BLDCMotor motor = BLDCMotor(pole pair number);
BLDCMotor motor = BLDCMotor(7);
// BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
BLDCDriver3PWM driver = BLDCDriver3PWM(IN1, IN2, IN3);
void setup() {
// deactivate the OUT4 output
pinMode(8,OUTPUT);
digitalWrite(8,LOW);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 5;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor movements
motor.voltage_limit = 3; // [V]
motor.velocity_limit = 20; // [rad/s]
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
motor.init();
Serial.begin(115200);
Serial.println("Motor ready!");
_delay(1000);
}
float target_velocity = 2; // [rad/s]
void loop() {
// open loop velocity movement
// using motor.voltage_limit and motor.velocity_limit
motor.move(target_velocity);
}
You can definitely get this working. Check operation of everything with an oscilloscope stage by stage. If there is current through the motor you should be able to tell when you try to turn it as it will resist. I noticed your power supply is 5 volts in the code. You could try a higher voltage, that might help.
I wouldn’t connect the motor until you can verify everything with a scope, you may burn out the motor, as I said the rated voltage means nothing in this context.
I always used motor.target(rads/s), then just call motor.move() at high frequency, I don’t know if the proper way to do it is to call motor.move(rads/sec).
Hey @Richard_Torsney, welcome to SimpleFOC!
It’s not clear what is wrong from your code… would you mind sharing a picture of your setup so we can see the pin connections?
One thing that might be a problem is that the 5V is very near the lower limit of the board’s input? Have you tried increasing the voltage a little, to 6V or 8V perhaps?
@Richard_Torsney you might need to check output pins as in my case it was out1 out2 and out3 instead of out4
btw which one is the middle phase among these how do you figure it out
I am not sure I understand the question?
What do you mean by “middle phase”?
For the motor, it does not matter which phase output is connected to which motor phase. You can switch them as you wish. Switching any two will change the direction the motor turns.
I’m pretty sure I have the connections right per Antun’s diagram above…
I switched power supplies and changed board power input to 12V with no apparent change. Also experimented a little with motor.voltage_limit = ;
(hope I didn’t burn it out) also with no result.
One small thing you might have missed from my code above is a change to one line. The compiler gave me a “has not been declared” error for this line…
motor.controller = ControlType::velocity_openloop;
…so I made this modification that I found with a search somewhere else (can’t remember where)…
motor.controller = MotionControlType::velocity_openloop;
Here’s the whole thing with changes…
// Open loop motor control example for L298N board
#include <SimpleFOC.h>
#define IN1 11
#define IN2 10
#define IN3 9
#define IN4 8
// BLDC motor & driver instance
// BLDCMotor motor = BLDCMotor(pole pair number);
BLDCMotor motor = BLDCMotor(11);
// BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
BLDCDriver3PWM driver = BLDCDriver3PWM(IN1, IN2, IN3);
void setup() {
// deactivate the OUT4 output
pinMode(8,OUTPUT);
digitalWrite(8,LOW);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor movements
motor.voltage_limit = 6; // [V]
motor.velocity_limit = 20; // [rad/s]
// open loop control config
// motor.controller = ControlType::velocity_openloop;
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
motor.init();
Serial.begin(115200);
Serial.println("Motor ready!");
_delay(1000);
}
float target_velocity = 2; // [rad/s]
void loop() {
// open loop velocity movement
// using motor.voltage_limit and motor.velocity_limit
motor.move(target_velocity);
}
Looking at the setup, I am not sure what is up.
The L298N board I have has +12V on the outside end of the power terminal. The middle is GND, so if you apply somewhere in the range 7-12V to this power input, like in your picture, then you should get a red light like this:
If the LED doesn’t come on when you apply power it’s probably time to get a new one… luckily they’re super-cheap!
THanks. I will check power connections again. I had not looked closely, but wondered if there was an indicator LED. I have not seen it light up at all.
Well I double-checked the connections, tried another 12V power supply and also hooked up the second L298N that came in the 2-pack and still can’t get that LED to light up. It looks like I received two duds.
Oh man, sorry to hear that!
These drivers are very cheap, so maybe the quality control isn’t that good. I bought mine in a 10-pack
Anyway, if they work I did not find them hard to use, so the fact you’re having so much trouble along with the LED not coming on does very much indicate they may just be broken.
If you get working ones they should be quite easy to set up, but fair warning: don’t expect great performance from this driver even if it works as expected…