Go Down

### Topic: Is arduino fast enough to handle brushless motors commutation?! (Read 8638 times)previous topic - next topic

#### Ludo91

##### Mar 27, 2011, 10:57 pm
Hi guys!
I`m making a BLDC motor controller and I am thinking about using Arduino to control it.
It` s very simple, depending on the digital input from 3+1 sensor it has to properly control 6 mosfets. (reads the gas potentiometer once in a while and then applies a pwm signal to 6 mosfets, depending on the readings of 3 hall sensors. Very simple process, based on a Boolean logic that relates hall imputs to phase commutations.)

The question is: Is arduino fast enough for that?!
The motor will be spinning at max 5000 rpm, wich is about 85 rpSecond.
Each mecahnical  rotation is made of 4 electrical rotation, and each rotation is made of 6 state changes. (each state change is the change of TWO pwm output status)

So, 24 commutations * 85 revolutions is 2040 operations per second. Is Arduino with its 16000000 Hertz able to handle that?

A quick math says it has something like 7500 clock cycles for each commutation, but in order not to loose sync the delay of each commutation should not be over let`s say 3%...
That means not over 250 clock cycle to read 3 digital sensor status, perform a supereasy boolean thing and set two pwm write. Can Arduino handle that?

Thankyou so much!  ^_^

#### MarkT

#1
##### Mar 28, 2011, 12:19 am
Yes, shouldn't be a problem.   You will however, I think, need to up the PWM frequency to higher than the commutation speed to get reasonable behaviour.  The default timer settings are about 1000Hz on timer0, 500Hz on timers 1 and 2.  Each timer controls two PWM pins - timer0 also maintains the millis() clock.  Timers have a prescaler that divides the system clock.  This can be set to divide by one, giving a maximum PWM frequency in 8 bit fast mode of  62.5kHz - plenty I think.

If you want to use all 6 pwm pins then that means you may have to give up on millis() being at all accurate - and learn how to directly set the timer prescaler settings.

[ If you want less delay in the system you can use direct access rather than digitalRead() and analagWrite() - at the expense of clarity.  It is possible to read a digital pin or set a PWM output value in a couple of cycles.... I think that  digitalRead and analogWrite are probably fast enough ]
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### westfw

#2
##### Mar 28, 2011, 06:32 am
Many of the "homebrew" Brushless motor controllers used in the RC hobby area use an ATmega8 CPU, which is the same CPU  used on the original Arduino (the newer CPUs are essentially the same speed, but have more program memory.)
(many commercial controllers use the same CPU, and there are assorted instructions out there for reprogramming some of the inexpensive imported ESCs with alternative software.)

#### MarkT

#3
##### Mar 28, 2011, 08:02 pm
And don't underestimate the important of monitoring current to such a low-resistance motor - overdrive it and it will take all the current you can throw at it till something melts...  RC brushless motors are typically 0.1 ohms or so winding resistance.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### bastukee

#4
##### Mar 28, 2011, 08:06 pm
No trees were harmed by the transmission of this message. However a few million electrons were temporarily inconvenienced.

#### Senso

#5
##### Mar 28, 2011, 08:22 pm
The C compiler might not be able to create code that fits in the 250 cycle space, because all the ESC's that have open source code are coded in assembly, also almost all ESC's use atmega8's as said and running at only 8Mhz using the internal oscillator, so 16Mhz is a lot more time.

#### Ludo91

#6
##### Mar 29, 2011, 06:20 pm
What about connecting the arduino pwms to the mosfet? I was thinking of useing a "pre-amp" stages made with transistor in order to keep the arduino away from the mosfets` gate saturation current (very high on 400A mosfets) and make a quicker switch. Am I on the right path?

In order to pick the right components i`ll refer to some datasheets and guides from national rectifiers and others.

I have some "ideal assembly" knowledge (part of a college exam), reading datasheets etc i may be able to write the code/part of it in assembler.
If needed i`ll get into it and, eventually, ask for help on the forum if i won't manage to figure it out myself

#### MarkT

#7
##### Mar 29, 2011, 06:28 pm
Typically a specialised driver chip(s) is needed - both to handle the high currents, boost the gate voltage to 10--12V and drive a charge pump to provide gate voltage for high-side n-channel MOSFETs.  IIRC one 3-phase driver chip is the HIP4086.

Be aware that high current MOSFET circuits are totally unforgiving of error - always limit the current during testing and development till you are sure all is well.  If you don't something will melt or explode.  Start with 100mA load, then 1A, then 5A, checking all the time for unexpected behaviour or overheating.

This is not an easy project.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### Senso

#8
##### Mar 29, 2011, 07:47 pm

The first two links have zip files and pdf files, they have both schematics and source code, there is also a fully designed i2c controled ESC based in a pic30f ou 33 dont remember correctly.

#### Ludo91

#9
##### Mar 29, 2011, 09:36 pm
tnks guys
Tnks for the link also, they refer to great technical works but are pretty different from my goal, I want to make a sensored controller to use on a ebike. I used to run it on a sensorless rc controller, it worked great but with the (big) limit that I had to run it at about 10mph before the back emf was strong enough to make a sensorless controller work.

Is there any ic that can help me connecting a logic pin (arduino output) to the mosfet gate?
I think I could solve this issue using logic level gate mosfets, but seems I`m wrong

#### bastukee

#10
##### Mar 29, 2011, 09:45 pm
Did you look at the data-sheet I posted?

Pin 1, 3 and 16 run the 3 phase and pin 17 does the sensing. Pin 4 can be used to control the outputs, Check Page 11.

No trees were harmed by the transmission of this message. However a few million electrons were temporarily inconvenienced.

#### Ludo91

#11
##### Mar 29, 2011, 11:32 pm
Yep I checked the datasheet and it`s for sensorless commutations, if fact it says something like "you`ll save 3 hall sensors with this lol".

I can already read the sensors and control some outputs on Ardu (in my automation engineering class in Italy we sometimes refer to it as God Ardu, who watches you  XD), my "only issues" were about speed of the whole system, seems there is enough, and how to connect the Ardu`s output to the mosfets.

Still, i don`t understant why logic level gate mosfets arent the right solution to "make it easy.. this is the datasheet of those i was looking at... http://www.irf.com/product-info/datasheets/data/irls3036-7ppbf.pdf

#### bastukee

#12
##### Mar 29, 2011, 11:39 pm
You will need to enlighten me because I'm lost here.

What is Pin 17 for? I have done both the sensing EMF from all 3 phases with a 10k resistor and also using the 4'th connector on the brushless DC motor on which cases it both uses sensing to decide the next step against it's internal EMF comparators. How is this none sensing?
No trees were harmed by the transmission of this message. However a few million electrons were temporarily inconvenienced.

#### Ludo91

#13
##### Mar 29, 2011, 11:52 pm
I don`t know, anyway looking with the search function in the datasheet I want able to find the word sensor without the word less near to it.
Of course, I may be wrong (and prabably I am!), but I am not really interested in understanding how that ic works, since my main point right now is to understand the principles of how to drive high power mosfets from Ardu and how to choose the mosfets (i can say that the thing about logic level gates in my last post is the main point for me right now). Anyway, thankyou for posting me that datasheet! :-)

#### Ludo91

#14
##### Mar 30, 2011, 03:36 pm

I can already read the sensors and control some outputs on Ardu (in my automation engineering class in Italy we sometimes refer to it as God Ardu, who watches you  XD), my "only issues" were about speed of the whole system, seems there is enough, and how to connect the Ardu`s output to the mosfets.