AnsweredAssumed Answered

Creat a PWM Signal

Question asked by Pascal Schroeer on Apr 12, 2014
Latest reply on Apr 15, 2014 by Pascal Schroeer

Hi, I hope anyone can help me....

 

First of all my facts:

I'm using CW V.1.4 (without PEX), to program a MK20DX128 (50MHz)

 

I would like to generate a PWM signal with selectable period and duty cycle. I thought it would

be very easy, so i did it like described in the datasheet:


PERIOD = (MOD-CNTIN+0x0001)


DUTY CYCLE = (CnV-CNTIN)


void PWM_init(void)

{

      FTM0_C1SC  = 0x00                                         /* Clear the FTM0_C1SC register */

                       | FTM_CnSC_MSB_MASK                /* Used for further selections in the channel logic */

                       | FTM_CnSC_ELSB_MASK               /* Edge or Level Select */

                       | FTM_CnSC_ELSA_MASK;              /* Edge or Level Select */

     

      FTM0_SC = 0x00                                              /*  Clear the FTM0_SC register */

                  |FTM_SC_CLKS(0x01);                         /* Selects the System clock */

     

      FTM0_CNTIN = FTM_CNTIN_INIT(0x0000);        /* Initialisation value */

     

      FTM0_CNT = FTM_CNT_COUNT(0x0000);          /* Set counter register */

     

      FTM0_MOD = FTM_MOD_MOD(0x0000);           /* Set up modulo register */

        

      FTM0_C1V = FTM_CnV_VAL(0x8000);              /* Set up the duty cycle */  

}

 

In this case the duty cycle is 50% how expected... but there isn't any change when I change CNTIN_INIT....

were is my fault here?

 

The next point is, when I would like to change the Period and change the mod register there isn't a PWM Signal anymore.

 

 

Hope anyone can help me

 

regards

 

 

 


Outcomes