MPC5566 EMIOS SAOC mode

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

MPC5566 EMIOS SAOC mode

跳至解决方案
626 次查看
EmilyZhou8
Contributor III

Hi,

I am setting EMIOS 17 to work as SAOC mode channel which uses bus C driven by EMIOS 8. However, SAOC mode is not working. Could you please help to check my code? 

Thank you very much!

Best Regards,

Emily

#include "MPC5566.h"

/************ PWM_Period and PWM_Frequence should be changed together ************/
/* Define PWM period Counter value */
#define PWM_Period 16
#define FS_GPIO_EMIOS17 196
#define Commutation_Time_Channel FS_GPIO_EMIOS17

void initSysclk (void) {

FMPLL.SYNCR.B.LOLRE = 0; /* 0: ignore loss of lock - reset not asserted. */
FMPLL.SYNCR.B.LOLIRQ = 0; /* 0: ignore loss of lock - interrupt not requested */
FMPLL.SYNCR.B.PREDIV = 1; /* 1: use incoming OSC 8MHz / 2 = 4 MHz */
FMPLL.SYNCR.B.MFD = 28; /* 28: VCO = 4 * (28+4) = 128 MHz */
FMPLL.SYNCR.B.RFD = 1; /* 1: divide by 2, Fsys = VCO / (2^1=2) = 64MHz */
while(FMPLL.SYNSR.B.LOCK != 1){} /* Wait for FMPLL to Lock */
FMPLL.SYNCR.B.RFD = 0; /* 0: divide by 1, Fsys = VCO / (2^0=1) = 128MHz */
}

void initEMIOS(void) {
EMIOS.MCR.B.GPRE= 7; /* Divide 128 MHz sysclk by 7+1 = 8 for 16MHz eMIOS clk*/ //EMIOS.MCR.B.GPRE= 63; /* Divide 64 MHz sysclk by 63+1 = 64 for 1MHz eMIOS clk*/
EMIOS.MCR.B.ETB = 0; /* External time base is disabled; Ch 23 drives ctr bus A */
EMIOS.MCR.B.GPREN = 1; /* Enable eMIOS clock */
EMIOS.MCR.B.GTBE = 1; /* Enable global time base */
EMIOS.MCR.B.FRZ = 1; /* Enable stopping channels when in debug mode */
}

void initEMIOSch8(void) { /* EMIOS CH 8: Modulus Up Counter */
EMIOS.CH[8].CADR.R = PWM_Period - 1; /* Period will be 15+1 = 16 clocks (1 MHz) */
EMIOS.CH[8].CCR.B.MODE = 0x10; /* MPC555x: Modulus Counter (MC), internal clock */
EMIOS.CH[8].CCR.B.BSL = 0x3; /* Use internal counter */
EMIOS.CH[8].CCR.B.UCPRE=0; /* Set channel prescaler to divide by 1 */
EMIOS.CH[8].CCR.B.FREN = 1; /* Freeze channel counting when in debug mode */
EMIOS.CH[8].CCR.B.UCPREN = 1; /* Enable prescaler; uses default divide by 1 */
}

void initEMIOSch17(void) {
uint8_t EMIOS_Channel_Output;

EMIOS_Channel_Output = Commutation_Time_Channel-179; /* Convert to EMIOS channel number compatible with EMIOS struct in MPC5566.h */

EMIOS.CH[EMIOS_Channel_Output].CCR.B.MODE = 0x3; /* MPC555x: Mode is Single action output compare */
EMIOS.CH[EMIOS_Channel_Output].CCR.B.BSL = 0x1; /* Use bus C */
EMIOS.CH[EMIOS_Channel_Output].CCR.B.UCPRE = 0; /* Set channel prescaler to divide by 1 */
EMIOS.CH[EMIOS_Channel_Output].CCR.B.FREN = 1; /* Stop (freeze) channel registers when in debug mode */
EMIOS.CH[EMIOS_Channel_Output].CCR.B.UCPREN = 1; /* Enable prescaler; uses default divide by 1 */
EMIOS.CH[EMIOS_Channel_Output].CCR.B.DMA = 0; /* FLAG assigned to Interrupt request */
EMIOS.CH[EMIOS_Channel_Output].CCR.B.EDSEL = 1; /* Both edges triggering */
EMIOS.CH[EMIOS_Channel_Output].CCR.B.FCK = 0; /* Filter clock select: EMIOS clock */
EMIOS.CH[EMIOS_Channel_Output].CCR.B.IF = 0x1; /* Input filter: 8 filter clock periods */
EMIOS.CH[EMIOS_Channel_Output].CCR.B.FEN = 1; /* Flag enables interrupt */

SIU.PCR[Commutation_Time_Channel].R = 0x0E00; /* MPC555x: Initialize pad for eMIOS output */
}

void main (void) {
volatile uint32_t i = 0; /* Dummy idle counter */
uint32_t NextCmtPeriod=1000;
initSysclk(); /* Set sysclk = 128MHz running from PLL */
initEMIOS(); /* Initialize eMIOS to provide 16 MHz clock to channels */
initEMIOSch8(); /* Initialize eMIOS channel 8 as modulus counter*/
initEMIOSch17(); /* Initialize eMIOS channel 17 as SAOC, using ch 8 as time base */

while (1)
{i++;

EMIOS.CH[17].CADR.R = EMIOS.CH[8].CCNTR.R + NextCmtPeriod;
while(EMIOS.CH[17].CSR.B.FLAG != 1)
{

}
NextCmtPeriod=NextCmtPeriod+2000;
EMIOS.CH[17].CSR.B.FLAG = 1;


}
}

 

0 项奖励
回复
1 解答
580 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

yes, correct.

BR, Petr

在原帖中查看解决方案

0 项奖励
回复
4 回复数
591 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

if you want to use local counter bus for ch17, then ch16 (counter us D) have to be configured, not ch8 you have

PetrS_0-1722834624619.png

 

BR, Petr

0 项奖励
回复
582 次查看
EmilyZhou8
Contributor III
Hi Peter,
Thanks for your reply. I am wondering if I use EMIOS Chanel 16 to set bus D, SAOC of EMIOS Channel 17 can work only if EMIOS.CH[16].CADR.R>=EMIOS.CH[17].CADR.R?

Best Regards,
Emily
0 项奖励
回复
581 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

yes, correct.

BR, Petr

0 项奖励
回复
544 次查看
EmilyZhou8
Contributor III
Thanks a lot!
0 项奖励
回复