Processor Expert - Clock Issue - MKE02Z16

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

Processor Expert - Clock Issue - MKE02Z16

Jump to solution
1,721 Views
danielhulshof
Contributor II

Hello there!

I'm using Kinetis Studio V3.1.0 and P.E. V3.0.2 developing software for the MKE02Z16 micro-controller.

Here are some issues I've encountered when fiddling with clock configurations using P.E.

I've attached images of the P.E. screen of each issue.

 

Issue 1:

On P.E. Component Inspector, editing "Cpu", setting "Slow internal reference clock" to 39.0625 and "ICS Mode" to FEI, the clock is not configured properly. The resulting clock should be 40Mhz (output prescaler set as 1), but in fact the clock generated (tested) was 32Mhz. That is because the generated code didn't change ICS_C3[SCTRIM] and ICS_C4[SCFTRIM] to the appropriate value. Actually, there was no apparent change to those registers. Here is the __init_hardware generated code:

 

void __init_hardware(void)

{

  /*** !!! Here you can place your own code before PE initialization using property "User code before PE initialization" on the build options tab. !!! ***/

  /*** ### MKE02Z16VLC4 "Cpu" init code ... ***/

  /*** PE initialization code after reset ***/

  SCB_VTOR = (uint32_t)(&__vect_table); /* Set the interrupt vector table position */

  /* Disable the WDOG module */

  /* WDOG_TOVAL: TOVAL=0xE803 */

  WDOG_TOVAL = WDOG_TOVAL_TOVAL(0xE803); /* Timeout value */

  /* WDOG_CS2: WIN=0,FLG=0,??=0,PRES=0,??=0,??=0,CLK=1 */

  WDOG_CS2 = WDOG_CS2_CLK(0x01);       /* 1-kHz clock source */

  /* WDOG_CS1: EN=0,INT=0,UPDATE=1,TST=0,DBG=0,WAIT=1,STOP=1 */

  WDOG_CS1 = WDOG_CS1_UPDATE_MASK |

             WDOG_CS1_TST(0x00) |

             WDOG_CS1_WAIT_MASK |

             WDOG_CS1_STOP_MASK;

 

  /* System clock initialization */

  /* SIM_BUSDIV: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,BUSDIV=1 */

  SIM_BUSDIV = SIM_BUSDIV_BUSDIV_MASK; /* Update system prescalers */

  /* Switch to FEI Mode */

  /* ICS_C1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */

  ICS_C1 = ICS_C1_CLKS(0x00) |

           ICS_C1_RDIV(0x00) |

           ICS_C1_IREFS_MASK |

           ICS_C1_IRCLKEN_MASK;

  /* ICS_C2: BDIV=0,LP=0 */

  ICS_C2 &= (uint8_t)~(uint8_t)((ICS_C2_BDIV(0x07) | ICS_C2_LP_MASK));

  /* OSC_CR: OSCEN=0,??=0,OSCSTEN=0,OSCOS=0,??=0,RANGE=0,HGO=0,OSCINIT=0 */

  OSC_CR = 0x00U;

  while((ICS_S & ICS_S_IREFST_MASK) == 0x00U) { /* Check that the source of the FLL reference clock is the internal reference clock. */

  }

  while((ICS_S & 0x0CU) != 0x00U) {    /* Wait until output of the FLL is selected */

  }

  /*** End of PE initialization code after reset ***/

  /*** !!! Here you can place your own code after PE initialization using property "User code after PE initialization" on the build options tab. !!! ***/

}

 

 

Issue 2:

On P.E. Component Inspector, editing "Cpu", setting "ICS Mode" to FBELP, the actual clock code is not generated on file Cpu.c.

I actually intend to use using FBELP with a 10Mhz oscillator (for better precision), so I really need to know how to fix this! Here is the __init_hardware generated code:

 

void __init_hardware(void)

{

  /*** !!! Here you can place your own code before PE initialization using property "User code before PE initialization" on the build options tab. !!! ***/

  /*** ### MKE02Z16VLC4 "Cpu" init code ... ***/

  /*** PE initialization code after reset ***/

  SCB_VTOR = (uint32_t)(&__vect_table); /* Set the interrupt vector table position */

  /* Disable the WDOG module */

  /* WDOG_TOVAL: TOVAL=0xE803 */

  WDOG_TOVAL = WDOG_TOVAL_TOVAL(0xE803); /* Timeout value */

  /* WDOG_CS2: WIN=0,FLG=0,??=0,PRES=0,??=0,??=0,CLK=1 */

  WDOG_CS2 = WDOG_CS2_CLK(0x01);       /* 1-kHz clock source */

  /* WDOG_CS1: EN=0,INT=0,UPDATE=1,TST=0,DBG=0,WAIT=1,STOP=1 */

  WDOG_CS1 = WDOG_CS1_UPDATE_MASK |

             WDOG_CS1_TST(0x00) |

             WDOG_CS1_WAIT_MASK |

             WDOG_CS1_STOP_MASK;

 

  /* System clock initialization */

  /* SIM_BUSDIV: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,BUSDIV=1 */

  SIM_BUSDIV = SIM_BUSDIV_BUSDIV_MASK; /* Update system prescalers */

Where is the code?!

  /*** End of PE initialization code after reset ***/

  /*** !!! Here you can place your own code after PE initialization using property "User code after PE initialization" on the build options tab. !!! ***/

}

 

 

