Brushless motor algorithm

I've been trying to build a sensorless brushless speed controller using some mosfets and an arduino, and I've been able to run the motor 'blindly' using a preset delay. My problem is, I don't quite know how to switch over to a closed loop control using the back EMF from the undriven coil of the motor - does anybody have an idea as to how I might go about writing an algorithm for this?

I've been following this guide, but it doesn't have any source code: http://www.digikey.com/en-US/articles/techzone/2013/jun/controlling-sensorless-bldc-motors-via-back-emf

When I connect the comparator to the undriven coil and print out its reading to the serial monitor, I get a pattern of alternating 1s and 0s(10101010101010...) - is this the expected signal? How would I use this to decide when to commutate the motor?

Thanks in advance for any help!

what do you mean by "the undriven coil" ?

At any one time, you drive the current into one coil and out of the other, leaving the third one floating - you measure the back emf on this coil to determine the rotor's position.

michinyon: what do you mean by "the undriven coil" ?

If you know anything about driving BLDCs with trapezoidal mode this is obvious. If you don't know such things, why try and contribute to answering this query?

The first thing to say to the OP is "post your code and schematic". You'lll probably need to set the analog clock to run faster so you can monitor the idle phase rapidly and spot the cross-over point. If you are using PWM then there will be noise and this may require some carefully chosen low-pass filtering.

You mentioned a comparator - there needs to be 3 comparators, one for each phase, or a summing circuit to average the 3 phases (since two are known) and share the comparator.

Code and schematic please...

Hi, sorry for the late reply, I've had tons of schoolwork.

My schematic for the power stages is this: http://i.imgur.com/rEn2Evr.png

For the comparator, I have 3 set up like this: http://www.digikey.com/~/media/Images/Article%20Library/TechZone%20Articles/2013/June/Controlling%20Sensorless%20BLDC%20Motors%20via%20Back%20EMF/article-2013june-controlling-sensorless-BLDC-motors-fig4b.jpg

As for code, I don't have any beyond just a blind startup of the motor. This is where I need help - how do I use the comparator waveform to decide when to commutate?

As a side note, my circuit draws insane current (3A @6V) - any idea why? When I use a store bought ESC, I only draw about 0.5A, even though I'm running it faster.

At one time Atmel had several application notes documents available on their web site on interfacing/driving DC brushless motors, both sensored and sensorless. The ATmega8 chip is/was one of the most common uC chips used in this kind of application.