MPC5643l PWM generation problem

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

MPC5643l PWM generation problem

1,077 Views
motognere
Contributor I

Hi, I'm new to MCU and just started getting my hands on MPC5643L. I'm trying to generate PWM signal on one Pin, PCR10.

 

#include "MPC5643L.h"

void sys_init(void);

void siul_init(void);

 

int main(void) {

  volatile int i = 0;

  sys_init();

  siul_init();

 

  // Enter Run Mode

  ME.RUN[0].R = 0x001F00F4; /* RUN0 cfg: IRCON,OSC0ON,PLL0ON,syclk=PLL */

  /* Mode Transition to enter RUN0 mode: */

  ME.MCTL.R = 0x40005AF0; /* Enter RUN0 Mode & Key */

  ME.MCTL.R = 0x4000A50F; /* Enter RUN0 Mode & Inverted Key */

  while (ME.GS.B.S_MTRANS) {}; /* Wait for mode transition to complete */

  while(ME.GS.B.S_CURRENT_MODE != 4) {}; /* Verify RUN0 is the current mode */

  while(CGM.FMPLL[0].CR.B.S_LOCK==0) {};

  while(CGM.FMPLL[1].CR.B.S_LOCK==0) {};

 

  // FlexPWM Config

  FLEXPWM_0.OUTEN.R = 0x0770;

  FLEXPWM_0.MASK.R = 0x0770;

  FLEXPWM_0.MCTRL.R   = 0x0700;

  FLEXPWM_0.FCTRL.R   = 0xF0F0;

  FLEXPWM_0.SUB[0].INIT.R   = 0xF448; // Initial count value

  FLEXPWM_0.SUB[0].CTRL.B.FULL = 0;    // No full Cycle reload

  FLEXPWM_0.SUB[0].CTRL.B.HALF = 1;           // Half cycle reload

  FLEXPWM_0.SUB[0].CTRL2.B.DBGEN = 1;    // PWM runs in debug mode

  FLEXPWM_0.SUB[0].CTRL2.B.INDEP = 0;    // PWMA & PWMB outputs are complementary

  FLEXPWM_0.SUB[0].CTRL2.B.CLK_SEL = 0;     // EXT force for PWM1

  FLEXPWM_0.SUB[0].CTRL2.B.PWM23_INIT= 0;     // PWM0_H = 1 at start-up

  FLEXPWM_0.SUB[0].CTRL2.B.PWM45_INIT= 1;     // PWM0_L = 0 at start-up

  FLEXPWM_0.SUB[0].DTCNT0.R = 0x003C;   //

  FLEXPWM_0.SUB[0].DTCNT1.R = 0x003C;   //

  FLEXPWM_0.SUB[0].DISMAP.R = 0x0FFF; // reset PWMA and PWMB Fault Disable Mask of selected submodule

  FLEXPWM_0.SUB[0].VAL[1].R = 0x0BB7; //

  FLEXPWM_0.SUB[0].VAL[2].R = 0xFA24;   //

  FLEXPWM_0.SUB[0].VAL[3].R = 0x05DC;   //

 

  // SIU Config

  SIU.PCR10.R = 0x0600;

  SIU.PCR91.R = 0x0102;

 

  /* Loop forever */

  for (;;) {

  }

}

 

However, it just doesn't work, although most lines of code are just copied from examples. I have no clue where is wrong. Thanks.

Labels (1)
Tags (1)
0 Kudos
2 Replies

626 Views
petervlna
NXP TechSupport
NXP TechSupport

Hi,

You PWM configuration is not correct.

Replace you PWM initializaiton with this one and then follow it step by step to set period and duty cycles as you require.

void FlexPMW_Init(void)

{

    FLEXPWM_0.OUTEN.R = 0x110;    //PWM0[SUB0] A0 & B0 output enable

    FLEXPWM_0.SUB[0].CTRL2.B.CLK_SEL = 2;  // PWM0[SUB0] AUX clock

    FLEXPWM_0.SUB[0].CTRL.B.PRSC = 0x0; /* Prescaler 1:1 */

   

    FLEXPWM_0.SUB[0].VAL[0].R = 0x0;  /* 0 offset */

    FLEXPWM_0.SUB[0].VAL[1].R = 0x320;  /* 20kHz period */

    FLEXPWM_0.SUB[0].VAL[2].R = 0x0;

    FLEXPWM_0.SUB[0].VAL[3].R = 0x160; /* 50% duty cycle */

    FLEXPWM_0.SUB[0].VAL[4].R = 0x100;

    FLEXPWM_0.SUB[0].VAL[5].R = 0x260; /* 50% duty cycle */

    FLEXPWM_0.SUB[0].CTRL2.B.DBGEN = 0x1; /* Enable debug */

    FLEXPWM_0.SUB[0].CTRL2.B.INDEP = 0x1; /* Independant channels */

    FLEXPWM_0.SUB[0].DISMAP.R = 0; /* Fault dissbale mapping register */

    FLEXPWM_0.SUB[0].TCTRL.R = 0x4; /* Output Trigger Enables (OUT_TRIG_EN2 = 1 )*/

   

    FLEXPWM_0.MCTRL.B.LDOK = 0x1; /* Load OK */

    FLEXPWM_0.MCTRL.B.RUN = 0x1;  /* Run PWM */

}//FlexPMW_Init

Your code is only generating high signal on the pin. This means you VAL register settings are incorrect. And also you must remove this line:

FLEXPWM_0.SUB[0].DISMAP.R = 0x0FFF; // reset PWMA and PWMB Fault Disable Mask of selected submodule


Peter

0 Kudos

626 Views
motognere
Contributor I

Hi Peter, thanks a lot for the reply. But I suppose FLEXPWM_0.SUB[0].CTRL2.B.CLK_SEL should be set as either 0 or 1 in this case, right? since submodule0 is being configured.

However, I'm confused about FlexPWM's clock. If CLK_SEL is 1, the clock is from EXT_CLK which is generated by eTimer. As there isn't eTimer created, I set CLK_SEL as 0 which is IPBus clock. I don't understand where is IPBus clock generated? I searched through the Ref manual, but didn't find anything helpful explaining it in detail. 

0 Kudos