DIY controller 48V/1000W with bluetooth Atmega328PB

cyclelife

100 µW
Joined
Sep 2, 2015
Messages
9
Location
Europe
A bit a learning experience I have started working on a controller two years ago. Target is a mostly road legal bike for Europe, i.e. with speed limit, power limit and pedal sensor.

Main features are:

  • 48V / 1000W
    based on Atmega 328 microcontroller ("Arduino")
    block or sinus + eventually sensorless commutation
    regenerative braking
    60V-> 12V DC/DC converter with 7.2W output, thus around 5W for light or smartphone
    bluetooth 4.0
    android app for configuration and logging
    open hardware and potentially open software
    size 60mmx100mm

Simplicity and clean layout are key as the main ideas are to have it robust and repairable.

I have done a few revisions already and it is working flawlessly since several thousand kilometers.
 

Attachments

  • bldc-test-rig.jpg
    bldc-test-rig.jpg
    94.7 KB · Views: 3,259
Groovy, Marcus. BTW? In English we tap more about "regen" as in regenerative braking rather than "recovery braking". :wink:
 
Thanks LockH, fixed that with the regen. Being german I had "recuperation" in my head and I know that that is definitely wrong. Either way it is a key feature for me as there are mountains everywhere here. The controller can be set to the KV of the motor in order to avoid drag when just normally cycling without assist. I use a semi race bike and go often up into the mountains.

The controller uses IR2104 chips which limits the maximum gate charge to roughly 100nC at 10V otherwise it wont be fast enough switching. That is still good enough to drive MOSFETs with 3-5mOhm Rdson. Currently I am running the controller with up to 500W without the MOSFETs being mounted on a heat sink or the enclosure. So there is still plenty of headroom.
 

Attachments

  • bike-hd.jpg
    bike-hd.jpg
    94.8 KB · Views: 2,610
Alan B said:
Curious why you picked that variant, there are some that have motor control output stages.

I just happen to know the Atmega microcontrollers. Also they are robust and with about $1.50 per piece not very expensive. You can't do FOC with them but you can do block and sinus. I currently run the controller with block commutation and hall sensors. The main loop of the firmware runs still 5000 times per second while handling the motor control and bluetooth communication and the firmware is only 7KB and uses less than 1 KB RAM.

I also made a version with an Atmega644. Basically the same chip but more pins. The idea was to add a barometric sensor, an accelerometer and an air quality sensor. But then you really come to the limits of the computing power of the chip.

Attached is a screenshot of the android app, with a big font for good readability in sunlight. It can also display Wh/km and motor amps.
 

Attachments

  • Screenshot_2017-06-10-23-23-04.png
    Screenshot_2017-06-10-23-23-04.png
    15.3 KB · Views: 3,226
Very nice.

I like the Atmel AVRs also, have been using them since before Arduino.

The ATMega32M1 has better motor PWM, they have a 64M1 also with more flash, and may even be able to do FOC. They have good motor control PWMs in a power stage controller and can react in hardware to fault conditions. They are made for automotive motor control applications such as BLDC window motors.
 
I didn't know the 32M1 nor did I know about the power stage control unit. What set me onto the track of the Atmega8 family were existing designs. All the cheap ESCs from Hobbyking for quadcopters use Atmega8 chips. They have much higher RPMs than a ebike motor thus I assumed they are definitely capable to run the latter.

Then there is the mikrocopter ESC design which in fact is using only PWM channel. And there are app notes AN-444 and AN-447 from Atmel with source code for block and sinus commutation. So it seemed kind of a safe bet.

After reading a bit the data sheet of the 32M1 I have to admit that the PSC is very convenient. I assume FOC would need lots of assembly trickery - probably not worth the effort.
 
They do have libraries for a lot of things, not sure about FOC for the M1. The AVR series was designed for compiler use, so not a lot of advantage to assembly language, but it is a small processor for FOC. There are app notes for FOC on some AVRs, so it must be possible. The hardware helps, too.

I bought a couple of the chips, did some paper designs, but haven't played with them.

One of these days when I have more time, perhaps. :)

Anyway, good on getting some AVR stuff working. The AVR is a good part to work with, and is very efficient with C.
 
Attached is the schematics file.

The half bridge drivers are IR2104 with a fixed dead time of 520ns and around 200mA gate current. The design has no shunt but uses an ACS712 for current sensing on the low side. It can measure both positive and negative currents.

The DC converter is a Texas Instruments LMR16006Y doing the 60V -> 12V.
 

Attachments

  • bldc.pdf
    144.2 KB · Views: 214
