Now I wanted to generate EMIOS OPWFM,and using EMIOS SAIC module for capturing frequency. On demo boads I connect pads between them.
But I can't generate OPWFM, I don't why?
Here my code:
///////////////////////////////////////////////////////////////////////////////////
/**********************************************************************
Function :eMIOS_Init初始化函数
Parameters:*ConfigPtr
return :None.
**********************************************************************/
void eMIOS_Init(const eMIOS_ConfigType* ConfigPtr)
{
eMIOS_ChannelType Chn = ConfigPtr->eMIOS_Channel;
/* 禁能分频器 */
//EMIOS.MCR.B.GPREN = 0;
if(PWM_MODE == ConfigPtr->eMIOS_Mode)
{
/* 设置管脚通道为PWM功能 */
SIU.PCR[Chn + 179].B.PA = 1;
SIU.PCR[Chn + 179].B.OBE = 1;
/* 禁能分频器 */
EMIOS.MCR.B.GPREN = 0;
/* eMIOS模块进入正常工作模式 */
EMIOS.MCR.B.MDIS = 0;
/* eMIOS模块全局64分频 */
EMIOS.MCR.B.GPRE = 63;
/* 禁止外部时基,设置通道23作为总线A控制时基 */
EMIOS.MCR.B.ETB = 0;
/* 使能全局时基 */
EMIOS.MCR.B.GTBE = 1;
EMIOS.MCR.B.FRZ = 1;
/* 使能全局分频器 */
//EMIOS.MCR.B.GPREN= 1;
/* eMIOS模式为:OPWFM */
EMIOS.CH[Chn].CCR.B.MODE = 0x19;
//EMIOS.CH[Chn].CCR.B.MODE = 0x60;
/* 使用内部时钟计数器 */
EMIOS.CH[Chn].CCR.B.BSL = 0;
/* 使能内部时钟分频 */
EMIOS.CH[Chn].CCR.B.UCPREN = 1;
/* 设置通道内部时钟分频值为1 */
EMIOS.CH[Chn].CCR.B.UCPRE = 0;
/* 设置极性:匹配A时输出0,匹配B时输出1 */
EMIOS.CH[Chn].CCR.B.EDPOL = 0;
/* 使能全局分频器 */
EMIOS.MCR.B.GPREN= 1;
}
else
{
/* 设置管脚通道为PWM功能 */
SIU.PCR[Chn + 179].B.PA = 1;
SIU.PCR[Chn + 179].B.IBE = 1;
#if 1
/* 禁能分频器 */
//EMIOS.MCR.B.GPREN = 0;
/* eMIOS模块进入正常工作模式 */
EMIOS.MCR.B.MDIS = 0;
/* eMIOS模块全局64分频 */
EMIOS.MCR.B.GPRE = 63;
/* 禁止外部时基,设置通道23作为总线A控制时基 */
EMIOS.MCR.B.ETB = 0;
/* 使能全局时基 */
EMIOS.MCR.B.GTBE = 1;
/* 使能全局分频器 */
EMIOS.MCR.B.GPREN = 1;
#endif
/* 设置为ICU模式 */
EMIOS.CH[Chn].CCR.B.MODE = 0x02;
/* 使用内部时钟计数器 */
EMIOS.CH[Chn].CCR.B.BSL = 0x3;
/* 使能内部时钟分频 */
EMIOS.CH[Chn].CCR.B.UCPREN = 1;
/* 使能中断 */
EMIOS.CH[Chn].CCR.B.FEN = 1;
/* 设置通道内部时钟分频值为1 */
EMIOS.CH[Chn].CCR.B.UCPRE = 0;
/* 上升沿触发 */
EMIOS.CH[Chn].CCR.B.EDSEL = 0x0;
EMIOS.CH[Chn].CCR.B.EDPOL = 0x1;
/* 使能全局分频器 */
//EMIOS.MCR.B.GPREN = 1;
}
//EMIOS.MCR.B.GPREN = 1;
}
/*******************************************************************
* FUNCTION : Pwm_Output *
* *
* DESCRIPTION : Set channel, Period and DutyCycle, for example, *
* your choice is channel 0, period=2s, *
* dutycycle=50%, you should input *
* (0,2000000,1000000),0.5=1,000,000/2,000,000 *
* Note :the clk is 1MHz, 1000 clocks =1 ms *
* *
* INPUTS : -Chn: Range from 0 to 22 *
* -Period: Type uint32 *
* -DutyCycle: Type uint32 *
*******************************************************************/
void eMIOS_SetPeriodAndDuty(eMIOS_ChannelType Chn, eMIOS_PeriodType Period, uint32 DutyCycle)
{
if(Period == 0)
{
EMIOS.CH[Chn].CBDR.R = 0;
EMIOS.CH[Chn].CADR.R = 0;
}
else
{
if(DutyCycle == 0)
{
EMIOS.CH[Chn].CBDR.R = Period;
EMIOS.CH[Chn].CADR.R = 0;
}
else if(DutyCycle >= Period)
{
EMIOS.CH[Chn].CBDR.R = Period;
EMIOS.CH[Chn].CADR.R = Period;
}
else
{
EMIOS.CH[Chn].CBDR.R = Period;
EMIOS.CH[Chn].CADR.R = Period - DutyCycle;
}
}
}
uint32 eMIOS_GetIcuFrequency(eMIOS_ChannelType Chn)
{
uint32 IcuFrequency = 0;
uint32 IcuFrequencyCount = 0;
if(eMIOSIcuPeriod[Chn].IcuPeriodSecond >= eMIOSIcuPeriod[Chn].IcuPeriodFirst)
{
IcuFrequencyCount = eMIOSIcuPeriod[Chn].IcuPeriodSecond - eMIOSIcuPeriod[Chn].IcuPeriodFirst;
}
else
{
IcuFrequencyCount = (0x00FFFFFF - eMIOSIcuPeriod[Chn].IcuPeriodFirst) + eMIOSIcuPeriod[Chn].IcuPeriodSecond;
}
if(0 == IcuFrequencyCount)
{
IcuFrequency = 0;
}
else
{
/* eMIOS内部频率为1MHz */
IcuFrequency = (uint32)(1000000/IcuFrequencyCount);
}
return IcuFrequency;
}
void eMIOS_ReadIcuPeriod(eMIOS_ChannelType Chn)
{
while(EMIOS.CH[Chn].CSR.B.FLAG == 0)
{
;
}
eMIOSIcuPeriod[Chn].IcuPeriodFirst = eMIOSIcuPeriod[Chn].IcuPeriodSecond;
eMIOSIcuPeriod[Chn].IcuPeriodSecond = EMIOS.CH[Chn].CADR.R;
}
void eMIOS_IcuIrq0(void)
{
eMIOS_ReadIcuPeriod(eMIOS_0);
EMIOS.CH[eMIOS_0].CSR.B.FLAG = 1;
}
void eMIOS_IcuIrq2(void)
{
eMIOS_ReadIcuPeriod(eMIOS_2);
EMIOS.CH[eMIOS_2].CSR.B.FLAG = 1;
}
///////////////////////////////////////////////////////////////////
Is there any example for MPC5634-OPWFM-SAIC?
Thank you!
Original Attachment has been moved to: MPC5634-OPWFM-SAIC.rar