Brushless electric motor (BLDC motors) are synchronous motors that are powered by a DC electric source via an integrated inverter/switching power supply, which produces an AC electric signal to drive the motor.
For an introduction to BLDC motors, you can take look at my sensored motor driver post, here: http://davidegironi.blogspot.it/2013/09/a-simple-brushless-sensored-motor.html or you can browse the internet, you will find there is a lot of litterature about BLDC motors.
This library implements a brushless sensorless motor dirver for AVR ATmega.
To write this library I take inspiration from the library above:
This library take inspiration from:
- http://davidegironi.blogspot.it/2013/09/a-simple-brushless-sensorless-motor.html: my previous project on sensorless brushless motors
- http://davidegironi.blogspot.it/2013/09/a-simple-brushless-sensored-motor.html : my previous project on sensorled brushless motors
- http://www.atmel.com/images/doc8012.pdf : AVR444 Application note - Sensorless control of 3-phase brushless DC motors
- https://github.com/tobylockley/qut-brushless-controller : a brushless driver by Toby Lockley
I've also tested a version of this code on ATmega8 running at 8Mhz.
The aim of is project is to build a fairly simple bldc driver one can embed and easly modify in order to meet their own needs.
There are of course driver that performs better than this one, so if you are looking for best performance and you are using an ATmega micro, i suggest you to take a look at the SimonK firmware (https://github.com/sim-/tgy) or the BLHeli firmware (https://github.com/bitdump/BLHeli).
My previos driver you can find on links above does not fully implements PWM, also the brushless sensorless version to detect Zero Crossing reads the ADC voltage insted of using the internal ADC comparer.
Like the previos driver, this one implements a speed and direction (clockwise and anti-clockwise) controller.
Speed and direction can be set using the proper function, the speed have to be set using a 0 to 100 interval. 0 will stop the motor, direction has defined macro available for CW and CCW set.
In the sample main file the speed is driven by an RC input library, binded to the external interrupt input PIN.
For the test project the RC signal generator is a servo tester.
The RC reader library can be found here: http://davidegironi.blogspot.com/2018/03/an-avr-atmega-rc-control-signal-reader.html
Settings for this library can be changed on the rcin2.h file.
The bldcsetup.h file containst the main settings. As example there you can find the RC input library enabler.
This driver implements 4 PWM schemes:
- H PWM L ON: PWM is performed on the ON channel
- H ON L PWW: PWM is performed on the OFF channel
- H PWM ON: PWM is performed on UWV channels every 60degrees, starting from U ON-ON
- H ON PWM: PWM is performed on UWV channels every 60degrees, starting from V OFF-NULL
One can chose the PWM scheme in the bldcsetup.h file.
The main.c file is a sample running project that use this library to run a motor.
bldcsetupmicro.h file contains specific microcontroller definition, this file should allow the implementation of this library over others than the ATmega8 microcontroller. It contains ADC registry settings and TIMER settings.
This driver can run on many board pinout, input/output PIN can be changed in the bldcsetupboard.h file.
The adc mux schema represent the order of PIN chosen as Zero Crossing detection depending on the running step.
The commutation sequence is defined in the bldc.h file.
By default it is set as follow (first group is the U bridge switch, second is the V, third is the W):
bldcsetupmicro.h file contains specific microcontroller definition, this file should allow the implementation of this library over others than the ATmega8 microcontroller. It contains ADC registry settings and TIMER settings.
This driver can run on many board pinout, input/output PIN can be changed in the bldcsetupboard.h file.
The adc mux schema represent the order of PIN chosen as Zero Crossing detection depending on the running step.
The commutation sequence is defined in the bldc.h file.
By default it is set as follow (first group is the U bridge switch, second is the V, third is the W):
- Step 1: 10-01-00
- Step 2: 10-00-01
- Step 3: 00-10-01
- Step 4: 01-10-00
- Step 5: 01-00-10
- Step 6: 00-01-10
The interface with the user consists in a bounch of function that performs:
- initialization of the library
- speed selection or retrive
- direction selection or retrive
- speed retrive in RPM
- debug function to retrive the status of the driver
- TIMER PWM: works as the PWM emitter, it emit the commutation to the power bridge according to the selected step
- TIMER MAIN: select the step to emit, depending on speed and direction selection. It works in three modes:
- startup mode: perform the startup sequence of step
- emission mode: select the commution step to run and switch to non emission mode
- non emission mode: check the BEMF for Zero Crossing detection, once the ZC is detected, the mission mode is triggered
The RPM speed estimation is performed assuming the TIMER A runs at a fixed frequency.
Further improvement can be made on the whole driver, expecially the startup stage.
Code
Notes
- read risk disclaimer
- excuse my bad english
Thanks Davide for your kind help. I have found the schematic from this blog. But the pic is not clearly visible. Please send me the clear view of schematic if any. Eagerly waiting for your early response.
ReplyDeleteDear Abhisek, please do not multi/post. Find it here: https://file.io/1PxLhURs
DeleteHi Davide, the ink is lost
DeleteHello, that link was temporary. You can find the board published here: https://davidegironi.blogspot.com/2020/02/bldc-motor-driver-atmega-dev-board.html
DeleteSir I've been trying to implement your eclipse project, but ive not been able to generate the hex file. the eclipse doesn't identify it as a C/C++ project.
ReplyDeleteDear Hassan, you have to build a new project, include the src code, then you can compile it. You can also use VSCode as an alternative. If you google for Eclipse AVR plugin tutorial you will find how to setup Eclipse to build and compile an avrgcc projeect.
Delete
ReplyDeleteHi Engineer, it is possible to enter the password of the file
Thanks
Hello, there is no password to the provided source files.
Deletehello sir can you share the hex code of your project
ReplyDeletebecause i dont know programing well
but i completely build the hardware
can you help me?
Hello, find it here: https://file.re/2021/11/19/avrlibbldc02-board2sensorless/
DeleteThe file will be automatically deleted by November 20, 2021, at 07:13 PM (CET)
thank you sir...
Deletesir i wrote one of your hex file (avr_lib_bldc02-board2sensorless.hex) from release folder to my at mega 8A-8PU
ReplyDeletebut the motor didn't run
is there anyway to solve my problem
how can i contact you
Hello, please do not multi-post the same question like you have done 4 times for this.
DeleteYou can look at the I/O PIN, using a multi-channel oscilloscope. Consider building up your compiling enviroment, my hex is for ATmega running at 16Mhz, so you also have to set Fuse of the micro. Keep in mind that setting fuse in an uncorrect way may brick your micro.
Hello sir.
ReplyDeleteThanks for your sharing. I have some question about supply voltage for bldc moter because you used cd-rom moter that it run at 3.3V or maximum 5v but your vcc for gate driver is >12V.
Yes, honeslty i do not investigate the working voltage for a CDROM motor, cause it's just for a testing environment. What i can say is that it works at 12V without too much overheat.
DeleteDear sir, im interesting to try this awesome project but theres no hex file code on article, may u kind send me please, thanks in advance for ur kindness hope u stay fine keep inspiring Cheerss..
ReplyDeleteok this what i did, ive dowload the avr_lib_bldc02-board1sensorless_02.zip - extract it - open extratced folder n found main.c - than open browser - drag+drop main.c to browser n main.c readed as text - than open this web https://www.online-toolz.com/tools/text-hex-convertor.php - corverted to hex - copy her result to notepad+ - than save as "intel hexadecimal" option than it gave me a *hex extension file.. Q/a is this ok upload it via Avrdudes.. ?
DeleteHello, I suggest you to compile you code. Anyway you can find the hex here (available for 6 days): https://filebin.net/b7rzefj6ok91gcz4
Delete"ok this what i did, ive dowload the avr_lib_bldc02-board1sensorless_02.zip - extract it - open extratced folder n "... not the right way. You have to Compile it. There are a lot of tutorial online on how to compile avr-gcc, you can check it. I think the simple IDE is Eclipse IDE with AVR plug (you can search online for tutorials). A good place to ask is https://www.avrfreaks.net/ forum. Hope this helps.
DeleteOk Thanks a lot Sir.. for ur the time n kindness..
DeleteSir Davide.. i've made this "sensorless" on breadboard
Deletehttps://www.youtube.com/watch?v=_gND47W_EAU
but would u kind to send me "sensored hex" code framework id like to learn try sensored one thankss.. sir Davide..
Hello, good project board. Find it here: https://file.io/hFOi1c96L7jL (look at the Release folder of the project you need). Good job.
DeleteThanks alot sir for your nice guide n dedication..
DeleteThis comment has been removed by the author.
ReplyDeletecan your configuration be used to run a BLdc drone motor??
ReplyDeleteHello, it should. But I'd rather use SimonK or BLHeli firmware, that is made just for doing that.
Delete