Thread Tools
This thread is privately moderated by AlkaM, who may elect to delete unwanted replies.
Mar 12, 2018, 08:01 PM
Registered User
Thread OP
Discussion

Writing ESC firmware.. and a 32 bit speed conroller using STM32f051 and MP6531.


Well, the last couple weeks of my life disapeared. I decided to try and write my own firmware for a 32 bit speed controller. I used the same processor as the KISS esc and BL_HELI32 because it makes a whole lot of sense. It was a toss up between that and the NXP Kinetis MCU as they both have the right peripherals and about the same price but I figured I would at least make hardware / software compatible with what's out there now. About a year ago I made a schematic for a firmware written by another user, DrDisorder, that was somewhere on here and faded into forum obscurity. Unfortunately it got delayed for a year. I never did get to try it. I also wanted to have regular 1000-2000us servo PWM input and tachometer output and stuff like that.
Stm32f051 firmware progress. 32 bit esc (2 min 49 sec)

Lately I got some MP6531 pre drivers in the mail. I wanted a problem for my solution and made a couple of motor drivers. One using the bb2 silabs chip and the other using the STM32F051. I decided to write firmware from the ground up, one , because I could not understand any of the other firmwares that were out there. ASM looks just bizarre to me. I had never worked with an stm32 processor before so it was a bit of a learning curve just figureing out how to initialize this and that and get things running. After the first few days of mucking around i had an open loop six step motor control going. Thats when the trouble started. I would get the motor going in a stable open loop commutation and then try and write code to switch based on what i was seeing on the scope. This is the WRONG approach for writing sensorless commutation. I burned a couple of mosfets on my test ESC, I had failure after failure. The back emf I saw during open loop control was not indicative of what i was going to see when the motor is in operation. Instead of writing commutation timing based on what I observed I just wrote what I thought SHOULD work. It made things a whole lot easier. This was after 20+ hours of writing code that I ended up deleting. It ran !!

I don't know what happened the next few minutes, I don't know if I was dancing or just blacked out and twitching but at least it gave me what I need to keep going. Once everything was running (poorly) I just made every possible variable and adjustment imaginable and fired up STMStudio. This handy little program allows you to adjust variables in memory real time. So i just start tweaking this and that, blank times, delay time, advance times and seeing what works. This made the process very very fast. After another day I had the sensorless control working fine with my good old trusty 1000kv ebay special motor. The startup dialed in for no load and the 1045 prop and the servo signal input working.

So now that I know the hardware works fine the gerbers and source files are below. My last blog post has a pdf schematic of a mp6531 driver using silabs processor, this uses the same schematic just with the st processor stuck in there. I have pin headers for rx tx, swdio, swclk, pa2 for input. There's a voltage divider and current shunt too, not implemented yet. It's pin compatible with the wraith_32 so blheli_32 would run on it. Or my firmware on Wraith32 but I would strongly advise against that. There is a very definite ( 100%) possibility (eventuality) that this firmware will blow up your motor controller at some point.. just the same.. here is also a hex file that can control it. It takes a servo input but beware !! 1000us is the motor start point and there is no arming procedure yet. I am not responsible for loss of limbs. This hex is just to verify that the hardware works.
Last edited by AlkaM; Mar 13, 2018 at 07:49 AM.
Sign up now
to remove ads between posts
Mar 14, 2018, 12:41 PM
Registered User
Thread OP
More testing, this time with a 2300kx 2403 motor.

Another diy 32 bit ESC test, with load 2300kv racerstar motor. (1 min 23 sec)
Mar 15, 2018, 03:26 PM
Registered User
hi

i have read your comment in blheli forum and see the link maybee you have the time to help me understand some details. if its ok for you - i have some questions.
Mar 15, 2018, 04:06 PM
Registered User
Thread OP
Yeah fire away, you can use pm if you want.
Mar 23, 2018, 01:40 PM
Registered User
Thread OP
protocols and autodetect working, chime on startup and arm.
Next add sensors and telemetry
32 bit open source esc all protocols working (1 min 13 sec)
May 19, 2018, 01:27 AM
Registered User
Hello

after a while researching und building and changing and learning with my first quadcopter, i come nearer to the esc's and motors.

My first question:

i have set in blheli the upper throttle limit to 1750 cause to have on my radio hovering at around 50 %. Is it ok to change this value manually ?

is your software also available for silab ESC's?

is your software also configurable like BlHeli ?

do you think to share your project ?

