MPC5634-EMIOS-SAIC   code

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

MPC5634-EMIOS-SAIC   code

Jump to solution
3,989 Views
陈秀侠
Contributor II

Now I want to capture  eMIOS_9  channel output PWM(duty cycle 20%,frequency is 1KHz),using eMIOS_0 channel for capture.

But  I  cannot  enter   eMIOS_0_isr   interrupt  function,Is there any wrong with my code?

////////////////////////////////////////////////////////////////////////////////

#include "MPC5634M_MLQC80.h"

 

#define  LED3 SIU.GPDO[190].R

#define  LED4 SIU.GPDO[191].R

 

uint32_t data1,data2;

uint32_t delaytime;

 

void Config_PLL(void)

   FMPLL.SYNCR.R = 0x03080030;            /* 8 MHz crystal */

   while (FMPLL.SYNSR.B.LOCK != 1) {};    /* Wait for LOCK = 1 */

   FMPLL.SYNCR.R = 0x03080430;            /* Enable FM */

   while (FMPLL.SYNSR.B.LOCK != 1) {}; /* Wait for FMPLL to LOCK again */

   FMPLL.SYNCR.R = 0x16000000;         /* Final value for 64 MHz: RFD=0 */

}

 

 

void init_led(void)

{

  //EMIOS9,10,11,12对应PCR188,189,190,191

  //SIU.PCR[188].R = 0x0203;            //EMIOS9,OUTPUT

  //SIU.PCR[189].R = 0x0203;             //EMIOS10,OUTPUT

  SIU.PCR[190].R = 0x0203;             //EMIOS11,OUTPUT

  SIU.PCR[191].R = 0x0203;             //EMIOS12,OUTPUT

}

 

void init_EMIOS(void)

{

   EMIOS.MCR.B.GPRE=63;      // 设置分频系数为63+1=64,分频后始终为1MHz

   EMIOS.MCR.B.ETB=0;        // 禁止外部时基,设置通道23作为总线A控制时基

   EMIOS.MCR.B.GPREN=1;      // 使能全局分频器

   EMIOS.MCR.B.GTBE=1;       // 使能全局时基

   EMIOS.MCR.B.FRZ=1;        // 在调试模式下停止通道

 

   /* 初始化eMIOS23:作为所有通道的时基Bus A*/

   EMIOS.CH[23].CADR.R=999;       // 周期是999=1=1000 clocks(1ms)

   EMIOS.CH[23].CCR.B.MODE=0x50;  //设置为缓冲模数计数器模式MCB

   EMIOS.CH[23].CCR.B.BSL=0x3;    //使用1MHz的内部计数器作为时钟源

   EMIOS.CH[23].CCR.B.UCPRE=0;    //设置通道分频值为1

   EMIOS.CH[23].CCR.B.FREN=1;     //在调试模式下冻结通道计数

   EMIOS.CH[23].CCR.B.UCPREN=1;   //使能分频器:使用默认预分频值为1

 

   /* 初始化eMIOS9:占空比20% */

   EMIOS.CH[9].CADR.R=100;         // 设置首边沿的匹配值

   EMIOS.CH[9].CBDR.R=900;         // 设置尾边沿的匹配值

   EMIOS.CH[9].CCR.B.BSL=0x0;      // 使用Bus A

   EMIOS.CH[9].CCR.B.EDPOL=0;      // 设置极性:A匹配时清0,B匹配时置1

   EMIOS.CH[9].CCR.B.MODE=0x60;    //选择OPWMB模式

   SIU.PCR[188].R = 0x0600;        //EMIOS9对应SIU.PCR188

 

 

   /*初始化eMIOS0:输入捕捉SAIC模式 */

 

   EMIOS.CH[0].CCR.B.MODE=0x02;    //设置SAIC

   EMIOS.CH[0].CCR.B.BSL=0x0;      //使用使用Bus A:1MHz的内部计数器作为时钟源

   //EMIOS.CH[0].CCR.B.IF = 1;       //设置输入滤波器

   //EMIOS.CH[0].CCR.B.FCK= 1;       //滤波器时钟为主时钟

   EMIOS.CH[0].CCR.B.FEN = 1;       //使能输入捕捉中断

   //EMIOS.CH[0].CCR.B.DMA = 0;       //FLAG用作中断请求

   EMIOS.CH[0].CCR.B.EDSEL=0;       //设置上升沿触发中断

   EMIOS.CH[0].CCR.B.EDPOL= 1;

   //EMIOS.CH[0].CCR.B.UCPRE = 0;     //设置分频值为1

   //EMIOS.CH[0].CCR.B.UCPREN = 1;    //使能分频器

   //EMIOS.CH[0].CCR.B.FREN=1;        //在调试模式下冻结通道计数

   INTC.PSR[51].R = 3;

   SIU.PCR[179].R = 0x0503;         //EMIOS0对应SIU.PCR179

}

 

 

