Adjusting crystal load capacitors.

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Adjusting crystal load capacitors.

跳至解决方案
1,404 次查看
brad_ci
Contributor II

I've got a custom K10 based board running well on a modified K40 BSP and PSP. I have a question relating to the Kinetis's built in load capacitors for the external crystal. I couldn't not find any location in the code where these caps are configiured. I find this odd, because the K40 Tower board that the BSP was written for doesn't include any load caps for the crystal, so it must be using the caps internal to the MCU. But where in the code are they configured?

 

My board seems to work fine, but I'd rather know where I can safely adjust the crystal's load caps to ensure I'm getting the best stability.

 

Thanks,

 

Brad

0 项奖励
回复
1 解答
948 次查看
MarkP_
Contributor V

Hi,

the header MK40X256VMD100.h comes from directory ...\Freescale MQX 3.7\mqx\source\psp\cortex.

Add the line:

    OSC_CR = OSC_CR_SC8P_MASK | OSC_CR_SC4P_MASK;

into init_hw.c:smileytongue:ll_init().

 

Don't know exact location, I would try after MCG_C2 setting:

    MCG_C2 = MCG_C2_RANGE(2) | MCG_C2_HGO_MASK | MCG_C2_EREFS_MASK | MCG_C2_IRCS_MASK;
    OSC_CR = OSC_CR_SC8P_MASK | OSC_CR_SC4P_MASK;

BSP uses PSP\cortex directory for include files. Check this:

Project properties -> C/C++ Build -> Settings -> ARM Compiler -> Input -> Include Search Paths

contains directory "${MQX_ROOT_DIR}\mqx\source\psp}cortex

~Mark

 

在原帖中查看解决方案

0 项奖励
回复
4 回复数
948 次查看
MarkP_
Contributor V

Hi Brad,

how did you change the Clock oscillator to Crystal?

Did you change the register configuration in pll_init() function?

 

K10 Datasheet describes register 25.7.1 OSC Control Register (OSC_CR)
SC2P: Add 2 pF capacitor to the oscillator load.


Header MK10X256VMD100.h has #define OSC_CR_SC16P_MASK etc.

Obviously there isn't any function for setting those.

 

I think you can set those in pll_init, e.g. set 12 pF caps:

OSC_CR = OSC_CR_SC8P_MASK | OSC_CR_SC4P_MASK

 

I use the bsp_twrk60n512_pe, it has the cap configuration directly in Component Inspector.

~Mark

 

0 项奖励
回复
948 次查看
brad_ci
Contributor II

I'm not sure what you mean by "how did I change the Clock oscillator to Crystal". The TWR K40 board that I stole the BSP from uses a crystal, so I didn't change anything of the sort.

 

I did change the clock-related defines (BSP_CLOCK_SRC, BSP_REF_CLOCK_SRC, BSP_CLOCK_MUL) to match my board though.

 

The BSP I'm using (twrk40x256) doesn't have any defines related to OSC_CR anywhere. I was considering manually adding code to set OSC_CR in the pll_init() function, but I wasn't sure if I should. Like I said, I figured that the BSP must already do it somewhere. But maybe not? I'm kinda confused as to how it's even working in the first place then.

 

I'm not using the PE BSPs, and I think it's too late for me to change.

0 项奖励
回复
949 次查看
MarkP_
Contributor V

Hi,

the header MK40X256VMD100.h comes from directory ...\Freescale MQX 3.7\mqx\source\psp\cortex.

Add the line:

    OSC_CR = OSC_CR_SC8P_MASK | OSC_CR_SC4P_MASK;

into init_hw.c:smileytongue:ll_init().

 

Don't know exact location, I would try after MCG_C2 setting:

    MCG_C2 = MCG_C2_RANGE(2) | MCG_C2_HGO_MASK | MCG_C2_EREFS_MASK | MCG_C2_IRCS_MASK;
    OSC_CR = OSC_CR_SC8P_MASK | OSC_CR_SC4P_MASK;

BSP uses PSP\cortex directory for include files. Check this:

Project properties -> C/C++ Build -> Settings -> ARM Compiler -> Input -> Include Search Paths

contains directory "${MQX_ROOT_DIR}\mqx\source\psp}cortex

~Mark

 

0 项奖励
回复
948 次查看
brad_ci
Contributor II

Well I added "OSC_CR = OSC_CR_SC16P_MASK | OSC_CR_SC2P_MASK;" after the MCG_C2 line like you suggested. (before creating this thread I was considering adding it just before that line, so pretty close). Not sure if it is "correct" or not, but the board still boots, so that's always good.

 

Thanks for your input.

 

Brad

0 项奖励
回复