FRDM-K64 PWM basic example using mbed

Document created by Pedro Augusto Panecatl Salas Employee on Jun 27, 2014
Version 1Show Document
  • View in full screen mode

Here you can find both the code and project files for the PWM project, in this example a single PWM channel belonging to the Flextimer 0 (PTC10/FTM_CH12) is enabled to provide a PWM signal with a 500ms period, the signal's duty cycle increases its period every 100ms, to visually observe the signal connect a led from the A5 pin in the J4 connector to GND (J3, pin 14).

 

Code:

 

#include "mbed.h"

 

//PWM output channel

PwmOut PWM1(A5);

 

int main()

{

    PWM1.period_ms(500);

    int x;

    x=1;

   

    while(1)

    {

        PWM1.pulsewidth_ms(x);

        x=x+1;

        wait(.1);

        if(x==500)

        {

            x=1;

        }

    }

}

Outcomes