/*******************************************************************************

/*                       SAIC中断函数:eMIOS_0_isr                             */

/*******************************************************************************/

void eMIOS_0_isr(void)

{

  //LED4 ^= 1;

  if(EMIOS.CH[0].CSR.B.FLAG == 1)

  {

  //EMIOS.CH[0].CSR.B.FLAG = 1;      //清除标志位

 

  data1 = data2;

  data2 = EMIOS.CH[0].CADR.R;    //记录上升沿对应的时刻

 

  delaytime = data2- data1;   //计算时间间隔

  LED4 ^= 1;

     EMIOS.CH[0].CSR.B.FLAG = 1;      //清除标志位

  }

}

 

 

/************************************************************/

/*                           主函数                         */

/************************************************************/

void main(void)

{   

   vuint32_t i = 0;    /* Dummy idle counter */

   Config_PLL();

 

   init_led();

   init_EMIOS();

 

   INTC_InitINTCInterrupts();

   INTC_InstallINTCInterruptHandler(eMIOS_0_isr,51,3);

   INTC.CPR.B.PRI = 0;       /* MPC555x: Lower INTC's current priority */

   /* Loop forever */

   for (;;)

   {    

      i++;

      LED3 ^= 1; 

   }

}

 

////////////////////////////////////////////////////////////////////////////////

Labels (1)
1 Solution
3,016 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

Seems the eMIOS setting is correct. be sure the external signal is really fed into proper pad and then check if the channel 0 flag is really set. If yes then interrupts may not be properly initialized.

Try to test attached code which do the same.

BR, Petr

View solution in original post

5 Replies
3,017 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

Seems the eMIOS setting is correct. be sure the external signal is really fed into proper pad and then check if the channel 0 flag is really set. If yes then interrupts may not be properly initialized.

Try to test attached code which do the same.

BR, Petr

3,016 Views
2039759305
Contributor I

Could you do me a favor?I am in trouble with IPWM setting of eMIOS channel of MPC5634M,especially the setting of interrupt .Do you have the demo of IPWM setting?I would be appreciated with your help.

0 Kudos
Reply
3,016 Views
陈秀侠
Contributor II

It's too long time, I find a demo for IPWM, and you check it.

0 Kudos
Reply
3,016 Views
2039759305
Contributor I

Thank you very much,I will check it .

0 Kudos
Reply
3,016 Views
陈秀侠
Contributor II

Hi,

   I checked my code again and finded the error in my interrupt functions:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void eMIOS_0_isr(void)

{

  //LED4 ^= 1;

  if(EMIOS.CH[0].CSR.B.FLAG == 1)

  {

  EMIOS.CH[0].CSR.B.FLAG = 1;      //清除标志位

  data1 = data2;

  data2 = EMIOS.CH[0].CADR.R;  

  // delaytime = 0x0000ffff&(data2- data1);  

     if(data2 > data1)

     {

      delaytime = data2 - data1;

     }

     //else

     //{

     // delaytime = (0xFFFFFF - data1) + data2;

     //}

  LED4 ^= 1;

  }

}

////////////////////////////////////////////////////////////////////////

Thank you for your answer,I'll test your demo tomorrow.

Best wishes!

0 Kudos
Reply