<?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: Very short delays(us) with TPM Module in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224158#M4239</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Diego,&lt;/P&gt;&lt;P&gt;I'm not sure that whether I've figured out the problem. Could you please upload your project? If I have your project, it's convenience to me for confirm the problem is right or not.&lt;/P&gt;&lt;P&gt;I'm looking forward to your reply.&lt;/P&gt;&lt;P&gt;Have a nice day!&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Ping&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 19 Feb 2014 08:49:44 GMT</pubDate>
    <dc:creator>jeremyzhou</dc:creator>
    <dc:date>2014-02-19T08:49:44Z</dc:date>
    <item>
      <title>Very short delays(us) with TPM Module</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224156#M4237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi to everybody here&lt;/P&gt;&lt;P&gt;Please, hints needed.&lt;/P&gt;&lt;P&gt;I want to implement precise delays from few us to 100us.This is for squeezing&amp;nbsp; consumption optimization in some peripheral ,following directives of a co-worker.&lt;/P&gt;&lt;P&gt;Of course it is not a disaster if i would wait 5us instead of 3us in some sequence.But it is mostly for me ,to learn to use the timer correctly.&lt;/P&gt;&lt;P&gt;Now i'm using a Freedom Board KL05Z,with core,bus and TPM clock=20.97 MHz,global optimization level=0&lt;/P&gt;&lt;P&gt;NB:the TPM0 prescaler is set to 0&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did a simple C function acting on TPM0 registers:&lt;/P&gt;&lt;PRE class="c++" name="code"&gt;void Mydelay_usec(unsigned int del) { &amp;nbsp; TPM0_MOD=del; &amp;nbsp; TPM0_CNT =0x00;//clean counter &amp;nbsp; TPM0_SC&amp;nbsp;&amp;nbsp; |=TPM_SC_CMOD(0x01)|TPM_SC_TOF_MASK ;//inc. on every edge,clean overflow flag,up &amp;nbsp; while(!(TPM0_SC &amp;amp; TPM_SC_TOF_MASK) );//wait for overflow &amp;nbsp; TPM0_SC&amp;nbsp;&amp;nbsp; &amp;amp;=~(TPM_SC_CMOD_MASK);//stop the timer }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I measure the delay by reading a&amp;nbsp; pulse width on a pin on the oscilloscope :&lt;/P&gt;&lt;PRE class="c++" name="code"&gt;GPIOB_PDOR &amp;amp;=~0x200; Mydelay_usec((test_var);//&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;nbsp; GPIOB_PDOR |=0x200;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P&gt;I leave the function empty ,just to measure the time needed to call it ,and to switch the test pin.The pulse width is &lt;STRONG&gt;1.5us&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="css" name="code"&gt;void Mydelay_usec(unsigned int del){}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P&gt;...i expected something less&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the function complete,if i call it with input parameter=1, the resulting time is about &lt;STRONG&gt;4.1us&lt;/STRONG&gt; that lowers to &lt;STRONG&gt;3us&lt;/STRONG&gt; with global optimization level=3&lt;/P&gt;&lt;P&gt;I don't have experience of ARM assembly.Looking the content of my function not far form assembly level, i expected less assembly instructions(see the alleged file).&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another issue is that incrementing the MOD value&amp;nbsp; by 1,does not correspond to a progressive increment of the pulse width-&lt;/P&gt;&lt;P&gt;It looks,that the overflow,and the related pulse width are varying only when the MOD increases by 8 (?) units.&lt;/P&gt;&lt;P&gt;I guess this is because of the time between two checks of the TOF flag in the while(..) loop,that is too long to resolve a count of few units.&lt;/P&gt;&lt;P&gt;So a loop shorter than a TPM count is needed, but this is impossible unless i slow the count with a prescaler.&lt;/P&gt;&lt;P&gt;What is the right approach in this case?Interrupt?I should ever check some flag changed by the ISR..&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all.&lt;/P&gt;&lt;P&gt;Diego&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-337696" rel="nofollow noopener noreferrer" target="_blank"&gt;assembly.txt.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Feb 2014 13:03:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224156#M4237</guid>
      <dc:creator>diegocolombo</dc:creator>
      <dc:date>2014-02-11T13:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Very short delays(us) with TPM Module</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224157#M4238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Diego,&lt;/P&gt;&lt;P&gt;I've been working on your&amp;nbsp; now and I'll reply as soon as possible if I work it out.&lt;/P&gt;&lt;P&gt;So be patient.&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Ping&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Feb 2014 06:23:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224157#M4238</guid>
      <dc:creator>jeremyzhou</dc:creator>
      <dc:date>2014-02-18T06:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Very short delays(us) with TPM Module</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224158#M4239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Diego,&lt;/P&gt;&lt;P&gt;I'm not sure that whether I've figured out the problem. Could you please upload your project? If I have your project, it's convenience to me for confirm the problem is right or not.&lt;/P&gt;&lt;P&gt;I'm looking forward to your reply.&lt;/P&gt;&lt;P&gt;Have a nice day!&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Ping&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Feb 2014 08:49:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224158#M4239</guid>
      <dc:creator>jeremyzhou</dc:creator>
      <dc:date>2014-02-19T08:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Very short delays(us) with TPM Module</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224159#M4240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for working on it,Ping.&lt;/P&gt;&lt;P&gt;I'll'do it as soon as possible,once&amp;nbsp; i have cleaned up&amp;nbsp; the unnecessary parts just to focus on the item.&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Feb 2014 13:42:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224159#M4240</guid>
      <dc:creator>diegocolombo</dc:creator>
      <dc:date>2014-02-19T13:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Very short delays(us) with TPM Module</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224160#M4241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Diego,&lt;/P&gt;&lt;P&gt;I'm glad to hear your news and I'm also looking forward to your demo code.&lt;/P&gt;&lt;P&gt;Have a nice day!&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Ping &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Feb 2014 09:32:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224160#M4241</guid>
      <dc:creator>jeremyzhou</dc:creator>
      <dc:date>2014-02-21T09:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Re: Very short delays(us) with TPM Module</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224161#M4242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry i just found the time to resume the code today ,in the very early morning-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In ProcessorExpert.c i call the delay function ,i check on the oscilloscope the duration of the pulses&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13941855017452504" jivemacro_uid="_13941855017452504" modifiedtitle="true"&gt;
