Cerbuino PWM

I can happily get 6 PWM’s on the Bee working fine - D6,D9,D10,D11,D12,D13

On the schematics D5 is marked as PMW and FEZCerbuino.Pin.PWM.D5 exists as an enum but not go - am i being blonde or missing something as usual?

What firmware are you using and are you using a Gadgeteer project or a console project? To verify that FEZCerbuino.Pin.PWM.D5 works as expected, we performed a test with the current Beta 4.2.1.1 firmware in a console app and used this code and we are getting the proper square wave:


PWM PA8 = new PWM(FEZCerbuino.Pin.PWM.D5, 1000, 0.25, false);
PA8.Start();

@ Aron - Latest and greatest firmware Solution Build Info: 4.2.1.1, Copyright © GHI Electronics, LLC, so are there more than 6 PWM’s then?


using System.Threading;
using GHI.OSHW.Hardware;
using Microsoft.SPOT.Hardware;

namespace MFConsoleApplication2
{
    public class Program
    {
        public static void Main()
        {
            PWM servo = new PWM(FEZCerbuino.Pin.PWM.D5, 20000, 1500, PWM.ScaleFactor.Microseconds, false);

            uint maxClockwise = 1000;        
            uint maxCounterClockwise = 2000; 

            servo.Start();  

            while (true)
            {
                servo.Duration = map(0, 0, 180, maxClockwise, maxCounterClockwise);
                Thread.Sleep(2000);
                servo.Duration = map(180, 0, 180, maxClockwise, maxCounterClockwise);
                Thread.Sleep(2000);
            }
        }
        private static uint map(uint x, uint in_min, uint in_max, uint out_min, uint out_max)
        {
            return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
        }
    }
}

Actually, Yes, there are 16 PWM channels for the Cerb family and are as followed:


//                         C6,A7,C7,A8,B0,B1,B5,B4,B3,B11,B10,A10,A9,A15, B8, B9
 #define STM32F4_PWM_TIMER { 8,14, 8, 1, 3, 3, 3, 3, 2,  2,  2,  1, 1,  2,  4,  4}
 #define STM32F4_PWM_CHNL  { 0, 0, 1, 0, 2, 3, 1, 0, 1,  3,  2,  2, 1,  0,  2,  3}
 #define STM32F4_PWM_PINS  {38, 7,39, 8,16,17,21,20,19, 27, 26, 10, 9, 15, 24, 25}

As with the AnalogInput, the PWM channels are enumerated sequentially to the above layout where C6 is channel 0 and B9 is channel 15.

Here is the Cerbuino Pin out for PWM as per the GHI.OSHW.Hardware library file:


            /// <summary>
            /// Provides Channel definitions for FEZ Cerbuino's PWM capable pins.
            /// </summary>
            public class PWM
            {
                /// <summary>PWM Output</summary>
                public const Cpu.PWMChannel D5 = (Cpu.PWMChannel)3;

                /// <summary>PWM Output</summary>
                public const Cpu.PWMChannel A2 = (Cpu.PWMChannel)4;

                /// <summary>PWM Output</summary>
                public const Cpu.PWMChannel A0 = (Cpu.PWMChannel)5;

                /// <summary>PWM Output</summary>
                public const Cpu.PWMChannel D11 = (Cpu.PWMChannel)6;

                /// <summary>PWM Output</summary>
                public const Cpu.PWMChannel D12 = (Cpu.PWMChannel)7;

                /// <summary>PWM Output</summary>
                public const Cpu.PWMChannel D13 = (Cpu.PWMChannel)8;

                /// <summary>PWM Output</summary>
                public const Cpu.PWMChannel D0 = (Cpu.PWMChannel)9;

                /// <summary>PWM Output</summary>
                public const Cpu.PWMChannel D1 = (Cpu.PWMChannel)10;

                /// <summary>PWM Output</summary>
                public const Cpu.PWMChannel D6 = (Cpu.PWMChannel)11;

                /// <summary>PWM Output</summary>
                public const Cpu.PWMChannel D9 = (Cpu.PWMChannel)12;

                /// <summary>PWM Output</summary>
                public const Cpu.PWMChannel D10 = (Cpu.PWMChannel)13;

            }

I think Justin is talking specifically about the Cerbuino Bee. Is there a way to get to the others that aren’t exposed through the arduino pinout on that board? I think he would need to go to a Cerberus or Cerb40 to get up to 12. Is there a way to get at the other 4 from those boards?

No, actually Cerbuino has the most PWM with 14 channels while Cerberus only has 9. Socket 5 and 6 shares the same PWM outputs as they are multi-functional to Pins PB3, PB4, and PB5 with the SPI bus.

On Cerbuino, Channel 0 and Channel 2 are not available but channels 1, and 3 through 15 are totally available. The above Cerbuino pin out shows that channel 3 through 13 are on the Arduino-style Headers and Socket 1 has channels 14, 1, and 15 and Socket 3 has channels 6, 7, and 8.

This is good info to know! You should update the sales page for the Cerbuino. It gives no indication that you can get more than 6 PWMs from it.

@ Aron - Thanks for the info Aron.

so what is wrong with PWM servo = new PWM(FEZCerbuino.Pin.PWM.D5, 20000, 1500, PWM.ScaleFactor.Microseconds, false);

cause it no workie for me on the Bee.

@ ianlee74 - good point.

Do you have a scope to verify that nothing is working? Make sure that you have data pin connected to D5 and not perhaps on D4 or D6. I performed a test with your code and used a scope to verify the functionality of the D5 pin and I am getting the proper square wave, first 1.500 ms then it goes to 1.000 ms then 2.000 ms. Also is there possibly a problem with the Servo itself? Can you check to verify the servo is working?

@ Aron - the servo works fine on D6 D9 D10 D11 D12 and D13 - nothing on D5 - No scope in the office :frowning:

Do you have access to a scope at all to test the pin?

Will tomorrow - not sure that that will prove as the servo works fine on the other channels but i will happily be proved wrong.

It is not really to prove if the servo is working, it is more to verify if the pin is working. Do you have any ability where you are at to toggle the pin high to see if the pin is at least working as an output port, like maybe connecting an LED to the pin? If you can, you could maybe have the pin cycle through from a High duration to a Low duration to see if there is any activity on the pin with PWM.

@ Aron - D5 flashes a LED fine - the plot thickens…

@ Aron - Righto it appears socket D5 might be a little loose, after a few giggles it’s playing the game :slight_smile:

Sorry for the time wasting…

and thanks for the info and ideas… much appreciated.

Hi,
I’ve just received my first Cerbuino Bee, also my first GHI board (I have experience on Arduino and Netduino).
I’m a bit confused as all the documentation points to Cerberus documentation. I already found that they share the same firmware but I still have to figure out the differences.
At the moment, I don’t have any Gadgeteer modules, I’m more interested on the Arduino-style pins. How do I start a project? One thing I noticed is that Gadgeteer editor doesn’t have a Cerbuino main board in the toolbox.
Does the Cerbuino have I2C in the Arduino-style pins? (pins A4 and A5 in Arduino and Netduino).
Thanks,
aalmada

@ aalmada -

You will get a better responses if you post your question as a new thread.

@ aalmada - Welcome to the community and please start new thread next time as Mike suggested.

You need this page GHI Electronics – Where Hardware Meets Software