AnsweredAssumed Answered

FTM2 channel not delivering PWM

Question asked by Robin S on Oct 21, 2013
Latest reply on Oct 22, 2013 by Robin S

Hi Everybody,


i m new to the Freescale controllers.can you please see my code and tell me why FTM2 is not working ? FTM0 is working properly.


About code:


Just trying to generate Hardware PWM in all channels of   MC9S08RN16 µc.




#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */



// Prototype Function


void main(void);

void delay();

void PWMInit(unsigned int i);


void main(void) {


    unsigned int  Period;    

    unsigned int  Duty;      


    Period =0x120;    


    Duty = 0x90;   





  PORT_PTAOE =   0x03;                          /* Define PortA all Pin As Output  ; one is Output and Zero is Input for Data Direction */

  PORT_PTBOE =   0xFF;                          /* Define PortB all Pin As Output */





//  PORT_PTAD =  0x00;                           /* Initialise the PORTA */

//  PORT_PTBD =  0x00;                              /* Initialise The PORTB */




  /* the following code segment demonstrates setting ICS to FEI mode generating 20MHz bus*/


//  ICS_C1 = 0x04;                                 /* internal reference clock to FLL */

//  ICS_C2 = 0x00;

//  ICS_C3 = 0x00;                                 /* BDIV = 0, no prescalar */





while (1)








      FTM0_SC=0x10;                            //Channel Zero PWM Timer is config for System clock ; Zero Prescaler and  Counter  Operates in Up counting mode




      FTM0_C0VH=(Duty>>8);                    //Ton Period or Duty Cycle







      FTM2_C0VH=(Duty>>8);                    //Ton Period or Duty Cycle







      FTM0_SC=0x10;                          //Select the PWM functionality for each channel that will be used to generate PWM by using the TPMCnSC register of each channel.












void PWMInit(unsigned int Period)  


    unsigned int Temp=Period;  


  //  FTM0_SC=0X10;                          







    FTM0_MODH = (Temp>>8);                 // T total Period of PWM Cycle                

    FTM0_MODL = Period;        


    FTM0_C0VH = 0x00;                      // Ton Period of Total Period

    FTM0_C0VL = 0x00;  

    FTM0_C1VH = 0x00;                      // Ton Period of Total Period

    FTM0_C1VL = 0x00; 



    FTM0_C0SC = 0x14;    

    FTM0_C1SC = 0x14;



    FTM2_MODH = (Temp>>8);                 // T total Period of PWM Cycle                

    FTM2_MODL = Period;  


    FTM2_C0VH = 0x00;                      // Ton Period of Total Period

    FTM2_C0VL = 0x00;   

    FTM2_C1VH = 0x00;                      // Ton Period of Total Period

    FTM2_C1VL = 0x00;




    FTM2_C0SC = 0x28;    

    FTM2_C1SC = 0x28;








void delay()




    int i;

    for (i=0;i<25;i++){;}