<?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 Extending Input Capture using timer overflow. in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Extending-Input-Capture-using-timer-overflow/m-p/196577#M15715</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Does anyone have experience extending a timer using the overflow interrupt, say to 24 or 32-bits and beyond?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the HCS08 TPM modules.&amp;nbsp; I have never done this and I am concerned about&amp;nbsp;any pitfalls.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One&amp;nbsp;concern would be using the timer within&amp;nbsp;a non-related&amp;nbsp;interrupt&amp;nbsp;just before or after the overflow occurs, and&amp;nbsp;then having a discontinuity problem.&amp;nbsp; If I am in an interrupt then I won't be able to service the overflow interrupt to increment the extending count unless I unmask the interrupts temporarily, but this could have other undesirable affects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want to&amp;nbsp;add a bunch of strange code to get this to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm trying to accomplish is extending the Input Capture to 24-bits.&amp;nbsp; I need the fine sub-microsecond accuracy, but I also need the extended&amp;nbsp;time of up to 250ms.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any insight or experience that anyone can share would be great.&amp;nbsp; Thanks.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Jan 2012 14:32:32 GMT</pubDate>
    <dc:creator>jgirard1</dc:creator>
    <dc:date>2012-01-10T14:32:32Z</dc:date>
    <item>
      <title>Extending Input Capture using timer overflow.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Extending-Input-Capture-using-timer-overflow/m-p/196577#M15715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Does anyone have experience extending a timer using the overflow interrupt, say to 24 or 32-bits and beyond?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the HCS08 TPM modules.&amp;nbsp; I have never done this and I am concerned about&amp;nbsp;any pitfalls.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One&amp;nbsp;concern would be using the timer within&amp;nbsp;a non-related&amp;nbsp;interrupt&amp;nbsp;just before or after the overflow occurs, and&amp;nbsp;then having a discontinuity problem.&amp;nbsp; If I am in an interrupt then I won't be able to service the overflow interrupt to increment the extending count unless I unmask the interrupts temporarily, but this could have other undesirable affects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want to&amp;nbsp;add a bunch of strange code to get this to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm trying to accomplish is extending the Input Capture to 24-bits.&amp;nbsp; I need the fine sub-microsecond accuracy, but I also need the extended&amp;nbsp;time of up to 250ms.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any insight or experience that anyone can share would be great.&amp;nbsp; Thanks.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jan 2012 14:32:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Extending-Input-Capture-using-timer-overflow/m-p/196577#M15715</guid>
      <dc:creator>jgirard1</dc:creator>
      <dc:date>2012-01-10T14:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Extending Input Capture using timer overflow.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Extending-Input-Capture-using-timer-overflow/m-p/196578#M15716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jgirard,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, I have been doing this since 1985. It really is pretty easy, but there are rules that I need to follow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First, I allocate one or two bytes of page zero ram for the timer-extension. I have a timer-overflow ISR that increments the extension (either a single INC instruction or three instructions), and also queues an overflow task to run (a single BSET instruction). That task may or may not do anything, but I schedule it anyway. Typically, it just keeps time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Most of the time I am using the timer with the compare function, which allows me to schedule tasks up to 2.38 hours into the future (with the old HC05 timer at its fixed 2 microsecond resolution, ~8 overflows per second). Usually, a single byte of extension is adequate for me. At a 10mHz count rate, a single byte will get you 1 2/3 seconds before a single-byte timer-extension overflows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input-Capture is trickier, as the edge interrupt has a higher priority than the overflow interrupt. If you tried to process your capture totally inside the ISR, you could have a coherency problem. My "rule" of processing outside of the ISR addresses that issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are some of the rules that I need to follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No interrupt service routine may take longer than 5 microseconds. This is to insure that interrupt latency stays reasonably short. 5 microseconds allows me to run two SCI modules at a megabit/second.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All ISRs do only what it takes to clear the interrupt, and then request a processing task to do the bulk of the work (again, a single BSET instruction). So almost all processing is done outside of ISRs where interrupts are enabled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No decisions are ever made inside an ISR, where things might not be coherent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any variables that are accessed inside an ISR are treated as critical-sections outside the ISR. That simply means that interrupts need to be disabled during their accesses (typically for less than a microsecond). Again, for coherency.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With those rules you can be assured that, should an overflow and a capture occur near simultaneously, both ISRs will have been executed before you process the capture (outside any ISR). You still need to determine which event happened first, and I use the high-bit of the 16-bit capture data to make that determination.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is simply how I do it. There are plenty of other ways. This way is very easy for me because I have had the code for years and I program in assembly language. It would probably be more difficult in C.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jan 2012 15:52:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Extending-Input-Capture-using-timer-overflow/m-p/196578#M15716</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2012-01-10T15:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Extending Input Capture using timer overflow.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Extending-Input-Capture-using-timer-overflow/m-p/196579#M15717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will assume that tor each TPM overflow interrupt, a 8-bit or 16-bit counter is incremented, and the overflow flag is cleared.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The&amp;nbsp;primary issue is that the input capture event is not subject to latency, whereas the overflow event processing will be subject to some degree of latency.&amp;nbsp; The question then arises whether, because of this latency, the counter value should be further incremented or not, for the calculation of the period.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the overflow interrupt has not yet been processed, at the time when the input capture event is processed, the additional increment will possibly be required.&amp;nbsp; If the overflow flag is tested within the capture ISR, this will show if there is an unprocessed overflow event.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We then need to determine whether&amp;nbsp;the unprocessed overflow&amp;nbsp;occurred prior to, or after the capture event.&amp;nbsp; If the capture value is&amp;nbsp;"high", this wouldl indicate capture prior to the&amp;nbsp;overflow.&amp;nbsp; If the capture value is "low", this would indicate that the counter should be further incremented.&amp;nbsp; The low threshold might conceivably be any capture value less than 0x8000, which should allow plenty of&amp;nbsp;scope for any latency.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jan 2012 18:30:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Extending-Input-Capture-using-timer-overflow/m-p/196579#M15717</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2012-01-10T18:30:59Z</dc:date>
    </item>
  </channel>
</rss>

