MCF51QM128 FTM1 in center aligned PWM mode

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

MCF51QM128 FTM1 in center aligned PWM mode

Jump to solution
879 Views
nz_developer
Contributor II

Trying to get a center aligned PWM output working. Managed to get Normal PWM working but when I change to center aligned it wont work. Any suggestions would really help me. I am using the processor expert to generate this code.

 

void FT1_Init(void)

{

  /* SIM_SCGC3: FTM1=1 */

  SIM_SCGC3 |= (uint8_t)0x08U;                           

  /* FTM1_MODE: FAULTIE=0,FAULTM=0,CAPTEST=0,PWMSYNC=0,WPDIS=1,INIT=0,FTMEN=1 */

  FTM1_MODE = (uint8_t)0x05U;                            

  /* FTM1_SC: TOF=0,TOIE=0,CPWMS=0,CLKS=0,PS=0 */

  FTM1_SC = (uint8_t)0x00U;                            

  /* FTM1_C0SC: CHF=0,CHIE=0,MSB=0,MSA=0,ELSB=0,ELSA=0,??=0,DMA=0 */

  FTM1_C0SC = (uint8_t)0x00U;                            

  /* FTM1_C1SC: CHF=0,CHIE=0,MSB=0,MSA=0,ELSB=0,ELSA=0,??=0,DMA=0 */

  FTM1_C1SC = (uint8_t)0x00U;                            

  /* FTM1_C2SC: CHF=0,CHIE=0,MSB=0,MSA=0,ELSB=0,ELSA=0,??=0,DMA=0 */

  FTM1_C2SC = (uint8_t)0x00U;                            

  /* FTM1_C3SC: CHF=0,CHIE=0,MSB=0,MSA=0,ELSB=0,ELSA=0,??=0,DMA=0 */

  FTM1_C3SC = (uint8_t)0x00U;                            

  /* FTM1_C4SC: CHF=0,CHIE=0,MSB=0,MSA=0,ELSB=0,ELSA=0,??=0,DMA=0 */

  FTM1_C4SC = (uint8_t)0x00U;                            

  /* FTM1_C5SC: CHF=0,CHIE=0,MSB=0,MSA=0,ELSB=0,ELSA=0,??=0,DMA=0 */

  FTM1_C5SC = (uint8_t)0x00U;                            

  /* FTM1_CNTINH: INIT_H=0 */

  FTM1_CNTINH = (uint8_t)0x00U;                            

  /* FTM1_CNTINL: INIT_L=0 */

  FTM1_CNTINL = (uint8_t)0x00U;                            

  /* FTM1_CNTH: COUNT_H=0 */

  FTM1_CNTH = (uint8_t)0x00U;                            

  /* FTM1_CNTL: COUNT_L=0 */

  FTM1_CNTL = (uint8_t)0x00U;                            

  /* FTM1_MODH: MOD_H=0 */

  FTM1_MODH = (uint8_t)0x00U;                            

  /* FTM1_MODL: MOD_L=0x4A */

  FTM1_MODL = (uint8_t)0x4AU;                            

  /* FTM1_FILTER0: CHoddFVAL=0,CHevenFVAL=0 */

  FTM1_FILTER0 = (uint8_t)0x00U;                            

  /* FTM1_FILTER1: CHoddFVAL=0,CHevenFVAL=0 */

  FTM1_FILTER1 = (uint8_t)0x00U;                            

  /* FTM1_C0SC: CHF=0,CHIE=0,MSB=0,MSA=0,ELSB=1,ELSA=0,??=0,DMA=0 */

  FTM1_C0SC = (uint8_t)0x08U;                            

  /* FTM1_C1SC: CHF=0,CHIE=0,MSB=0,MSA=0,ELSB=1,ELSA=0,??=0,DMA=0 */

  FTM1_C1SC = (uint8_t)0x08U;                            

  /* FTM1_C2SC: CHF=0,CHIE=0,MSB=0,MSA=0,ELSB=1,ELSA=0,??=0,DMA=0 */

  FTM1_C2SC = (uint8_t)0x08U;                            

  /* FTM1_C3SC: CHF=0,CHIE=0,MSB=0,MSA=0,ELSB=1,ELSA=0,??=0,DMA=0 */

  FTM1_C3SC = (uint8_t)0x08U;                            

  /* FTM1_C4SC: CHF=0,CHIE=0,MSB=0,MSA=1,ELSB=0,ELSA=0,??=0,DMA=0 */

  FTM1_C4SC = (uint8_t)0x10U;                            

  /* FTM1_C5SC: CHF=0,CHIE=0,MSB=0,MSA=1,ELSB=0,ELSA=0,??=0,DMA=0 */

  FTM1_C5SC = (uint8_t)0x10U;                            

  /* FTM1_C0VH: VAL_H=0 */

  FTM1_C0VH = (uint8_t)0x00U;                            

  /* FTM1_C0VL: VAL_L=0x14 */

  FTM1_C0VL = (uint8_t)0x14U;                            

  /* FTM1_C1VH: VAL_H=0 */

  FTM1_C1VH = (uint8_t)0x00U;                            

  /* FTM1_C1VL: VAL_L=0x14 */

  FTM1_C1VL = (uint8_t)0x14U;                            

  /* FTM1_C2VH: VAL_H=0 */

  FTM1_C2VH = (uint8_t)0x00U;                            

  /* FTM1_C2VL: VAL_L=0x16 */

  FTM1_C2VL = (uint8_t)0x16U;                            

  /* FTM1_C3VH: VAL_H=0 */

  FTM1_C3VH = (uint8_t)0x00U;                            

  /* FTM1_C3VL: VAL_L=0x22 */

  FTM1_C3VL = (uint8_t)0x22U;                            

  /* FTM1_C4VH: VAL_H=0 */

  FTM1_C4VH = (uint8_t)0x00U;                            

  /* FTM1_C4VL: VAL_L=0 */

  FTM1_C4VL = (uint8_t)0x00U;                            

  /* FTM1_C5VH: VAL_H=0 */

  FTM1_C5VH = (uint8_t)0x00U;                            

  /* FTM1_C5VL: VAL_L=0 */

  FTM1_C5VL = (uint8_t)0x00U;                            

  /* FTM1_POL: POL7=0,POL6=0,POL5=0,POL4=0,POL3=0,POL2=0,POL1=0,POL0=0 */

  FTM1_POL = (uint8_t)0xFFU;                            

  /* FTM1_OUTINIT: CH7OI=0,CH6OI=0,CH5OI=0,CH4OI=0,CH3OI=0,CH2OI=1,CH1OI=0,CH0OI=1 */

  FTM1_OUTINIT = (uint8_t)0x05U;                            

  /* FTM1_OUTMASK: CH7OM=0,CH6OM=0,CH5OM=0,CH4OM=0,CH3OM=0,CH2OM=0,CH1OM=0,CH0OM=1 */

  FTM1_OUTMASK = (uint8_t)0x01U;                            

  /* FTM1_COMBINE0: ??=0,FAULTEN=0,SYNCEN=0,DTEN=0,DECAP=0,DECAPEN=0,COMP=0,COMBINE=0 */

  FTM1_COMBINE0 = (uint8_t)0x00U;                            

  /* FTM1_COMBINE1: ??=0,FAULTEN=0,SYNCEN=0,DTEN=0,DECAP=0,DECAPEN=0,COMP=0,COMBINE=0 */

  FTM1_COMBINE1 = (uint8_t)0x00U;                            

  /* FTM1_COMBINE2: ??=0,FAULTEN=0,SYNCEN=0,DTEN=0,DECAP=0,DECAPEN=0,COMP=0,COMBINE=0 */

  FTM1_COMBINE2 = (uint8_t)0x00U;                            

  /* FTM1_DEADTIME: DTPS=0,DTVAL=0 */

  FTM1_DEADTIME = (uint8_t)0x00U;                            

  /* FTM1_SYNC: SWSYNC=0,TRIG2=0,TRIG1=0,TRIG0=0,SYNCHOM=0,REINIT=0,CNTMAX=0,CNTMIN=0 */

  FTM1_SYNC = (uint8_t)0x00U;                            

  /* FTM1_EXTTRIG: TRIGF=0,INITTRIGEN=0,CH1TRIG=0,CH0TRIG=0,CH5TRIG=0,CH4TRIG=0,CH3TRIG=0,CH2TRIG=0 */

  FTM1_EXTTRIG = (uint8_t)0x00U;                            

  /* FTM1_FLTFILTER: ??=0,??=0,??=0,??=0,FFVAL=0 */

  FTM1_FLTFILTER = (uint8_t)0x00U;                            

  /* FTM1_FLTCTRL: FFLTR3EN=0,FFLTR2EN=0,FFLTR1EN=0,FFLTR0EN=0,FAULT3EN=0,FAULT2EN=0,FAULT1EN=0,FAULT0EN=0 */

  FTM1_FLTCTRL = (uint8_t)0x00U;                            

  /* FTM1_MODE: FAULTIE=0,FAULTM=0,CAPTEST=0,PWMSYNC=0,WPDIS=1,INIT=1,FTMEN=1 */

  FTM1_MODE = (uint8_t)0x07U;                            

  /* FTM1_SC: TOF=0,TOIE=0,CPWMS=1,CLKS=1,PS=0 */

  FTM1_SC = (uint8_t)0x28U;                            

}

 

