<?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: Periodic Interrupt Timer in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267679#M9886</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Timer overflow interrupt routine is called when main 16-bit free-running timer (TCNT) overflows from 0xFFFF to 0x0000. &lt;/P&gt;&lt;P&gt;For example: rising_edge = 0xF000; overflow = 3; falling_edge = 0x2000; then:&lt;/P&gt;&lt;P&gt;number_of_cycles = (0xFFFF * (unsigned long int)overflow) + falling_edge - rising_edge&lt;/P&gt;&lt;P&gt;number_of_cycles = (0xFFFF * 3) + 0x2000 - 0xF000 =&amp;nbsp; 0x22FFD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Back to your first question: Can we use PIT for such detection?&lt;/P&gt;&lt;P&gt;Idea 1: IC timer function (previous proposal)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Idea 2: We can connect signal from proximity sensor to port with pin interrupt (Ports P, H, and J). In interrupt routine we can start some output compare function for measuring 2s and set some flag. Timer interrupt will signalize 2s quiet on line and we should clear our flag. When pin interrupt occurs before 2s time interval (our flag is still set) finishes, we should reset OC timer for measuring 2s again. Note: pin interrupt could be set to rising or falling edge, unfortunately not simultaneously. Detected edge could be set by PPSP (PPSH, PPSJ) register.&lt;/P&gt;&lt;P&gt;Disadvantage: PIT is not suited for such general OC function (periodic interrupt) and 2s could be too long interval for ECT (we should work with overflow …).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Idea 3: We can connect signal from proximity sensor to port with pin interrupt as in case 2. We can configure PIT for generating interrupt with period for example 100ms. In PIT interrupt routine we will increment counter and when counter&amp;gt;=20 we should generate some action. In pin interrupt routine we will simply clear this counter (plus change polarity of detected edge).&lt;/P&gt;&lt;P&gt;Disadvantage: we measure 2s with maximum error = 100ms (periodic interruptionand edge detection are independent). So, question is how accuracy of this 2s interval you need. &lt;/P&gt;&lt;P&gt;Note: for this purpose you can use also RTI (real time interrupt).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found some similar example code for this case (Idea 3). I hope that help you.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 26 Feb 2013 23:35:09 GMT</pubDate>
    <dc:creator>RadekS</dc:creator>
    <dc:date>2013-02-26T23:35:09Z</dc:date>
    <item>
      <title>Periodic Interrupt Timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267673#M9880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone, &lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working on MC9S12XDT512 controller and i'm in particular dealing with timers. My requirement is that i need to measure how long my signal from the proximity sensor is ON and how long it is OFF. I've tried with the 16 bit TCNT register but i'm getting only the time when i my sensor detects an obstacle. Does using a periodic interrupt timer help? How do i use it?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 13:23:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267673#M9880</guid>
      <dc:creator>sreeharshak</dc:creator>
      <dc:date>2013-02-21T13:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Periodic Interrupt Timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267674#M9881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sree,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To answer your question, I really need some additional details.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is the signal from the proximity sensor a relatively clean digital signal?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What are the minimum and maximum on and off times you are trying to measure?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Gordon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 18:44:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267674#M9881</guid>
      <dc:creator>GordonD</dc:creator>
      <dc:date>2013-02-21T18:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Periodic Interrupt Timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267675#M9882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi :-)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, it is a clean digital signal. I get a logic 1 when there is no obstacle and i get a logic 0 when there is an obstacle. I am using this to detect if the wheel of my bike is stationary or not. So, i need to perform an action once i know that my wheel is stationary for 2 or more seconds. I will be continuously monitoring the proximity sensor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Feb 2013 07:14:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267675#M9882</guid>
      <dc:creator>sreeharshak</dc:creator>
      <dc:date>2013-02-25T07:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Periodic Interrupt Timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267676#M9883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PIT is suited for output compare function only (generate period). I think that it will be difficult to use PIT for measuring of pulse with.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I understood correctly, your problem with normal timer (ECT) is 2s interval = too long for TCNT timer. Correct?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In attachment you can find simple example code for measuring of pulse width by ECT module. This example code uses overflow interrupt for measuring longer pulses (longer than TCNT period). I suppose that you can simply modify this code for measuring both (0V and 5V) pulses.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also simply testing overflow variable for 2s limit in overflow interrupt routine.&lt;/P&gt;&lt;P&gt;Note: There is necessary take into account error of one TCNT period. If you want get better accuracy (of 2s limit), you should calculate with last value of TCx timer/resets TCx timer value….&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Feb 2013 16:06:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267676#M9883</guid>
      <dc:creator>RadekS</dc:creator>
      <dc:date>2013-02-25T16:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: Periodic Interrupt Timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267677#M9884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Radek :-)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You got my question right. Thanks for the help:-)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll try this method and will get back to you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Feb 2013 18:42:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267677#M9884</guid>
      <dc:creator>sreeharshak</dc:creator>
      <dc:date>2013-02-25T18:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Periodic Interrupt Timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267678#M9885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Radek :-)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've gone through your program. I have a few doubts. Can you tell me when exactly is the program executing the timer overflow interrupt? We first are going through the input capture interrupt and at exactly what point do we branch to the timer overflow interrupt? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I executed your program and it runs fine, I get my logic 1 and logic 0 detected if signal exists for greater than 2 seconds but this executes only once. I need to reset to detect my signal again. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can u please help me in my doubts in the first paragraph? Once i'm through that part, i feel i can manage the rest.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanking You, &lt;/P&gt;&lt;P&gt;Regards, &lt;/P&gt;&lt;P&gt;Harsha.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Feb 2013 15:04:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267678#M9885</guid>
      <dc:creator>sreeharshak</dc:creator>
      <dc:date>2013-02-26T15:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Periodic Interrupt Timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267679#M9886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Timer overflow interrupt routine is called when main 16-bit free-running timer (TCNT) overflows from 0xFFFF to 0x0000. &lt;/P&gt;&lt;P&gt;For example: rising_edge = 0xF000; overflow = 3; falling_edge = 0x2000; then:&lt;/P&gt;&lt;P&gt;number_of_cycles = (0xFFFF * (unsigned long int)overflow) + falling_edge - rising_edge&lt;/P&gt;&lt;P&gt;number_of_cycles = (0xFFFF * 3) + 0x2000 - 0xF000 =&amp;nbsp; 0x22FFD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Back to your first question: Can we use PIT for such detection?&lt;/P&gt;&lt;P&gt;Idea 1: IC timer function (previous proposal)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Idea 2: We can connect signal from proximity sensor to port with pin interrupt (Ports P, H, and J). In interrupt routine we can start some output compare function for measuring 2s and set some flag. Timer interrupt will signalize 2s quiet on line and we should clear our flag. When pin interrupt occurs before 2s time interval (our flag is still set) finishes, we should reset OC timer for measuring 2s again. Note: pin interrupt could be set to rising or falling edge, unfortunately not simultaneously. Detected edge could be set by PPSP (PPSH, PPSJ) register.&lt;/P&gt;&lt;P&gt;Disadvantage: PIT is not suited for such general OC function (periodic interrupt) and 2s could be too long interval for ECT (we should work with overflow …).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Idea 3: We can connect signal from proximity sensor to port with pin interrupt as in case 2. We can configure PIT for generating interrupt with period for example 100ms. In PIT interrupt routine we will increment counter and when counter&amp;gt;=20 we should generate some action. In pin interrupt routine we will simply clear this counter (plus change polarity of detected edge).&lt;/P&gt;&lt;P&gt;Disadvantage: we measure 2s with maximum error = 100ms (periodic interruptionand edge detection are independent). So, question is how accuracy of this 2s interval you need. &lt;/P&gt;&lt;P&gt;Note: for this purpose you can use also RTI (real time interrupt).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found some similar example code for this case (Idea 3). I hope that help you.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Feb 2013 23:35:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267679#M9886</guid>
      <dc:creator>RadekS</dc:creator>
      <dc:date>2013-02-26T23:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Periodic Interrupt Timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267680#M9887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much for such a detail explanation :-) i've done a few modifications and i'm now getting the response the way i wanted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for all the help :-) learnt a lot from your response. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Feb 2013 06:38:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Periodic-Interrupt-Timer/m-p/267680#M9887</guid>
      <dc:creator>sreeharshak</dc:creator>
      <dc:date>2013-02-27T06:38:47Z</dc:date>
    </item>
  </channel>
</rss>