thanks in advance for your answer :
May 21, 2018, 06:22 AM
Registered User
Thread OP
Hi , the only firmware I wrote was for the 32 bit ST chip. All of my other hardware designs are intended to use blheli or blheli_s. I have a few silabs designs on the blog too.
My code for driving the ESC has setting that can be changed but only in source right now . I will be adding eeprom next to save settings then most setting will be changeable through betaflight and dshot commands. Later in the summer I will make a interface to change settings like the blheli configurator. I will share any code I have, I am cleaning it up this week to make it more readable and will upload to GitHub . There is a messy version 1.0 up now. https://github.com/conuthead/f051bldc?files=1
May 21, 2018, 04:39 PM
Registered User
Thank you for your answer.

Lets see for what kind of ECS's your software is . In the moment i have only "blheli-S" and "blheli" ESCs so i think i am not able to use your work - maybee in future i will have.
May 29, 2018, 11:54 PM
Registered User
Nice project!

Are you planning to implement everything (i mean, active freewheel, oneshot and so on) so you can compete in performance with blheli?

Do you know this project?, perhaps it would have been a good idea to branch this code.
betaflight-esc - it seems similar to blheli but on STM32F0, it seem not still functional
https://github.com/betaflight/betaflight-esc
Jun 11, 2018, 12:39 AM
Team WarpSquad
Phoboss's Avatar
Hi, do you think controlling two motors with one cpu is possible? F0 has two hardware comparators.
Jun 11, 2018, 03:52 AM
Registered User
Thread OP
Quote:
Originally Posted by Phoboss
Hi, do you think controlling two motors with one cpu is possible? F0 has two hardware comparators.
Its possible, I think the f051 might not have enough pins to do it though. I am pretty sure there will be some conflicts. The f3 has a much better chance.
Jul 01, 2018, 01:04 AM
Registered User
Hello
I realized with a esp8266 and a https://www.ebay.com/itm/BTS7960B-43...r/192001422696 a winch for big sailing ship ( more 2m ).
Receiver control and copyback potentiometer (multi turn), brushed motor.
The H-bridge is used with motor in one direction, in the other direction, pwm and brake by short circuiting the motor to have a very fast stop.
I would like to use a brushless, is there a possibility to have a controller with the same type of input control : sense, pwm ? Or ready made : Rx, potentiometer
Jul 01, 2018, 06:13 AM
Registered User
Thread OP
Quote:
Originally Posted by froussel
Hello
I realized with a esp8266 and a https://www.ebay.com/itm/BTS7960B-43...r/192001422696 a winch for big sailing ship ( more 2m ).
Receiver control and copyback potentiometer (multi turn), brushed motor.
The H-bridge is used with motor in one direction, in the other direction, pwm and brake by short circuiting the motor to have a very fast stop.
I would like to use a brushless, is there a possibility to have a controller with the same type of input control : sense, pwm ? Or ready made : Rx, potentiometer
Hi froussel, using a two line input can be acheived, the hardware would have to use two pins instead of one on the controller . Is it possible to modify your program to use a regular servo (1000-2000us pulse) output instead of the sense and pwm. Then you can use just about any brushless speed controller and not have to modify firmware or hardware.
Jul 01, 2018, 07:20 AM
Registered User
I have already tested the process the boredom is the reverse: it is necessary to mark a stop when passing to neutral and if it is not the case then no brake
Sep 10, 2018, 09:40 AM
Registered User
Hi!
I am new to designing sensorless BLDC controllers and am writing my own code. So far I am able to get the motor spinning in open loop very fast (using delay loop that gets smaller every time).. I tried to grasp your logic using your code, but could not - due to the lack of comments. Could you please explain the overall process of getting a sync. I am using STM32F103C8 (blue pill) - which lacks the internal comparators that you have setup - I am using an external LM339 module configured as in here: (https://simple-circuit.com/pic18f455...or-controller/). It would be great if you could either comment your code - or give a general overview as how to establish sync in between the interrupt pulses from LM339 (or internal comparator). Thanks a ton!

on a side note: I was researching-by-doing BLDC controllers and surprisingly took the exact same route you did - apart from the flight controllers to get here


Quick Reply
Message:
Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Whoops! AGF rc 32 Bit ESC & super narrow ESC Camille.Zhang Product Announcements 0 Dec 29, 2017 01:32 AM
New Product Vgoodrc ARM 32-bit ESC Vgoodrc Multirotor Drone Electronics 31 Aug 21, 2016 10:03 AM
Discussion RTF 32 bit ARM ESC akcom Multirotor Drone Electronics 5 Feb 25, 2016 11:27 PM
Discussion Jet Scream1400 w/Het6904, Which speed conroler can I use? Quixksilver Electric Ducted Fan Jet Talk 6 Dec 10, 2009 11:15 PM