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?
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();
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
@ 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.