FRDM-K64 PWM basic example using mbed

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FRDM-K64 PWM basic example using mbed

FRDM-K64 PWM basic example using mbed

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;

        }

    }

}

Attachments
%3CLINGO-SUB%20id%3D%22lingo-sub-1113600%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EFRDM-K64%20PWM%20basic%20example%20using%20mbed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1113600%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHere%20you%20can%20find%20both%20the%20code%20and%20project%20files%20for%20the%20PWM%20project%2C%20in%20this%20example%20a%20single%20PWM%20channel%20belonging%20to%20the%20Flextimer%200%20(PTC10%2FFTM_CH12)%20is%20enabled%20to%20provide%20a%20PWM%20signal%20with%20a%20500ms%20period%2C%20the%20signal's%20duty%20cycle%20increases%20its%20period%20every%20100ms%2C%20to%20visually%20observe%20the%20signal%20connect%20a%20led%20from%20the%20A5%20pin%20in%20the%20J4%20connector%20to%20GND%20(J3%2C%20pin%2014).%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3ECode%3A%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%23include%20%22mbed.h%22%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%2F%2FPWM%20output%20channel%3C%2FP%3E%3CP%3EPwmOut%20PWM1(A5)%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3Eint%20main()%20%3C%2FP%3E%3CP%3E%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20PWM1.period_ms(500)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20int%20x%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20x%3D1%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20while(1)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20PWM1.pulsewidth_ms(x)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20x%3Dx%2B1%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wait(.1)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if(x%3D%3D500)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20x%3D1%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1113600%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EFreedom%20Development%20Platform%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EKinetis%20K%20Series%20MCUs%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
No ratings
Version history
Last update:
‎06-27-2014 11:04 AM
Updated by: