<?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: Why do I need a delay after PIT clock enable? in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-do-I-need-a-delay-after-PIT-clock-enable/m-p/327309#M15115</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Charles&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See Errata to the mask 0M50M (valid for the K22)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="pastedImage_0.png"&gt;&lt;IMG alt="pastedImage_0.png" src="https://community.nxp.com/t5/image/serverpage/image-id/50676i9C6BA60A613B5D78/image-size/large?v=v2&amp;amp;px=999" title="pastedImage_0.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jiveImage" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;Code from uTasker framework:&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14245795729803547" jivemacro_uid="_14245795729803547"&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; POWER_UP(6, SIM_SCGC6_PIT);&amp;nbsp;&amp;nbsp; // ensure the PIT module is powered up&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #if defined ERRATA_ID_7914&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (void)PIT_MCR;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // dummy read of PIT_MCR to guaranty a minimum delay of two bus cycles after enabling the clock gate and not losing next write&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #endif&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PIT_MCR = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // ensure the PIT module is clocked&lt;/P&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kinetis: &lt;A href="http://www.utasker.com/kinetis.html" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank" title="http://www.utasker.com/kinetis.html"&gt;µTasker Kinetis support&lt;/A&gt;&lt;/P&gt;&lt;P&gt;K22: &lt;A href="http://www.utasker.com/kinetis/FRDM-K22F.html" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank" title="http://www.utasker.com/kinetis/FRDM-K22F.html"&gt;µTasker Kinetis FRDM-K22F support&lt;/A&gt; / &lt;A href="http://www.utasker.com/kinetis/TWR-K22F120M.html" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank" title="http://www.utasker.com/kinetis/TWR-K22F120M.html"&gt;µTasker Kinetis TWR-K22F120M support&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Kinetis Hardware Timers and PWM - &lt;A href="http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank" title="http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF"&gt;http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For the complete "out-of-the-box" Kinetis experience and faster time to market&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Nov 2020 13:10:20 GMT</pubDate>
    <dc:creator>mjbcswitzerland</dc:creator>
    <dc:date>2020-11-02T13:10:20Z</dc:date>
    <item>
      <title>Why do I need a delay after PIT clock enable?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-do-I-need-a-delay-after-PIT-clock-enable/m-p/327308#M15114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried to write an application that uses PIT interrupt and I ran into trouble. I noticed that the timers do not advance. So I started to investigate what is wrong, printing register values. It turns out that if there is no delay after the line&lt;SPAN style="font-size: 13.3333330154419px;"&gt; "SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;" the PIT_MCR somehow ends up with the value 2 and the timer does not advance. This happens even when commenting a couple of the "&lt;SPAN style="font-size: 13.3333330154419px;"&gt;__asm("nop"); " lines. However, with this 8-line delay everything works OK, with the PIT_MCR having value 0 and timer advancing normally.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;My setup is the same as with "Writing my first KSDK Application in KDS - Hello World and Toggle LED with GPIO Interrupt", with exception that I work with FRDM-K22F, KDS 2.0.0, KSDK 1.1.0. I flash the firmware using PEMicro/OpenSDA. My plan is to investigate assembly code next but I thought that there is a good chance someone will provide an answer here.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#include "fsl_device_registers.h"&lt;/P&gt;&lt;P&gt;#include "board.h"&lt;/P&gt;&lt;P&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int main(void)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; hardware_init();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; dbg_uart_init();&lt;/P&gt;&lt;P&gt;&amp;nbsp; SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Enable the clock to the PIT module&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm("nop");&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // I have no idea why I need this delay :-(&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm("nop");&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // but without these lines timer does not advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm("nop");&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // I had a printf here before and everything started to work&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm("nop");&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // so I put these lines to investigate how long of a delay is needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm("nop");&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm("nop");&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm("nop");&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm("nop");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PIT_MCR = 0x00; //Enable PIT module&lt;/P&gt;&lt;P&gt;&amp;nbsp; PIT_LDVAL1 = 8000000; //PIT Load value&lt;/P&gt;&lt;P&gt;&amp;nbsp; PIT_TCTRL1 |= PIT_TCTRL_TEN_MASK; // start Timer 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf("Register&amp;nbsp;&amp;nbsp; address&amp;nbsp; value\n\r");&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf("SIM_SCGC6&amp;nbsp; %08x %08X\n\r",&amp;amp;SIM_SCGC6, SIM_SCGC6);&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf("PIT_MCR&amp;nbsp;&amp;nbsp;&amp;nbsp; %08x %08X\n\r",&amp;amp;PIT_MCR, PIT_MCR);&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf("PIT_LDVAL1 %08x %08X\n\r",&amp;amp;PIT_LDVAL1, PIT_LDVAL1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf("PIT_TCTRL1 %08x %08X\n\r",&amp;amp;PIT_TCTRL1, PIT_TCTRL1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf("PIT_CVAL1&amp;nbsp; %08x %08X\n\r",&amp;amp;PIT_CVAL1, PIT_CVAL1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; while(1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; return 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 22 Feb 2015 03:32:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-do-I-need-a-delay-after-PIT-clock-enable/m-p/327308#M15114</guid>
      <dc:creator>charleszimnicki</dc:creator>
      <dc:date>2015-02-22T03:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Why do I need a delay after PIT clock enable?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-do-I-need-a-delay-after-PIT-clock-enable/m-p/327309#M15115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Charles&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See Errata to the mask 0M50M (valid for the K22)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="pastedImage_0.png"&gt;&lt;IMG alt="pastedImage_0.png" src="https://community.nxp.com/t5/image/serverpage/image-id/50676i9C6BA60A613B5D78/image-size/large?v=v2&amp;amp;px=999" title="pastedImage_0.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jiveImage" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;Code from uTasker framework:&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14245795729803547" jivemacro_uid="_14245795729803547"&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; POWER_UP(6, SIM_SCGC6_PIT);&amp;nbsp;&amp;nbsp; // ensure the PIT module is powered up&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #if defined ERRATA_ID_7914&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (void)PIT_MCR;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // dummy read of PIT_MCR to guaranty a minimum delay of two bus cycles after enabling the clock gate and not losing next write&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #endif&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PIT_MCR = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // ensure the PIT module is clocked&lt;/P&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kinetis: &lt;A href="http://www.utasker.com/kinetis.html" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank" title="http://www.utasker.com/kinetis.html"&gt;µTasker Kinetis support&lt;/A&gt;&lt;/P&gt;&lt;P&gt;K22: &lt;A href="http://www.utasker.com/kinetis/FRDM-K22F.html" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank" title="http://www.utasker.com/kinetis/FRDM-K22F.html"&gt;µTasker Kinetis FRDM-K22F support&lt;/A&gt; / &lt;A href="http://www.utasker.com/kinetis/TWR-K22F120M.html" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank" title="http://www.utasker.com/kinetis/TWR-K22F120M.html"&gt;µTasker Kinetis TWR-K22F120M support&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Kinetis Hardware Timers and PWM - &lt;A href="http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank" title="http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF"&gt;http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For the complete "out-of-the-box" Kinetis experience and faster time to market&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Nov 2020 13:10:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-do-I-need-a-delay-after-PIT-clock-enable/m-p/327309#M15115</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2020-11-02T13:10:20Z</dc:date>
    </item>
  </channel>
</rss>