&lt;P&gt;PinScope_SetVal();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; McuWaitUs(50);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; PinScope_ClrVal();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; McuWaitUs(80);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; PinScope_SetVal();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; McuWaitUs(10);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; PinScope_ClrVal();&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i don't pretend to have actually the duration in microseconds,even in this case i would need a macro to calculate the right value of the parameter eg:&lt;/P&gt;&lt;P&gt;McuWaitUs(CONVERT_FOR_REAL_US_VALUE(14)) depending by clock frequency ,prescalers etc&lt;/P&gt;&lt;P&gt;Furtermore time is neede to call the function and passing the parameter.&lt;/P&gt;&lt;P&gt;But i would like to be able to measure &lt;STRONG&gt;increments&lt;/STRONG&gt; of 1us of the delay time.&lt;/P&gt;&lt;P&gt;This looks possible,i need to increase the parameter from 50 to 80 to see someting more than 1us increase,not bad.&lt;/P&gt;&lt;P&gt;Anyway many intermediate values gives the same delay,i guess this is becaus the loops that checks the flag&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13941868914062225" jivemacro_uid="_13941868914062225" modifiedtitle="true"&gt;
&lt;P&gt;while(!(TPM0_SC &amp;amp; TPM_SC_TOF_MASK) );//wait for overflow&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;is much longer than the increses in TPM count,so a shorter loop would be needed-I'm i right?&lt;/P&gt;&lt;P&gt;Wich is the best way (in assembly?) to obtain it?&lt;/P&gt;&lt;P&gt;Thank you again and i apologize for my late reply to this topic&lt;/P&gt;&lt;P&gt;Diego&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;McuWaitUs(14);&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Mar 2014 10:10:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224161#M4242</guid>
      <dc:creator>diegocolombo</dc:creator>
      <dc:date>2014-03-07T10:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: Very short delays(us) with TPM Module</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224162#M4243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Diego,&lt;/P&gt;&lt;P&gt;Thanks for your reply. I also aggree with your opinion the loops that checks the overflow flag cost much longer than the increses in TPM count.&lt;/P&gt;&lt;P&gt;So 1us can't be calculated just by clock frequency and prescale parameter and I'd like to suggest two methods for you.&lt;/P&gt;&lt;P&gt;One method is using interrupt which could avoid the loop, another method is using systick to implement precise delay as the replacement of TPM.&lt;/P&gt;&lt;P&gt;You could chck the detail describtion of systick for KL through the thread as follow.&lt;/P&gt;&lt;P&gt;&lt;A __default_attr="350275" __jive_macro_name="message" class="jive_macro_message jive_macro" href="https://community.nxp.com/"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Ping&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2014 08:05:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Very-short-delays-us-with-TPM-Module/m-p/224162#M4243</guid>
      <dc:creator>jeremyzhou</dc:creator>
      <dc:date>2014-03-10T08:05:46Z</dc:date>
    </item>
  </channel>
</rss>

