Multiple PWM output pins

Hey everyone,
I’m trying to control 4 motors with the 4 PWM Output Pins on the FEZ Panda II. I read here somewhere that you can use all pwm Pins at the same time but only with the same frequency. My problem is that I can only control one pin at the same time. I have already tried to initialize all 4 of them without any Problem. But when I call the first pwm.set methode the other pwm ports don’t react anymore. Even with the same frequency. Is there a trick or something I do wrong?

Thank you in advance

Can you show some code?

Welcome to the community.

Sorry I haven`t been on my computer the last couple days.
This is the code I use at the moment. I can control every individual pwm pin this way. But not all of them at the same time.

static PWM pwm1 = new PWM(PWM.Pin.PWM1);
        static PWM pwm2 = new PWM(PWM.Pin.PWM2);
        static PWM pwm3 = new PWM(PWM.Pin.PWM3);
        static PWM pwm4 = new PWM(PWM.Pin.PWM6);

        const uint PWM_MIN = 1000000;   // 1ms
        const uint PWM_MAX = 2000000;   // 2ms
        const uint PWM_FRQ = 2500000;   // 400Hz 

        public static void Main()
        {

            pwm1.SetPulse(PWM_FRQ, PWM_MIN);
            pwm2.SetPulse(PWM_FRQ, PWM_MIN);
            pwm3.SetPulse(PWM_FRQ, PWM_MIN);
            pwm4.SetPulse(PWM_FRQ, PWM_MIN);
}

can you show us what works and what fails? How did you check that the pins were working? I suspect you are using servos, can you try connecting the same servo to all pins individually and see if the pins are operating?

I have connected all four pwm pins to the ESC of my quadrocopter. When I comment out any three of the four SetPulse methods from the code above one pwm pin works. But as soon as I call more then one SetPulse methods (e.g. pwm1.SetPulse and pwm2.SetPulse) only the first pin (pwm1) will have a signal. I have checked the pins with the ESC and with an oscilloscope. Looks like only one pwm pin works at a time.

OK, thanks for explaining, but no I don’t think this is the correct behaviour. There’s something else going on.

Can you please try some combinations now?

First, confirm each works individually by only including one SetPulse command for different Pins and confirm your ESC will work.

Then, please try by including two pins, and re-order the SetPulse statements, see what happens when you SetPulse for Pin2 before Pin1. In the meantime I’ll see if I can repro this (although I don’t have an ESC or servo close by I can try it on).

Also, can you please check your SDK installs? Please report back what Device Capabilities shows from MFDeploy, and please confirm what SDK you have installed (check the release notes in something like C:\Program Files (x86)\GHI Electronics\GHI NETMF v4.1 SDK… Mine shows USBizi (FEZ Mini, FEZ Domino, FEZ Rhino, FEZ Panda) V 4.1.8.0)

OK, test done. Two different servos, connected to Di10 and Di6 (PWM1 and PWM6 respectively).


using System;
using System.Threading;

using Microsoft.SPOT;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;


namespace Pan2_pwmtest
{
    public class Program
    {

        static PWM pwm1 = new PWM(PWM.Pin.PWM1);
        static PWM pwm2 = new PWM(PWM.Pin.PWM2);
        static PWM pwm3 = new PWM(PWM.Pin.PWM3);
        static PWM pwm4 = new PWM(PWM.Pin.PWM6);

        const uint PWM_MIN = 1000000;   // 1ms
        const uint PWM_MAX = 2000000;   // 2ms
        const uint PWM_IDLE = 1400000;   // 1.5ms
        const uint PWM_ADJ = 250000;
        const uint PWM_FRQ = 2500000;   // 400Hz 

        public static void Main()
        {
            Debug.Print("Starting");
            Thread.Sleep(3000);
            pwm1.SetPulse(PWM_FRQ, PWM_IDLE);
            //pwm2.SetPulse(PWM_FRQ, PWM_IDLE);
            //pwm3.SetPulse(PWM_FRQ, PWM_IDLE);
            pwm4.SetPulse(PWM_FRQ, PWM_IDLE);
            Thread.Sleep(3000);
            pwm1.SetPulse(PWM_FRQ, PWM_IDLE - PWM_ADJ);
            pwm4.SetPulse(PWM_FRQ, PWM_IDLE + PWM_ADJ);
            Thread.Sleep(3000);
            pwm1.SetPulse(PWM_FRQ, PWM_IDLE + PWM_ADJ);
            pwm4.SetPulse(PWM_FRQ, PWM_IDLE - PWM_ADJ);
            Thread.Sleep(3000);
            pwm1.SetPulse(PWM_FRQ, PWM_IDLE);
            Thread.Sleep(3000);
            pwm1.Set(false);
            pwm4.Set(false);
            Debug.Print("Ending");
            Thread.Sleep(Timeout.Infinite);
        }

    }
}


I can confirm that my Panda2 works as expected. With this program the two servos turn in different directions as expected.

1 Like

Hey Brett,
thank you for helping me out. Looks like I messed something up. I programmed everything again and updated the firmware to have factory settings. Now it seems to work. Thank you again. I thought my pwm pins were broken.

Hi, i’m just starting to program, i just get a FEZ Panda II and i want to learn how to make PWM ports work, i’ve been trying with some codes that i found in the forum but i can’t make it works, i can’t even setup a PWM port, i got an error that PWM could not be found, maybe a missing assembly reference

I’m using Visual Studio 2013 with .NET MF V4.1, but i had previously installed the 2014 R1 version , also i’m using the next references

using System;
using System.Threading;

using Microsoft.SPOT;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;

Please help to start with this, Thanks in advance

Hey Sergioaas, welcome to the forum.

I don’t think you can use VS2013 yet.

To use VS2012 you’d need to install VS2012, then netmf 4.3 RTM SDK, then GHI 2014 R1 package, then the 4.1 GHI SDK. That way you know the combination works.

Then you need to start a new console application, target the correct 4.1 framework version, and add references and USING statements.