Hello everyone!
I’m developing a bldc motor controller and looking for a reliable microcontroller to run FOC_current mode, and to be able to program it through Arduino IDE. Preferebly, the size of the microcontroller should be the size of a Arduino Nano, or STM32 Nucleo 32, becouse my board has a layout that fits this size. I have seen the Supported Hardware section on the web site, but i am looking for something that was already tried out, to be as sure as possible, that it is going to work smoothly.
In the beggining i was using a basic Arduino Nano, but it didn’t have enough Flash memory available.
Then i wanted to use an STM32 L432KC nucelo32, but there are problems with communication with Arduino IDE. I am runnnig short on time to finish the project and i cant spend another week or two looking what the problem is.
That’s why i want to ask the community to help me pick one that is going to work well.
If you have experience with a microcontroller, and you already tested that it is going to work with Arduino IDE please give me a hint.
In the Nano shape we would support, out of the box, also any of the newer Arduino Nanos, like the Nano 33 BLE, the Nano 33 IoT or the Nano 33 Sense.
We would also support the Nucleo 32 boards… while the STM32L series might give you some trouble, the STM32F4 or STM32G4 should be well supported.
Note also that with some effort we can probably get the L432 to work. It sounds like you were having problems with the flash memory size, which is usually something that can be fixed with options, or in the worst case by creating your own board description files…
What sensors do you need to use? Is your motor sensored? The only problem with that board is the limited number of pins, depending on your angle sensoring scheme.
@runger@Valentine Thank you so much for all your help @Valentine The position feedback on the motor are Hall sensors, and i am planning to use in-line current sensing.
You will have enough free analog and IO pins for that.
When you get to that point if you decide to use the G431KB please come back here and ask, I will post the pin mappings that would work in your case. I was going to do this anyways because I’m in the process of mapping the G431KB board to make it work with the SimpleFOC Power Shield but I may speed it up if your needs are urgent.
Hey @Valentine thanks for the offer, i ordered the STM32G431KB T6U, so if you would like to help me with the pin mappings that would be great. I am planning to connect 6PWMbldc driver to 3 high/low N-mosfet drivers with hall sensors and 2 in-line curent sensors. If hardware interrupts possible then would be cool to use them. Thanks again!
Below is the open loop code for testing. We have to re-write the code because I commented out a bunch of stuff you won’t need, but may need later. The way I posted it, it will work well for testing as is.
// Open loop motor control example
#include <SimpleFOC.h>
// BLDCMotor motor = BLDCMotor(pole pair number);
BLDCMotor motor = BLDCMotor(1);
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PA7, PA9, PB0, PA10, PF0, PA4);
//target variable
float target_velocity = 3.0;
float target_voltage = 3.0;
int analog_read_A0 = 0;
int analog_read_A1 = 0;
// instantiate the commander
//Commander command = Commander(Serial);and.scalar(&target_velocity, cmd); }
//void doTarget(char* cmd) { comm
void setup() {
//pinMode(PA15, OUTPUT);
//digitalWrite(PA15, LOW);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
//driver.enable_active_high = false; // INFINEON ELICE DRIVER
// pwm frequency to be used [Hz]
driver.pwm_frequency = 10000;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor movements
motor.voltage_limit = 12; // [V]
motor.velocity_limit = 100; // [rad/s] cca 50rpm
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
motor.init();
// add target command T
//command.add('T', doTarget, "target velocity");
//Serial.begin(115200);
//Serial.println("Motor ready!");
//Serial.println("Set target velocity [rad/s]");
_delay(1000);
}
void loop() {
//analog_read_A0 = analogRead(PA3);
//analog_read_A1 = analogRead(PA4);
//target_velocity = float(map(analog_read_A0, 0, 4096, 0, 10000))/100.0;
//target_voltage = float(map(analog_read_A1, 0, 4096, 0, 1200))/100.0;
motor.voltage_limit = target_voltage;
// open loop velocity movement
// using motor.voltage_limit and motor.velocity_limit
motor.move(target_velocity);
// user communication
//command.run();
}
Hey @Valentine!
I was wondering if you might have some time to post the hall sensor - closed loop code and maybe also the current sensors code. I’ve got the open loop going and it works perfectly. The commander interface in open-loop also works the way it should.
I also tried to get the closed loop - velocity control going but there is a problem.
The code loads and everytghing seems to be ok, the driver.init(), sensor, motor.init(), FOC functions load correctly. Then when i try to use a commander command in the serial monitor/commander, it also seems to be working and the commander responds to setting target velocity in the serial monitor window.
The problem is, there is completely no PWM signal form the microcontroller no matter what the set target velocity is. I tried out multiple code configurations and nothing helps.
Also, when i add commander command for Full motor configuration:
command.add('M',onMotor,"full motor config");
the driver(), sensor() and rest of the functions stop loading and the code breaks, basically everything stops responding.
I tested the Hall sensors and they give out correct signals, and i have no further idea what the problem might be becouse the open loop works exactly the way it should.
I believe the problem is that you are accessing the default Serial. Please remove all references to serial and commander (comment them out) and try running a slow fixed speed. The default Serial conflicts with some of the other pins.
Hi @Valentine ,
I have this board and am finding the same as OP, I get no PWM out, even with your code above that comments out all serial.
I notice you did a solder bridge of SB8, what was that for, I havn’t done that …
Here is what I have for code …
// Open loop motor control example
#include <SimpleFOC.h>
// BLDC motor & driver instance
// BLDCMotor motor = BLDCMotor(pole pair number, phase resistance (optional) );
BLDCMotor motor = BLDCMotor(15);
// BLDCDriver6PWM( int phA_h, int phA_l, int phB_h, int phB_l, int phC_h, int phC_l, int en)
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PA7, PA10, PF0, PA9, PB0);
// instantiate the commander
//Commander command = Commander(Serial);
//void onTarget(char* cmd) { command.target(&motor, cmd);}
//void onMotor(char* cmd) { command.motor(&motor,cmd); }
void setup() {
//Serial.begin(115200);
// power supply voltage [V]
driver.voltage_power_supply =14;
driver.pwm_frequency = 1000;
// driver config
//Serial.print("Driver init ");// init driver
if (driver.init())
//Serial.println("success!");
//else{Serial.println("failed!");
//return;}
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor movements
//motor.phase_resistance = 0.5; // [Ohm]
//motor.current_limit = 3; // [Amps] - if phase resistance defined
motor.voltage_limit = 5; // [V] - if phase resistance not defined
motor.velocity_limit = 50; // [rad/s] cca 50rpm
//driver.dead_zone = 0.02;
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
motor.init();
// add target command T
//command.add('T', onTarget, "target velocity");
//command.add('M',onMotor,"full motor config");
//command.motor(&motor,"E0");
//Serial.println("Motor ready!");
//Serial.println("Set target velocity [rad/s]");
_delay(1000);
}
void loop() {
// open loop velocity movement
// using motor.voltage_limit and motor.velocity_limit
motor.move(0.01);
//motor.move(5);
// user communication
//command.run();
}
Where would you want us to set this as default? Not sure if we provide platformio files!
What we could do is put an obvious warning as Serial.println. e.g hardware detection failed, check lib_archive.
It will be part of the next release, but unfortunately I think it might not be enough to fix the issue.
I agree that this issue is very annoying and causes a lot of problems for our users. I would love to find another solution. Perhaps it’s a point for the 2.5 release to move away from the weak bindings again.