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.