EMIOS configuration to set variable frequency

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

EMIOS configuration to set variable frequency

2,273 Views
vignesh_v
Contributor III

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

Labels (1)
0 Kudos
Reply
14 Replies

2,037 Views
vignesh_v
Contributor III

Hi Petr,

          Thanks for the sggestions. One query regarding regarding reading the frequency measurement . for example i need to check 5hZ is fed correctly in reading the frequency (measurement) can be done thtogh 

IPWM modes using counter as stated in one of example or is there any other way to do it.

like SAIC mode . Could yo please guide me?

Regards,

Vignesh

0 Kudos
Reply

2,037 Views
PetrS
NXP TechSupport
NXP TechSupport

To measure frequency/period of input signal you rather make use of IPM and/or SAIC modes.

BR, Petr

0 Kudos
Reply

2,037 Views
vignesh_v
Contributor III

Hi,

 Ok thanks.

Regards,

Vignesh.

0 Kudos
Reply

2,037 Views
vignesh_v
Contributor III

Hi Peter,

             The mode to be used shall be for OPWFMB 

eMIOS_0_UC.UC[Chn].C.B.MODE = 0x5A; /* Mode is OPWFMB Buffered */

or 

eMIOS_0_UC.UC[Chn].C.B.MODE = 0x58; /* Mode is OPWFMB Buffered */

right ?

Actually I ve tried both to activate a communication port I need to set this frequency to 5HZ on AD17

its not happening any insight on this please.

Regards,

Vignesh

0 Kudos
Reply

2,036 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi Vignesh,

I tested attached code on the EVB and I got 5Hz signal on AD17 pin normally.

BR, Petr

0 Kudos
Reply

2,036 Views
vignesh_v
Contributor III

Hi  Peter,

 Thanks i'll check with this and come back to you in case any further clarifications.

Thanks,

Vignesh

0 Kudos
Reply

2,036 Views
vignesh_v
Contributor III

Hi Peter,

              Cant get u exactly. This is my understanding kindly  tell me whether right.

EMIOS_Init doesn't require any channel 23 counter initialisation

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 */
   //not required- 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 = 3;     //use internal counter
  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 =Period/2;
  eMIOS_0_UC.UC[Chn].B.R = Period;  
}

Thanks,

Vignesh

0 Kudos
Reply

2,036 Views
PetrS
NXP TechSupport
NXP TechSupport

yes, it could work this way. Just, set the mode as the latest instruction in Set_Channel_Parameters().

Channel 23 init is not needed if counter bus A is not used in your code.

BR, Petr

0 Kudos
Reply

2,036 Views
vignesh_v
Contributor III

hi,

   My other clarification would be whatever the channel I use only setting parameters would do and the setting for eMIOS 23 channel as time base s not required?

Thanks,

Vignesh

0 Kudos
Reply

2,036 Views
vignesh_v
Contributor III

setting of BSL to 3 is applicable for which channel I need to set frequency or its same for even emios23 channel which is being used as timebase as per example.

Could u pl clarify that?

Thanks,

Vignesh.V

0 Kudos
Reply

2,036 Views
PetrS
NXP TechSupport
NXP TechSupport

usage of the BSL depends on the mode chosen for given channel. I realized for OPWFMB mode the internal counter is automatically selected, so then BSL should be don't care, I think. You can test it. 

BR, Petr

0 Kudos
Reply

2,036 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi Vignesh,

what does Set_Channel_Parameters() do? Can you share the code too?

BR, Petr

0 Kudos
Reply

2,036 Views
vignesh_v
Contributor III

Hi, 

  I have edited the above section where in I have added the Set_Channel_Parameters() function definition.

It is used to set parameters for the specified channel and the value of period

0 Kudos
Reply

2,036 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

set BSL=3 to use channel's internal counter. Also set A register to value greater then 0, unless 0% duty is generated, so no signal will be visible. Set it e.g. to Period/2 to have 50% duty.

BR, Petr

0 Kudos
Reply