If you need any other information, please ask.

Thanks a lot!

Labels (1)
1 Solution
1,058 Views
marek_neuzil
NXP Employee
NXP Employee

Hello Daniel,

I have checked your issues:

Issue 1:

The Slow internal reference clock property provides support for ICS trim adjustment by other tools (e.g. debugger). The hint of this property states "It is responsibility of the user to correctly set the trim register." This property is only used for calculation of the clock frequencies (clock signals) that are based on this internal oscillator.

There is the Initialize slow trim value property group that allows you to set the exact values of trim registers but these values are not computed (it is your responsibility to set requested values of trim registers), see below:

pastedImage_5.png

The default value of the Slow Internal reference clock property contains factory trimmed value of the internal oscillator. But there is not any exact algorithm how to set trim value according to requested value (due to dispersion during manufacturing).

Therefore you can set the value that is in the defined range (defined in datasheet of the MCU and also provided in the hint of this property) and use debugger to adjust precise value of this internal oscillator. For example PEMicro provide the following advanced options (Program Trim Registers):

pastedImage_0.png

This feature allows you to precisely set the trim registers.

Issue 2:

I have reproduced the problem. When you select the FBELP ICS mode the Processor Expert does not set the ICS_C1 register in the generated code (it remain in the after reset state - FEI mode). I have reported this issue to the Processor Expert development team (PEXMCU-4163).

Best Regards,

Marek Neuzil

View solution in original post

8 Replies
1,058 Views
DavidS
NXP Employee
NXP Employee

Hi Daniel,

I am looking into this and will reply tomorrow.

Regards,

David

0 Kudos
1,058 Views
danielhulshof
Contributor II

Hello David!

Thanks for looking into it.

I've worked around issue 2 by adding the necessary code to the "Build Options" "User Initialization" tab.

I'm being forced to use an external oscillator because I couldn't get a stable enough PWM output for my Ultrasound movement sensor.

I need a very stable 40Khz on the transmitter for the receiver to work properly. We are actually migrating a product from an S08 micro-controller to the KE family, and we had the same problem previously. I was hopping for a more stable internal oscillator!

If you need anything, let me know.

Regards,

0 Kudos
1,058 Views
DavidS
NXP Employee
NXP Employee

Hi Daniel,

Correct that our internal ICR is not as stable/accurate as external clock.  What accuracy on PWM do you require for Ultrasound?

With respect to Question 1.  I too see that changing the "Slow internal reference clock [kHz]" does nothing to the code.  I will report that to the CodeWarrior Processor Expert team.

My workaround (for others that may wish to do this) is to leave it as the default 32.768kHz, run the application and halt, use the Register View to look at the Clock management (ICS) registers, then modify the ICS_C3 to find the correct SCTRIM setting.  This assumes you have enabled the Bus clock output pin under the Internal peripherals Properties of the CPU  component to watch the bus clock with oscope.

Then you need to add code in the CPU.c _init_hardware() function for run-time configuring or ICS_C3 and ICS_C4.

Ok...so not exactly the cleanest approach but ...

Negatives are that the factory trims the ICR to the 32.768kHz which implies each device could be slightly different and therefore probably a hassle for production.  I am guessing that this is the reason PE cannot actually change SCTRIM and therefore I conclude the "Slow internal reference clock [kHz]" should probably be a constant and not changeable.

So your using known external clock source resolves these hassles.

Regards,

David

Reference:

Issue PEXSUP-3 - CW10.6 PE for Kinetis MKE02Z64VLH4 (40MHZ) ICS setting does nothing has been successfully created.

0 Kudos
1,058 Views
danielhulshof
Contributor II

Hi David,

We have to keep the frequency variation under 1% because the sensitivity of the receiver drops very quickly outside the 40Khz ideal frequency.

Regarding "Issue 1" I agree with you, SCTRIM should not be messed with. I've tried it before as you described and could not get to the desired frequency (39.0625 Khz).

