DIY controller 48V/1000W with bluetooth Atmega328PB

Electric Motors and Controllers
Post Reply
cyclelife
100 µW
100 µW
Posts: 9
Joined: Sep 02, 2015 4:11 am
Location: Europe

DIY controller 48V/1000W with bluetooth Atmega328PB

Post by cyclelife » Jun 10, 2017 9:39 am

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 atmega 328 test rig
bldc-test-rig.jpg (94.66 KiB) Viewed 676 times
Last edited by cyclelife on Jun 10, 2017 3:36 pm, edited 1 time in total.

User avatar
LockH
100 GW
100 GW
Posts: 12746
Joined: Jul 09, 2013 11:06 pm
Location: Ummm.. Started out in Victoria BC Canada, then started to move around... Oh oh.

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by LockH » Jun 10, 2017 3:27 pm

Groovy, Marcus. BTW? In English we tap more about "regen" as in regenerative braking rather than "recovery braking". :wink:
ES changed my life (for the waaaaay better).

Eff. June, 2014 Phoenix Ebike Promotions

(Current ride? High speed lawn chair.)
https://endless-sphere.com/forums/viewt ... =3&t=57408

Phoenix Ebike Promotions conversion kit (work in progress. More drink holders, etc etc)
https://endless-sphere.com/forums/viewt ... 15&t=60564

User avatar
Alan B
100 GW
100 GW
Posts: 7020
Joined: Sep 11, 2010 7:43 am
Location: San Francisco Bay Area, USA
Contact:

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by Alan B » Jun 10, 2017 3:52 pm

Nice Job!

Curious why you picked that variant, there are some that have motor control output stages.

cyclelife
100 µW
100 µW
Posts: 9
Joined: Sep 02, 2015 4:11 am
Location: Europe

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by cyclelife » Jun 10, 2017 4:03 pm

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.83 KiB) Viewed 31 times

cyclelife
100 µW
100 µW
Posts: 9
Joined: Sep 02, 2015 4:11 am
Location: Europe

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by cyclelife » Jun 10, 2017 4:30 pm

Alan B wrote: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 (33.75 KiB) Viewed 647 times

User avatar
Alan B
100 GW
100 GW
Posts: 7020
Joined: Sep 11, 2010 7:43 am
Location: San Francisco Bay Area, USA
Contact:

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by Alan B » Jun 10, 2017 5:20 pm

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.

cyclelife
100 µW
100 µW
Posts: 9
Joined: Sep 02, 2015 4:11 am
Location: Europe

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by cyclelife » Jun 10, 2017 6:38 pm

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.

User avatar
Alan B
100 GW
100 GW
Posts: 7020
Joined: Sep 11, 2010 7:43 am
Location: San Francisco Bay Area, USA
Contact:

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by Alan B » Jun 10, 2017 7:14 pm

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.

cyclelife
100 µW
100 µW
Posts: 9
Joined: Sep 02, 2015 4:11 am
Location: Europe

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by cyclelife » Jun 12, 2017 4:34 am

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.15 KiB) Downloaded 58 times

Njay
10 kW
10 kW
Posts: 871
Joined: Sep 09, 2010 10:43 am
Location: Portugal

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by Njay » Jun 12, 2017 1:18 pm

Very nice project, thumb's up :)

casainho
10 kW
10 kW
Posts: 937
Joined: Feb 14, 2011 2:43 pm

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by casainho » Jun 13, 2017 6:07 pm

cyclelife wrote: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.bitbuck ... oject.html
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

cyclelife
100 µW
100 µW
Posts: 9
Joined: Sep 02, 2015 4:11 am
Location: Europe

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by cyclelife » Jun 14, 2017 1:11 pm

Alan B wrote: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 wrote: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
10 kW
10 kW
Posts: 937
Joined: Feb 14, 2011 2:43 pm

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by casainho » Jun 14, 2017 1:36 pm

casainho wrote: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.
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

cyclelife
100 µW
100 µW
Posts: 9
Joined: Sep 02, 2015 4:11 am
Location: Europe

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by cyclelife » Sep 11, 2017 6:09 pm

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
0prototype.jpg (76.75 KiB) Viewed 311 times
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
0summit.jpg (80.1 KiB) Viewed 31 times
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...

casainho
10 kW
10 kW
Posts: 937
Joined: Feb 14, 2011 2:43 pm

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by casainho » Sep 12, 2017 3:21 am

Good!! So, are you sharing the sources or not??

Is that sinewave or/and FOC?
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

cyclelife
100 µW
100 µW
Posts: 9
Joined: Sep 02, 2015 4:11 am
Location: Europe

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by cyclelife » Sep 12, 2017 12:16 pm

casainho wrote: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.

casainho
10 kW
10 kW
Posts: 937
Joined: Feb 14, 2011 2:43 pm

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by casainho » Sep 12, 2017 7:21 pm

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.bitbuck ... llers.html

What was the cost of one unit of the controllers you show on the picture? what was the price of assembling?
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

casainho
10 kW
10 kW
Posts: 937
Joined: Feb 14, 2011 2:43 pm

Re: DIY controller 48V/1000W with bluetooth Atmega328PB

Post by casainho » Sep 12, 2017 8:05 pm

cyclelife wrote:
casainho wrote: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.
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

Post Reply