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;
}
}
Solved! Go to Solution.
Hi,
if you want to use local counter bus for ch17, then ch16 (counter us D) have to be configured, not ch8 you have
BR, Petr
Hi,
yes, correct.
BR, Petr