<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help with oscilator problem on Kinetis K40 in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-oscilator-problem-on-Kinetis-K40/m-p/175196#M1449</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry .. the problem is at the line:&amp;nbsp;while (((MCG_S &amp;amp; MCG_S_CLKST_MASK) &amp;gt;&amp;gt; MCG_S_CLKST_SHIFT) != 0x3){}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Oct 2011 00:05:47 GMT</pubDate>
    <dc:creator>luisf_rossi</dc:creator>
    <dc:date>2011-10-20T00:05:47Z</dc:date>
    <item>
      <title>Help with oscilator problem on Kinetis K40</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-oscilator-problem-on-Kinetis-K40/m-p/175195#M1448</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi i am working on a custom design with a PK40N512. I want to run my core at 100Mhz., however i got a weird problem. The circuit i am using at the crystal is attached for reference. My crystal is a 4MHz one (ATS040SM) and the R1 resistor is 1M Ohm.&lt;/P&gt;&lt;P&gt;The problem is the following. If i place a 0R resistor at R2, for some reason the Kinetis run at half of the frequency (from the flash and from the RAM). I am measuring it using the PIT module. However, if i place a 390R resistor, the circuit run at the right frequency (100Mhz) when running from the RAM, but hangs at the external referencen initialization when running from the flash.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My initialization code is the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#pragma section CopyToRAM beginvoid clock_init(void){// If the internal load capacitors are being used, they should be selected// before enabling the oscillator. Application specific. 16pF and 8pF selected// in this example//  OSC_CR = OSC_CR_SC16P_MASK | OSC_CR_SC8P_MASK;// Enabling the oscillator for 8 MHz crystal// RANGE=1, should be set to match the frequency of the crystal being used// HGO=1, high gain is selected, provides better noise immunity but does draw// higher current// EREFS=1, enable the external oscillator// LP=0, low power mode not selected (not actually part of osc setup)// IRCS=0, slow internal ref clock selected (not actually part of osc setup)  OSC_CR = (uint8_t)0xA0U;  MCG_C2 = MCG_C2_RANGE(1) | MCG_C2_HGO_MASK | MCG_C2_EREFS_MASK;// Select ext oscillator, reference divider and clear IREFS to start ext osc// CLKS=2, select the external clock source// FRDIV=3, set the FLL ref divider to keep the ref clock in range//         (even if FLL is not being used) 8 MHz / 256 = 31.25 kHz// IREFS=0, select the external clock// IRCLKEN=0, disable IRCLK (can enable it if desired)// IREFSTEN=0, disable IRC in stop mode (can keep it enabled in stop if desired)  MCG_C1 = MCG_C1_CLKS(2) | MCG_C1_FRDIV(4);// wait for oscillator to initialize  while (!(MCG_S &amp;amp; MCG_S_OSCINIT_MASK)){}// wait for Reference clock to switch to external reference  while (MCG_S &amp;amp; MCG_S_IREFST_MASK){}// Wait for MCGOUT to switch over to the external reference clock  while (((MCG_S &amp;amp; MCG_S_CLKST_MASK) &amp;gt;&amp;gt; MCG_S_CLKST_SHIFT) != 0x2){}// Now configure the PLL and move to PBE mode// set the PRDIV field to generate a 4MHz reference clock (8MHz /2)  SIM_SOPT2 &amp;amp;= (uint8_t)~(uint8_t)0x01U;  MCG_C5 = MCG_C5_PRDIV(0); // PRDIV=1 selects a divide by 2// set the VDIV field to 0, which is x24, giving 4 x 24  = 96 MHz// the PLLS bit is set to enable the PLL// the clock monitor is enabled, CME=1 to cause a reset if crystal fails// LOLIE can be optionally set to enable the loss of lock interrupt  MCG_C6 = MCG_C6_CME_MASK | MCG_C6_PLLS_MASK | MCG_C6_VDIV(1);// wait until the source of the PLLS clock has switched to the PLL  while (!(MCG_S &amp;amp; MCG_S_PLLST_MASK)){}// wait until the PLL has achieved lock  while (!(MCG_S &amp;amp; MCG_S_LOCK_MASK)){}// set up the SIM clock dividers BEFORE switching to the PLL to ensure the// system clock speeds are in spec.// core = PLL (96MHz), bus = PLL/2 (48MHz), flexbus = PLL/2 (48MHz), flash = PLL/4 (24MHz)  SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1)              | SIM_CLKDIV1_OUTDIV3(1) | SIM_CLKDIV1_OUTDIV4(3);// Transition into PEE by setting CLKS to 0// previous MCG_C1 settings remain the same, just need to set CLKS to 0  MCG_C1 &amp;amp;= ~MCG_C1_CLKS_MASK;// Wait for MCGOUT to switch over to the PLL  while (((MCG_S &amp;amp; MCG_S_CLKST_MASK) &amp;gt;&amp;gt; MCG_S_CLKST_SHIFT) != 0x3){}// The USB clock divider in the System Clock Divider Register 2 (SIM_CLKDIV2)// should be configured to generate the 48 MHz USB clock before configuring// the USB module.    SIM_CLKDIV2 |= SIM_CLKDIV2_USBDIV(1); // sets USB divider to /2 assuming reset          // state of the SIM_CLKDIV2 register    SIM_SCGC5 |= (uint32_t)0x0200UL;     /* Enable clock gate for ports to enable pin routing */    SIM_SOPT2 &amp;amp;= (uint8_t)~(uint8_t)0x01U;}#pragma section CopyToRAM end&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;My linker got the following lines added from the basic one:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;_ROMCodeToCopy = ___ROM_AT + SIZEOF(.app_data);&lt;BR /&gt;.copyToRAM: AT(_ROMCodeToCopy) {&lt;BR /&gt;. = ALIGN (0x4);&lt;BR /&gt;__START_COPYTORAM = .;&lt;BR /&gt;*(CopyToRAM)&lt;BR /&gt;__END_COPYTORAM = .;&lt;BR /&gt;} &amp;gt;&amp;gt; m_data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is at the line with the following code:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  while (((MCG_S &amp;amp; MCG_S_CLKST_MASK) &amp;gt;&amp;gt; MCG_S_CLKST_SHIFT) != 0x2){}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea of what is the problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:23:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-oscilator-problem-on-Kinetis-K40/m-p/175195#M1448</guid>
      <dc:creator>luisf_rossi</dc:creator>
      <dc:date>2020-10-29T09:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Help with oscilator problem on Kinetis K40</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-oscilator-problem-on-Kinetis-K40/m-p/175196#M1449</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry .. the problem is at the line:&amp;nbsp;while (((MCG_S &amp;amp; MCG_S_CLKST_MASK) &amp;gt;&amp;gt; MCG_S_CLKST_SHIFT) != 0x3){}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2011 00:05:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-oscilator-problem-on-Kinetis-K40/m-p/175196#M1449</guid>
      <dc:creator>luisf_rossi</dc:creator>
      <dc:date>2011-10-20T00:05:47Z</dc:date>
    </item>
  </channel>
</rss>

