Cerbuino Bee PWM LEDs Don't Work

I’m testing my LED Cobra/EMX code on a Cerbuino Bee and I can’t get the PWM LED functions to work. I’m using the built-in LED (LED1/PB2) and a LED7R module connected to PB1. I can light up the LEDs with standard Output but the PWM doesn’t work. Do these LEDs not support PWM or am I missing something? Here is my code:


        const Cpu.PWMChannel A0 = (Cpu.PWMChannel)5; // PB1 connected to LED7R Led

        // This works
        OutputPort LedOutput = new OutputPort((Cpu.Pin)GHI.Hardware.FEZCerb.Pin.PB1, true);
        LedOutput.Write(false);

        // This does not work
        PWM LedPWM = new PWM(A0, 10000, 100, false);
        LedPWM.Duration = 1000;
        LedPWM.Start();

Also, the built-in LED PB2 doesn’t seem to have a corresponding PWM pin. Is this correct?

Thanks.

any chance you could define “doesn’t work”?

Take a look at cerbuino mainboard class. It shows which pins are PWM capable and what PWM channel they correspond to.

http://gadgeteer.codeplex.com/SourceControl/latest#Main/Mainboards/GHIElectronics/FEZCerbuinoBee/Software/FEZ Cerbuino Bee/FEZ Cerbuino Bee_42/FEZ_Cerbuino_Bee_42.cs

Using Output, I can turn on and off the LED. Using PWM nothing happens, the LED remains off.

[quote=“Architect”]
Take a look at cerbuino mainboard class. It shows which pins are PWM capable and what PWM channel they correspond to.[/quote]

I’ve been referring to these pages which shows PWM 5 associated with PB1.

https://www.ghielectronics.com/docs/46/cerb-family

https://www.ghielectronics.com/docs/45/fez-cerbuino-bee-developer#396

I actually have 2 LEDs wired up, the other one is on PB0. Just for fun I ran the following code and still no LEDs lit up.


            for (int pin = 0; pin < 15; pin++)
            {
                led = new PWM((Cpu.PWMChannel)pin, 10000, 100, false);
                led.Duration = 1000;
                led.Start();
            }

I’m thinking that maybe the LED7R module is not wired up to use PWM. Plus the on-board LED is wired to PB2 and I can’t find any association of PB2 to a PWM pin.

@ SkierHiker - The overload of the PWM constructor you are calling is expecting the frequency in Hz and the duty cycle as a double between 0 and 1. Try the following


PWM LedPWM = new PWM(A0, 5, 0.5, false);
LedPWM.Start();

Which has a frequency of 5 Hz and 50% duty cycle (On half the time and off the other half).

If you want to use microseconds you can use the alternate constructor, the following is the same as the previous example.


PWM LedPWM = new PWM(A0, 200000, 100000, PWM.ScaleFactor.Microseconds, false); 
LedPWM.Start();

1 Like

So what you mean is that using PWM, you can’t get the intensity to change as you change the PWM parameters?

The docs you point to says what the PWM channel mapping should be:

(from Cerb family) PWM channels: The order of PWM channels is PC6,PA7,PC7,PA8,PB0,PB1,PB5,PB4,PB3,PB11,PB10,PA10,PA9,PA15, PB8, PB9

(from Cerbuino)

 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;

             }

And from the mainboard Socket 1:

 = FEZCerb_Pins.PB5;
			socket.CpuPins[8] = FEZCerb_Pins.PB4;
			socket.CpuPins[9] = FEZCerb_Pins.PB3;
			//P
			socket.PWM7 = Cpu.PWMChannel.PWM_6;
			socket.PWM8 = Cpu.PWMChannel.PWM_7;
			socket.PWM9 = (Cpu.PWMChannel)8;

Mainboard Socket 3:

 = FEZCerb_Pins.PB8;
			socket.CpuPins[8] = FEZCerb_Pins.PA7;
			socket.CpuPins[9] = FEZCerb_Pins.PB9;
			// P
			socket.PWM7 = (Cpu.PWMChannel)14;
			socket.PWM8 = Cpu.PWMChannel.PWM_1;
			socket.PWM9 = (Cpu.PWMChannel)15;


So between all of those you should have the detail you need? Also why don’t you try 50% duty cycle then the invert won’t cause you a problem if that’s actually needed (I don’t have a cerb to try any of this on) Edit: while collecting references and info Taylorza comes along and completes that task quicker than me :slight_smile:

That was it. My original code was from MF 4.1 and I converted it as is without realizing that the new PWM values were a factor of the old ones.

Thanks guys.

Still curious though if the on-board LED, PB2, can be PWM’ed. From what I can tell it can’t.

@ SkierHiker - I have not checked the Datasheet, but based on the constants defined by GHI it does not appear that PB2 is connected to the PWM peripheral.

Agreed, nothing in the doco implies PB2 is on a PWM, sorry. Plus, if you’re using a Gadgeteer app, the mainboard object takes over that LED anyhow and all you can do is set it on/off/pulse it.