also have this which I don't think is needed

  MXC_PTAPF4 = (MXC_PTAPF4 & 0xF) |(0x4 <<4);

  MXC_PTAPF3 = 0x4;

 

Thank you


 


Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
642 Views
nz_developer
Contributor II

Seems like the problem is that at the end each of the output value registers gets reset to zero. such as

FTM1_C0VL

So wrote this small function which then produces the waveform I wanted

#define FT1_CLK_FQ 20971500

#define DEAD_TIME 5

void StartFMT1(u32 Fq){

    u16 Mod = (u16)((20971500/2)/Fq);

    FTM1_SC &= ~(BIT4 | BIT3);

    // Timer frequency is clk frequency divided by 2*Period

    FTM1_MOD = Mod;

    FTM1_C0V = Mod/2 + DEAD_TIME;

    FTM1_C1V = Mod/2 - DEAD_TIME;

    FTM1_C2V = Mod/2;       

    FTM1_C3V = Mod/2;

    // Turn on FT1

    FTM1_SC |=  BIT3;

}


View solution in original post

0 Kudos
Reply
1 Reply
643 Views
nz_developer
Contributor II

Seems like the problem is that at the end each of the output value registers gets reset to zero. such as

FTM1_C0VL

So wrote this small function which then produces the waveform I wanted

#define FT1_CLK_FQ 20971500

#define DEAD_TIME 5

void StartFMT1(u32 Fq){

    u16 Mod = (u16)((20971500/2)/Fq);

    FTM1_SC &= ~(BIT4 | BIT3);

    // Timer frequency is clk frequency divided by 2*Period

    FTM1_MOD = Mod;

    FTM1_C0V = Mod/2 + DEAD_TIME;

    FTM1_C1V = Mod/2 - DEAD_TIME;

    FTM1_C2V = Mod/2;       

    FTM1_C3V = Mod/2;

    // Turn on FT1

    FTM1_SC |=  BIT3;

}


0 Kudos
Reply