11 years, 7 months ago.

PwmOUT not working

Using the FRDM-KL25Z board.

Should the Green LED be flashing every 0.5s? Am I missing something?

It flashes once and then stops. I've put the code inside the while (1), and still nothing.

  1. include "mbed.h"
  2. include <PwmOut.h>

PwmOut greenLED(PTB19);

int main() {

greenLED.period_ms(1000); greenLED.pulsewidth_ms(500);

while(1) {}

}

1 Answer

11 years, 7 months ago.

Hey Mike

EDIT:

after looking in the mbed FRDM KL25Z introduction page, the pins that support PwmOut are (PTD4,PTA12,PTA4,PTA5,PTC8,and PTC9). and that's why your code is not working. try the code below

#include "mbed.h"
 
PwmOut led(PTD4); // or replace PTD4 with any of the above mentioned pins, or use the board's LED directly PwmOut  led(LED_GREEN)
 
int main() {

  led.period(1);
  led.pulsewidth_ms(500);
    while(1) {}
}

hope that helped

Accepted Answer

Thanks for the help. I thought the commands latched the period and duty cycle. In the KL25, setting the TPM registers once sets a PWM value until it is turned off. So this PwmOut commands are one shot only? Also, why the 50ms delay between commands?

posted by Mike Steffen 25 Apr 2013

Hey Mike,

Sorry, but it seems that i misread your code and thought that you're setting the pulsewidth twice with different values, but i fixed my post above please look at it.

posted by Karim Azzouz 25 Apr 2013

Hi Karim, Your code does not work on my FRDM-KL25Z board. I'll need to get this up to the admin of this site.

Mike

posted by Mike Steffen 25 Apr 2013

Hi Karim, Yes, now I see why it does not work. The PWM pinouts on mbed pinouts dioagram only support a limited number of PwmOut pins as you stated. However, as I'ved used this board outside of mbed, those LED pins are also on PWM channels, but they are just not available as PwmOut pins using the mbed tools. Thanks for catching that! Mike

posted by Mike Steffen 28 Apr 2013