I'm getting started to simplefoc & Nothing is working

Hi Guys, I have a bldc motor setup with arduino and a basic driver. In the hopes of achieving Foc I tried the standalone 6pwm code. and there is no moment in the motor. I tested the voltage on the pwm pins and few pins do not have any voltage on them and the others are not generating any pwm, They are giving out a stable voltage of 1.8v - 2v. Can someone help me with getting pwm signals on the output pins of arduino uno.

code:

#include <SimpleFOC.h>

// BLDC driver instance
BLDCDriver6PWM driver = BLDCDriver6PWM(5, 6, 9,10, 3, 11, 8);

void setup() {

// pwm frequency to be used [Hz]
// for atmega328 fixed to 32kHz
// esp32/stm32/teensy configurable
driver.pwm_frequency = 50000;
// power supply voltage [V]
driver.voltage_power_supply = 12;
// Max DC voltage allowed - default voltage_power_supply
driver.voltage_limit = 12;
// daad_zone [0,1] - default 0.02f - 2%
driver.dead_zone = 0.05f;

// driver init
driver.init();

// enable driver
driver.enable();

_delay(1000);
}

void loop() {
// setting pwm
// phase A: 3V
// phase B: 6V
// phase C: 5V
driver.setPwm(3,6,5);
}

Hi @josia

I would start trying to make it working using a BLDCDriver3PWM for simplicity instead of BLDCDriver6PWM and testing with an oscilloscope if you are able to get PWM signals.

1 Like

Could you describe a bit more about the driver you are using? Is it the SimpleFOC shield?

1 Like

I tried with 3pwm, no luck

1 Like

hi, the driver is made using ir2104 mosfet driver and irfz44n FETs. Its working with other codes but not with simplefoc

Hi, yes, for IR2401 it should be BLDCDriver3PWM - these drivers have one PWM and one enable signal.

You should use the IN pins as the PWM pins and the SD pins as the EN pins.

Maybe BLDCDriver3PWM(5, 6, 9,10, 3, 11) - here 5,6,9 are IN and 10,3,11 are SD.

If you also have a separate enable input for the whole driver on pin 8, you can just switch It on separately first: digitalWrite(8, 1);

2 Likes

I tried the 3 pwm setting but the motor isnt turning, Its beeping but not turning. I also connected a AS5600 Magnetic encoding sensor behind the motor shaft. I’m getting the angle and velocity on the serial monitor, but when I run closed loop or open loop or any other code focusing on rotating the motor it isn’t working.
I want to change the driver but I have no time to do so. Can you please help me with getting the motor turn with ir2104s driver. Is it even possible to do so in the first place?

Ok, if open loop is not working, then it is a sign that this is an electrical problem or a problem with the PWM generation.

First thing to check is the PWM generation. It is best to do this with the motor power switched off, to prevent problems.
Do you have an oscilloscope or logic analyser? Then you can check each of the 3 PWM pins, using the 3-PWM mode. You can use the code like you posted, and use driver.setPwm(3,6,9); - then you should see 3 PWM waves on pins 5, 6 and 9, with duty cycles of 25%, 50% and 75%.
Please also comment out the line // driver.pwm_frequency = 50000; and leave it at the default setting for now.

I do not know the details of your driver board. If you have a circuit diagram or other information it could be helpful.

But in terms of the IR2104, if you can control its IN and SD pins, then yes, it should be possible to use BLDCDriver3PWM with these drivers, no problem.


This is the driver circuit that I’m using. I would’ve gone with simplefoc drivers, but I have a budget constrain. Getting Drv driver in india is pretty hard.

Something that you could try is checking that the cables make good contact by checking that there is a signal at both ends of them and make sure that the Arduino GND is connected to the GND of the driver board.

Can you remove all your voltage dividers at the bottom? I’m not sure why you have them all tied with one pin also, are you trying to bias it? They might be causing an issue. If you want to do in-line current sensing, it should be like this:
image

That one is a voltage sensing circuit, and it can just be ignored. SimpleFOC does not use it, but it also shouldn’t bother anything. No need to change it.

This driver circuit looks ok, and should work.

When testing, keep the voltage as low as possible for first tests. You can increase it later, when things are working well.

Do you have a chance to use an oscilloscope or logic analyzer to check the PWM output?

1 Like

I don’t have a logic analyser, I tested the outputs with a Multimeter and there is a very stable voltage of 8v at the phase output of the bldc driver.
I don’t think any pwm is being generated.

Is it mandatory to check the pwm signals with an oscilloscope ? If yes I’ll try to do so.

No, its not mandatory, but if you say the wiring is correct, and the open loop is not working, then we should find out why…

The first step to know is if the PWM is being generated correctly. If yes, then the problem will be with the driver stage. If there is no PWM then it is a MCU/Software problem…

Its possible to make a cheap logic analyser just with Arduino - it won’t be high performance, but it should be enough to see the PWM signal: GitHub - gillham/logic_analyzer: Implementation of a SUMP compatible logic analyzer for the Arduino

1 Like

I Tested arduino with an oscilloscope, It had the Open loop example running up in it. There were
pwm signal in pins 9, 10 ,11 and no moment in 3, 5, 6 .What to do?

@josia

The IR2104 driver is a single PWM input with a HIGH enable shutdown. Why do you have the SD pins taking PWM from 9,10,11 ?

Tie up all three SD to a single arduino pin, for example, 8 for driver enable function and tie the three IN to the 9, 10 and 11 each respectively.

Then the code will be something like

BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 8);

Also the code example you posted is just a static PWM test, you need to load the open loop example, that’s different code.

Cheers,
Valentine



Hi,

Are you now using 9,10,11 on the IN pins of the driver?

Could you update us with the current version of your code and the current wiring Diagram?

Hi, This is my code. 3pwm

#include <SimpleFOC.h>

BLDCMotor motor = BLDCMotor(11);

BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 3, 5, 6);

float target_velocity = 0;

Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }
void doLimit(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }

void setup() {

driver.voltage_power_supply = 12;

driver.voltage_limit = 6;
driver.init();

motor.linkDriver(&driver);

motor.voltage_limit = 3; // [V]

motor.controller = MotionControlType::velocity_openloop;

motor.init();

command.add(‘T’, doTarget, “target velocity”);
command.add(‘L’, doLimit, “voltage limit”);

Serial.begin(115200);
Serial.println(“Motor ready!”);
Serial.println(“Set target velocity [rad/s]”);
_delay(1000);
}

void loop() {

motor.move(target_velocity);

command.run();
}