AnsweredAssumed Answered

PWM control problem for MPC5744P

Question asked by nathan 米 on Nov 16, 2017
Latest reply on Nov 16, 2017 by nathan 米

I want to control a motor by the PWM module of MPC5744P.

I need to change the duty of PWM after each calculate cycle. 

The following are my config code:

 

SIUL2.MSCR[PC15].R = 0x02800003; // C[15] pin as FlexPWM A[1] output
SIUL2.MSCR[PD0].R = 0x02800003; // D[0] pin as FlexPWM B[1] output
SIUL2.MSCR[PA11].R = 0x02800003; // A[11] pin as FlexPWM A[2] output
SIUL2.MSCR[PG4].R = 0x02800001; // G[4] pin as FlexPWM B[2] output
SIUL2.MSCR[PG6].R = 0x02800001; // G[6] pin as FlexPWM A[3] output
SIUL2.MSCR[PA3].R = 0x02800003; // A[3] pin as FlexPWM B[3] output

 

FlexPWM_0.OUTEN.R = 0xFF0; // enable A and B outputs on submodule 0,1,2,3

 

/* Submodule 1 Initialization */
FlexPWM_0.SUB[1].CTRL1.R = 0x0404; // full cycle reload, every opportunity,IPBus/1, LDMOD=1
FlexPWM_0.SUB[1].CTRL2.R = 0x8080; // debug and force enable,有对时钟的选择,PBRIDGE_CLK
FlexPWM_0.SUB[1].INIT.R = 0;
FlexPWM_0.SUB[1].VAL0.R = 1000;
FlexPWM_0.SUB[1].VAL1.R = 2000; // PWM modulo
FlexPWM_0.SUB[1].VAL2.R = 100; // PWM A1 rising edge
FlexPWM_0.SUB[1].VAL3.R = 900; // PWM A1 falling edge
FlexPWM_0.SUB[1].DTCNT0.R = 0; // deadtime values
FlexPWM_0.SUB[1].DTCNT1.R = 0;
FlexPWM_0.SUB[1].DISMAP.R = 0x0000; // disable fault pin condition

 

/* Submodule 2 Initialization */
FlexPWM_0.SUB[2].CTRL1.R = 0x0404; // full cycle reload, every opportunity,IPBus/1, LDMOD=1
FlexPWM_0.SUB[2].CTRL2.R = 0x8080; // debug and force enable
FlexPWM_0.SUB[2].INIT.R = 0;
FlexPWM_0.SUB[2].VAL0.R = 1000;
FlexPWM_0.SUB[2].VAL1.R = 2000; // PWM modulo
FlexPWM_0.SUB[2].VAL2.R = 100; // PWM A2 rising edge
FlexPWM_0.SUB[2].VAL3.R = 800; // PWM A2 falling edge
FlexPWM_0.SUB[2].DTCNT0.R = 0; // deadtime values
FlexPWM_0.SUB[2].DTCNT1.R = 0;
FlexPWM_0.SUB[2].DISMAP.R = 0x0000; // disable fault pin condition

 

/* Submodule 3 Initialization */
FlexPWM_0.SUB[3].CTRL1.R = 0x0404; // full cycle reload, every opportunity,IPBus/1, LDMOD=1
FlexPWM_0.SUB[3].CTRL2.R = 0x8080; // debug and force enable
FlexPWM_0.SUB[3].INIT.R = 0;
FlexPWM_0.SUB[3].VAL0.R = 1000;
FlexPWM_0.SUB[3].VAL1.R = 2000; // PWM modulo
FlexPWM_0.SUB[3].VAL2.R = 100; // PWM A3 rising edge
FlexPWM_0.SUB[3].VAL3.R = 700; // PWM A3 falling edge
FlexPWM_0.SUB[3].DTCNT0.R = 0; // deadtime values
FlexPWM_0.SUB[3].DTCNT1.R = 0;
FlexPWM_0.SUB[3].DISMAP.R = 0x0000; // disable fault pin condition

// do immediate update, LDMOD bit already set
FlexPWM_0.MCTRL.B.LDOK = 0xF; // Load OK for each submodules
while (FlexPWM_0.MCTRL.B.LDOK == 0xF );
FlexPWM_0.SUB[1].CTRL2.B.FORCE = 1; // generate FORCE to init CNTR register by INIT value
FlexPWM_0.SUB[2].CTRL2.B.FORCE = 1; // generate FORCE to init CNTR register by INIT value
FlexPWM_0.SUB[3].CTRL2.B.FORCE = 1; // generate FORCE to init CNTR register by INIT value
// restore INIT values
FlexPWM_0.SUB[1].INIT.R = 0;
FlexPWM_0.SUB[2].INIT.R = 0;
FlexPWM_0.SUB[3].INIT.R = 0;
// do immediate update, LDMOD bit already set
FlexPWM_0.MCTRL.B.LDOK = 0xF; // Load OK for each submodules
while (FlexPWM_0.MCTRL.B.LDOK == 0xF );

FlexPWM_0.SUB[1].CTRL1.B.LDMOD = 0; // disable immediate update
FlexPWM_0.SUB[2].CTRL1.B.LDMOD = 0; // disable immediate update
FlexPWM_0.SUB[3].CTRL1.B.LDMOD = 0; // disable immediate update

FlexPWM_0.MCTRL.R = 0x0F00; // Submodule 0,1,2,3 PWM generator enabled
}

 

Then after each calculate cycle I tried to change the duty of PWM by changing the VAL2.R and VAL3.R

of each module.

But it turns out that the duty of PWM is still the init value, it can not be changed by me.

 

What is the problem? Are there any changes I need to make in my configuration?

 

Outcomes