Regarding "Issue 2", is the FBELP mode generating the initialization code properly for you? Mine is not generating any code at all.

Thank you again!

0 Kudos
1,058 Views
DavidS
NXP Employee
NXP Employee

Hi Daniel,

For Issue 1 I was able to get very close to the 40MHz internal clock and 20MHz bus clock.  My Cpu.c attached.  You may have to tweak the SCTRIM value as compared to what I am using.

For Issue 2 I haven't tried.  Honestly I read your post quickly and figured since you had workaround you were good.  Do you need me to look into this?

Regards,

David

0 Kudos
1,058 Views
danielhulshof
Contributor II

Hi David,

I have worked around it, just trying to make sure it's not an issue with P.E. that should be reported.

Also, it's kind of a mess having to use "User Initialization" since it will always appear at Cpu.c even when I change the Clock Mode back to FEI.

Anyways, thanks a lot for your help!

0 Kudos
1,059 Views
marek_neuzil
NXP Employee
NXP Employee

Hello Daniel,

I have checked your issues:

Issue 1:

The Slow internal reference clock property provides support for ICS trim adjustment by other tools (e.g. debugger). The hint of this property states "It is responsibility of the user to correctly set the trim register." This property is only used for calculation of the clock frequencies (clock signals) that are based on this internal oscillator.

There is the Initialize slow trim value property group that allows you to set the exact values of trim registers but these values are not computed (it is your responsibility to set requested values of trim registers), see below:

pastedImage_5.png

The default value of the Slow Internal reference clock property contains factory trimmed value of the internal oscillator. But there is not any exact algorithm how to set trim value according to requested value (due to dispersion during manufacturing).

Therefore you can set the value that is in the defined range (defined in datasheet of the MCU and also provided in the hint of this property) and use debugger to adjust precise value of this internal oscillator. For example PEMicro provide the following advanced options (Program Trim Registers):

pastedImage_0.png

This feature allows you to precisely set the trim registers.

Issue 2:

I have reproduced the problem. When you select the FBELP ICS mode the Processor Expert does not set the ICS_C1 register in the generated code (it remain in the after reset state - FEI mode). I have reported this issue to the Processor Expert development team (PEXMCU-4163).

Best Regards,

Marek Neuzil

1,058 Views
marek_neuzil
NXP Employee
NXP Employee

Hello,

I have received the following workaround from the Processor Expert development team for the issue #2:

1 - Select the FBE mode of the ISC (select the FBE in the ICS mode property).

pastedImage_0.png

2 - Navigate to 'Build options' tab in the Components Inspector of the CPU. Find 'User code after PE initialization' property. Enter following code to the string list:

ICS_C2 |= ICS_C2_LP_MASK;

The property allows to generate any user code right at the end of __Init_hardware() function, where the clock are configured. The code sets low power mode, i.e. FBELP ICS mode.

pastedImage_1.png

The initialization code generated (CPU.c program module) by Processor Expert is:

void __init_hardware(void)

{

  . . .

  . . .

  /* System clock initialization */

  /* SIM_BUSDIV: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,BUSDIV=0 */

  SIM_BUSDIV = 0x00U;                  /* Update system prescalers */

  /* Switch to FBE Mode */

  /* ICS_C2: BDIV=0,LP=0 */

  ICS_C2 &= (uint8_t)~(uint8_t)((ICS_C2_BDIV(0x07) | ICS_C2_LP_MASK));

  /* OSC_CR: OSCEN=1,??=0,OSCSTEN=0,OSCOS=1,??=0,RANGE=1,HGO=0,OSCINIT=0 */

  OSC_CR = (OSC_CR_OSCEN_MASK | OSC_CR_OSCOS_MASK | OSC_CR_RANGE_MASK);

  /* ICS_C1: CLKS=2,RDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */

  ICS_C1 = (ICS_C1_CLKS(0x02) | ICS_C1_RDIV(0x03) | ICS_C1_IRCLKEN_MASK);

  while((ICS_S & ICS_S_IREFST_MASK) != 0x00U) { /* Check that the source of the FLL reference clock is the external reference clock. */

  }

  while((ICS_S & 0x0CU) != 0x08U) {    /* Wait until external reference clock is selected as ICS output */

  }

  /*** End of PE initialization code after reset ***/

  /*** User code after PE initialization and before C initialization ***/

  ICS_C2 |= ICS_C2_LP_MASK;

  /*** End of user code after PE initialization and before C initialization ***/

}

This code allows proper switching from the FBE mode to the FBELP mode according to the following diagram from the reference manual:

pastedImage_4.png

Best regards,

Marek Neuzil

0 Kudos