SimpleFOC + Arduino + STM32F405RG [SOLVED]

Do you mean driva combines 2 vesc into one board?

No, I’m using one of these.
https://banggood.app.link/XYmcwumLufb
Two vescs on one board connected by CAN.
It’s designed to power a dual motor skateboard.

It is a combination of 2 individual sperated VESC, you make one works another works too. I noticed you had made VESC works before, what is the difference than this?

There is little difference between hooking up two vescs. The CAN bus is already connected and you only need one power supply connection.
It’s a shame the CAN terminator resistor isn’t programmable, using CAN with 3+ Vescs will probably require desoldering.

Hi @Daenzell - I’ve recently ported the SimpleFOC code to STM32 using HAL.

Here is the SimpleFOC for version 1 of the driver board: GitHub - ngalin/STM32_SimpleFOC: Port of SimpleFOC (https://github.com/simplefoc/Arduino-FOC/tree/v2.0.2) to STM32 environment.
and here is the code for code for version2 of the driver board (inline current sensing): GitHub - ngalin/STM32_SimpleFOC_InlineCurrentSense: Port of the SimpleFOC code to STM32 environment. (Original code here: https://github.com/simplefoc/Arduino-FOC/tree/v2.1)

My code is not general as Antun’s original library. It has only been tested with my hardware setup which is described in the README file. However, it should provide a good starting point to allow you to customise it to your board and application.

2 Likes

Awesome :grinning: True to your board specific, but certainly a great starting point for anyone who wants to port SimpleFOC to any other specific STM32 MCU :slight_smile:

@ngalin ,

In the Readme file

given accurate current measurements not possible

This might be the wrong thread but what did you mean by that? Could you please elaborate?

Thanks,
Valentine

Hi @Valentine,

Sure, no problem. That note is basically to remind me to look into accurate current measurements that I assume are necessary for the anti-cogging algorithm described here.

I wrote that note at a time when I was convinced that something was wrong with the current measurements that were being made because my low resistance motor was not spinning. The issue turned out to be poor choice of PID and related (ramp/limit) parameters. I haven’t had a chance to go back to this, nor understand in depth what current values are necessary for the anti-cogging algo to work.

The reason it may require further thought is that as the current is not constant during the PWM on/off periods…see attached screenshot of the PWM duty cycle, and voltage values (proxy for current from the inline current sensing chip) going into the ADC. Outstanding questions for me to explore are - can I take current measurements at any point in the waveform, or any point in time as long is it’s the same point across all angles (then I need to add an interrupt trigger based on a timer) or do I need to measure the average current waveform? or something else entirely.

Hopefully above thoughts give you a bit more context for the comment you referenced in the README file. If you have answers or more questions, please let me know!

Best,
Nat

@ngalin

Thank you. Am I to assume you have not implemented the algorithm referenced above?

Thanks,
Valentine

@Valentine - no I haven’t implemented that algorithm yet…I had attempted it though, here: STM32_SimpleFOC_InlineCurrentSense/Core/Src/BLDCMotor.cpp at main · ngalin/STM32_SimpleFOC_InlineCurrentSense · GitHub

search for: BLDCMotor::antiCoggingCalibration()

but at the time the PID control problem wasn’t resolved, and was influencing the results so you’ll see a bunch of code commented out as I was trying to figure out what was going on with the erratic motor behavior I was observing. I haven’t gone back to it yet.

In the mean time though, I found that Antun had coded up the algo here: Arduino-FOC/examples/utils/calibration/alignment_and_cogging_test at master · simplefoc/Arduino-FOC · GitHub

Look forward to getting time to go back to it :slight_smile:

@ngalin,

Antun’s calibration code seems only cogging test not the actual algo. Perhaps i am missing something.

Thanks, Valentine

@Valentine - you are correct. I had not looked closely at the code.

Thanks,
Nat