Hi,
Im trying to use the eMIOS module of to set frequency of variable values. in this code im trying to set 5HZ frequency but i dont get anything in the scope when i measure.
Im using MPC5777c i have attched the code snippet to know whats wrong prpbably in it.
void Init_EMIOS_Channel_Bus_Counter(void) {
eMIOS_0_UC.UC[23].C.B.MODE = 0x50; /*Mod Ctr Bufd (MCB) int clk */
eMIOS_0_UC.UC[23].C.B.BSL = 1; /* Use internal counter */
eMIOS_0_UC.UC[23].C.B.UCPRE = 0; /* Set channel prescaler to divide by 1 */
eMIOS_0_UC.UC[23].C.B.FREN = 1; /* Freeze channel counting when in debug mode */
eMIOS_0_UC.UC[23].C.B.UCPREN = 1; /* Enable prescaler; uses default divide by 1 */
eMIOS_0_UC.UC[23].A.R = 999; /* Period will be 999+1 = 1000 clocks (1 msec) */
}
void EMIOS_Init(void)
{
eMIOS_0.MCR.B.MDIS= 0; /*EMIOS module enter normal mode */
eMIOS_0.MCR.B.GPRE= 0x99; /* eMIOS clk= sysclk/(GPRE+1)= 100 MHZ/100= 1MHz */
eMIOS_0.MCR.B.ETB = 0; /* External time base is disabled */
eMIOS_0.MCR.B.GPREN = 1; /* Enable eMIOS clock */
eMIOS_0.MCR.B.GTBE = 1; /* Enable global time base */
eMIOS_0.MCR.B.FRZ = 0; /* Disable stopping channels when in debug mode */
Init_EMIOS_Channel_Bus_Counter();
}
void Set_Channel_Parameters(uint8_t Chn,float Period)
{
eMIOS_0_UC.UC[Chn].C.B.MODE = 0x5A; /* Mode is OPWFMB Buffered */
//eMIOS_0_UC.UC[Chn].C.B.MODE = 0x58; /* Mode is OPWFMB Buffered */
eMIOS_0_UC.UC[Chn].C.B.BSL = 0; /* Use counter bus A (default) */
eMIOS_0_UC.UC[Chn].C.B.UCPRE = 0; /* Set channel prescaler to divide by 1 */
eMIOS_0_UC.UC[Chn].C.B.FREN = 1; /* Freeze channel counting when in debug mode */
eMIOS_0_UC.UC[Chn].C.B.UCPREN = 1; /* Enable prescaler; uses default divide by 1 */
eMIOS_0_UC.UC[Chn].C.B.EDPOL = 1; /* Polarity-leading edge sets output/trailing clears*/
eMIOS_0_UC.UC[Chn].A.R = 0;
eMIOS_0_UC.UC[Chn].B.R = Period;
//eMIOS_0_UC.UC[Chn].A.R = Period;
//eMIOS_0_UC.UC[Chn].B.R = 0;
}
void Set_Frequency_Output(uint8_t Chn,float Period)
{
Set_Channel_Parameters(Chn,Period);
}
int main(void)
{
#define GPIO_FUNC 0x0000
#define PRIMARY_FUNC 0x0400
#define ALTERNATE_1_FUNC 0x0800
#define OBE 0x0200
#define IBE 0x0100
SIU.PCR[197].R = PRIMARY_FUNC | OBE ;
EMIOS_Init();
/*using channel 18 as i need to control pin AD17*/
/* For 5Hz period in microseconds - 200000 */
Set_Frequency_Output(18,200000); .
}
Thanks,in Advance
Vignesh