cyclelife said:
A bit a learning experience I have started working on a controller two years ago. Target is a mostly road legal bike for Europe, i.e. with speed limit, power limit and pedal sensor.
Great!! Is that OpenSource? if so, where can I get the sources??

I took a different approach, a very cheap and widely available chinese motor controller that is firmware programmable with a STM8 that is 8bits and running at 16MHz, using OpenSource tools and compiler: https://opensourceebikefirmware.bitbucket.io/About_the_project.html
 
Alan B said:
I bought a couple of the chips, did some paper designs, but haven't played with them.
This is my first project using KiCAD. After getting used to the few quirks it has it has become reasonably fast for me to create a PCB. In the US you have oshpark to get prototype PCBs for little money. I use a mixture of European and Chinese manufacturers.

One thing I like on KiCAD is the fact that the file format is xml and thus can be checked in into git while getting sensible diffs. With Eagle's binary blobs there is no point of using a source code management system.

casainho said:
I took a different approach, a very cheap and widely available chinese motor controller that is firmware programmable with a STM8 that is 8bits and running at 16MHz, using OpenSource tools and compiler
That's a cool project! My personal aim was also to learn about the BLDC hardware. I had a mostly unused oscilloscope sitting on my desk and thought this would be a good opportunity to make use of it. And indeed it has been indispensable.

I still need to clean up my code before putting it anywhere up on github. We'll see.
 
casainho said:
I took a different approach, a very cheap and widely available chinese motor controller that is firmware programmable with a STM8 that is 8bits and running at 16MHz, using OpenSource tools and compiler
That's a cool project! My personal aim was also to learn about the BLDC hardware. I had a mostly unused oscilloscope sitting on my desk and thought this would be a good opportunity to make use of it. And indeed it has been indispensable.[/quote]
You are welcome to join the project. The hardware is dirty cheap. And we are using OpenSource tools.
 
It's been a while since the last update - mostly I have been happily cycling.

The controller has now been running with up to 1000W @ 48V and I also made a second version with better MOSFETs which does up to 2000W peak. As I usually use a road bike this is more than plenty!

I've made a first batch for friends and family:
0prototype.jpg

And I have ran my personal challenge of going from Nice up to the Col de la Bonette (2800m/9200ft) and back in one day. The return trip is 240km/150miles and I wanted to do it with one 48V/11.6Ah battery.

0summit.jpg

The output from the app can be seen here:
http://cyclehikemap.eu/mymaps/view.php?id=73
http://cyclehikemap.eu/mymaps/view.php?id=72
http://cyclehikemap.eu/mymaps/view.php?id=71
And the return:
http://cyclehikemap.eu/mymaps/view.php?id=70

The website still needs a bit more love but overall I couldn't be happier with the controller & motor combo. There is nothing that beats a silent running direct drive motor with sinus control. :D

Am currently checking with seeedstudio to produce a few more PCBs. Their website is a bit buggy, it told me that one prototype will cost $723. :shock: I kicked them an email, so we'll see what comes out of it...
 
Good!! So, are you sharing the sources or not??

Is that sinewave or/and FOC?
 
casainho said:
Is that sinewave or/and FOC?
Currently it is sinewave and switches to block at higher speeds for more torque.

My direct drive is a 154mm with 18 stator poles and it runs absolutely silent.
So far my ebike life was only with block controllers, thus this was a revelation. It really gives a totally new feeling to the bike.

Also I can now sneak up silently behind bio-bikers. :D
Just that there is no misunderstanding, I get well along with them and occasionally I cycle without motor.

For the code, I'll put up some code the next days to github.
 
What is the max eRPM you are running? what is the PWM frequency??

I implemented very low resolution FOC on the STM8 8 bits 16MHz microcontroller, maybe you are interested to look at it: https://opensourceebikefirmware.bitbucket.io/Various--Endless-sphere.com_forum_messages--2017.09.02_-_How_to_do_FOC_on_the_BMSBattery_S06S-Kunteng_STM8_motor_controllers.html

What was the cost of one unit of the controllers you show on the picture? what was the price of assembling?
 
cyclelife said:
casainho said:
Is that sinewave or/and FOC?
Currently it is sinewave and switches to block at higher speeds for more torque.
Which form of sinewave? SVM?? because I think with SVM you get 1.15x the battery voltage on the motor terminals and so you should get higher speed (??).

The maximum voltage is increased by 15%. Under sinusoidal PWM modulation, the maximum line-to-line voltage is equal to sqrt(3)/2*Vdc, whereas under SVM, the maximum is Vdc. 1/(sqrt(3)/2) = 1.15.
 
Have you uploaded the code files on github ? Can you please share the link
 
Back
Top