Use FEZ Spider to control a ESC for a brushless motor

Hi all,
I’ve just started looking into what would be involved in building a quad copter using the FEZ Spider. But for the life of me I can find any references on how to connect 4 Brushless ESCs up.

I have found a few examples of drivers but no information on how to actually connect them to the spider.

Any help would be appreciated.

There’s currently not a native module for this, so you’ll need an Extender module. Here’s the basics using standard NETMF but it’s just a matter of setting the pins correctly from the Extender to make it work.

Welcome to the community!

Thanks for that.Hopefully this should keep me out of trouble for a while.

I’ve had a look at the FEZ Spider and it states that it supports 6 PWMs (which I presume I need 4 to be able to control 4 separate ESCs), but they all appear to located on two sockets (8 & 11, with 3 on each).

What I am now trying to understand is where and how I connect 4 PWM connections two on each port?

Are their particular pins I should use or could I use any (e.g. would pins 1, 2 & 3 from each socket be fine)?

Thanks Coop

Did you look at this it explains the pins a bit

No I hadn’t seen that one yet.
7, 8 & 9 it is then.
Thanks heaps.

It doesn’t matter which PWM pins you use. For simplicity, I’d use all four from a single socket so you only need one Extender module.

Definitely keep the chart swestcott referenced in you back pocket. You’ll use it often with Gadgeteer.

Is there any benefit of using the pins that are assigned PWM? As it just seems a bit strange that these pins are marked that way but any could do the job. Also does this also mean I could use any socket on the board to connect my extender to and use PWM?

Sorry for all the questions, I just want to make sure that I’m doing this correctly and don’t end up with extra hardware or worse fried hardware, lol.

Thanks again.

Only P sockets have PWM pins. You could also use any X or Y socket with any digital IO pin if you use OutputCompare to generate the PWM.

There are 6 hardware PWM channels on the Spider, pins 7,8 & 9 on sockets 8 & 11

That should keep me out of trouble for while.
Btw, could anyone refer a good site to get header pins and cables to suit the extender modules?
Thanks heaps.

For the pins, I use these to connect it to a breadboard:

You can get the cables from GHI:

I come from the Domino world (not that I am an expert by any means)… so this is an intelligence gathering question for me:

[quote]Only P sockets have PWM pins. You could also use any X or Y socket with any digital IO pin if you use OutputCompare to generate the PWM.

Could he just use a single (both 8 & 11 are shown on the illustration as P, U & Y) socket – using hardware 3x PWM & 1x Output compare?

Or is there a practical difference between hardware/software PWM?
Would the Output compare be able to be easily and accurately “synced” up with the a hardware PWM?


He absolutely could. Only benefit is that you offload some CPU cycles if you use the hardware PWM. Syncing isn’t really an issue since he’ll be controlling the motors individually anyway.

Thanks ian!

Hey guys,
thanks for that useful answers :slight_smile:

However I’m having problems with the OutputCompare, combined with the brushless motor controller from this source

With PWM the SetPower function looks like this:

/// <summary>
        /// Sets the outputpower, from 0 to "Scale"
        /// </summary>
        /// <param name="power">0..."Scale"</param>
        public void SetPower(int power)
            uint highTime = (uint)(Min + (Precalc * Constrain(power, 0, (int) _scale)));
            this._pwmPin.SetPulse(Period, highTime);

As there are only 3 PWM’s on one P-socket, and I need 4, I decided to use an Output-Compare so I don’t have to connect another extender module.
I wrote a small wrapper class for the OutputCompare based on the wiki entry GHI Electronics – Where Hardware Meets Software (Section "Include PWM signal) , but the motor just beeps and doesn’t rotate…
The original code works fine with PWM pins.

That’s the class:

class BrushlessMotorOutputCompare : OutputCompare, IBrushlessMotorInterface
        static uint[] timings = new uint[2];

        public BrushlessMotorOutputCompare(Microsoft.SPOT.Hardware.Cpu.Pin pin) : base(pin, false, timings.Length)

        public static BrushlessMotorOutputCompare Create(int extenderSocket, Gadgeteer.Socket.Pin pin)
            Gadgeteer.Socket socket = Gadgeteer.Socket.GetSocket(extenderSocket, true, null, null);
            return new BrushlessMotorInterfaceOutputCompare(  socket.ReservePin(pin, null));

        void IBrushlessMotorInterface.SetPulse(uint period, uint highTime)
            //from wiki
            //public static void Set(int frequency, byte dutyCycle)


                //to make sure period time is microsecond

                //uint period = ((uint)(1000000000 / frequency))/1000; 

                //uint highTime = (period * dutyCycle) / 100;

                timings[0] = period - highTime; ;

                timings[1] = highTime;

                base.Set(true, timings, 0, timings.Length, true); 


That’s the adapted SetPower function:

/// <summary>
        /// Sets the outputpower, from 0 to "Scale"
        /// </summary>
        /// <param name="power">0..."Scale"</param>
        public void SetPowerOutputCompare(int power)
            uint highTime = (uint)(Min + (Precalc * Constrain(power, 0, (int) _scale)));
            this._outputComparePin.SetPulse(Period, highTime);

Thanks for help :slight_smile:

@ CokeViper - I appologize for such a long delay in getting back to this. I’m catching up… Try this as your BrushlessMotorOutputCompare.SetPulse()

    public void SetPulse(uint period, uint highTime)
        timings[0] = highTime / 1000;
        timings[1] = (period - highTime)/1000; ;
        base.Set(true, timings, 0, timings.Length, true);