Hi,sir:
I am a new to use the function of FlexPWM capture about MPC5744p. In the process of using, I had a promblem.
I use the PIN of X2 (G[2]) as the input port to capture the signal , used FlexPWM capture rigester,used Uart receive the value of Pulse width. What i recerved on the uart,Pulse width is 78.However,the signal is 100hz ,50% duty. Is my result right? Who can tell me how to confiure the rigester ,how to measure the period and the pulse width?
Blow are my init code and ISR code.
void SUIL2_PWMIN_Init(void)
{
SIUL2.MSCR[PC11].R = 0x32000000; //PC[11] GPIO - Red LED
SIUL2.MSCR[PC12].R = 0x32000000; //PC[11] GPIO - Red LED
SIUL2.GPDO[PC12].R = 1;
SIUL2.GPDO[PC11].R = 1;
SIUL2.MSCR[PG2].B.SRC = 3; /* Pad: Maximum slew rate */
SIUL2.MSCR[PG2].B.SMC = 1; /* Pad: Safe Mode Control Enable */
SIUL2.MSCR[PG2].B.HYS = 1; /* Pad: Input Hysteresis Enable */
SIUL2.MSCR[PG2].B.PUS = 1; /* Pad: PullUP */
SIUL2.MSCR[PG2].B.PUE = 1; /* Pad: Pull Enable */
SIUL2.MSCR[PG2].B.IBE = 1; /* Pad: Enable pad for input */
SIUL2.IMCR[96].B.SSS = 2; /* connected to pad flexpwm0 X2 */
SIUL2.MSCR[PG5].B.SRC = 3; /* Pad: Maximum slew rate */
SIUL2.MSCR[PG5].B.SMC = 1; /* Pad: Safe Mode Control Enable */
SIUL2.MSCR[PG5].B.HYS = 1; /* Pad: Input Hysteresis Enable */
SIUL2.MSCR[PG5].B.PUS = 1; /* Pad: PullUP */
SIUL2.MSCR[PG5].B.PUE = 1; /* Pad: Pull Enable */
SIUL2.MSCR[PG5].B.IBE = 1; /* Pad: Enable pad for input */
SIUL2.IMCR[99].B.SSS = 3; /* connected to pad flexpwm0 X3 */
}
void FlexPWM_IN_Init()
{
FlexPWM_0.SUB[2].CTRL1.R = 0x0474; // full cycle reload, PWM 128 clock frequency = fclk/128=1.25mhz,fclk=160MHZ
FlexPWM_0.SUB[2].DTCNT0.R = 0x0000;
FlexPWM_0.SUB[2].DTCNT1.R = 0x0000;
FlexPWM_0.SUB[2].INIT.R = 0; // PWM init count value
FlexPWM_0.SUB[2].VAL0.R = 6250;
FlexPWM_0.SUB[2].VAL1.R = 12500; //100HZ val1=(1/freq)*(fclk/128) period
FlexPWM_0.SUB[2].DISMAP.R = 0x0000; // disable fault pin condition
FlexPWM_0.MCTRL.B.LDOK = 0x0f; //PWM module 0,1,2,3 load init value.
FlexPWM_0.SUB[2].INTEN.B.CX0IE= 1; // CIE0 enable interrupt
FlexPWM_0.SUB[2].INTEN.B.CX1IE= 1; // CIE1 enable interrupt
FlexPWM_0.SUB[2].CAPTCTRLX.B.EDGX0= 2; // CAPT0 capture rising edge
FlexPWM_0.SUB[2].CAPTCTRLX.B.EDGX1= 1; // CAPT1 capture falling edge
FlexPWM_0.SUB[2].CAPTCTRLX.B.ONESHOTX= 1; // one shot mode
}
*******************************************************************************/
void FlexPWM_CAF2_ISR(void)
{
if(FlexPWM_0.SUB[2].STS.B.CFX0)//CAP0 interrupt
{
rising_edge= FlexPWM_0.SUB[2].CVAL0.R; // read cap0 rising edge
num1 = FlexPWM_0.SUB[2].CVAL0CYC.R;//
falling_edge= FlexPWM_0.SUB[2].CVAL1.R; // read cap1 falling edge
num2 = FlexPWM_0.SUB[2].CVAL1CYC.R;//
SIUL2.GPDO[PC12].R = 0;//
}
FlexPWM_0.SUB[2].STS.R = 0x00C0; // clear CFX1/CFX0 flag
Pulse_width =falling_edge-rising_edge;
Duty=(UInt32)Pulse_width*100/Period;
capture_over=1;
}
Thank you can provide source code and some information.
Thank you very much for you hlep.