<?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>8-bit MicrocontrollersのトピックRe: Unexpected Disabling of interrupt</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155895#M8896</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Kef, Lundina and BigMac,&lt;/P&gt;&lt;P&gt;I am really sorry as i mistyped the main thing. Once again ask you to forgive me please.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Exact&amp;nbsp;PseudoCode :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Main:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if((System Input Conditions) &amp;amp;&amp;amp; (InterruptStatus == DISABLED))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Switch ON the Port Pin;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TPM2CH1IF = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable the Compare Interrupt */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2CH1IE = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Flag holding the status of Timer Interrupt */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InterruptStatus = ENABLED;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM1C1V = TPM1CNT + One Ms Equivalent Count;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ISR:&lt;/P&gt;&lt;P&gt;{&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; /*&amp;nbsp;Interrupt Flag clearing mechanism */&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DummyVariable = TPM2CH1SC;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2CH1IF = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Disabling the interrupt */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2CH1IE = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InterruptStatus = DISABLED;&lt;/P&gt;&lt;P&gt;&amp;nbsp;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your replies and please let me know the views on this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 21 Nov 2009 15:41:22 GMT</pubDate>
    <dc:creator>TDKamalAru</dc:creator>
    <dc:date>2009-11-21T15:41:22Z</dc:date>
    <item>
      <title>Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155891#M8892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In&amp;nbsp;HCS08SG8 controller, I&amp;nbsp;am using&amp;nbsp;TPM2CH1 as a compare channel (- software interrupt only) to generate the MonoStable Output(OneShot signal). ie ON duration of the pulse is fixed and the off duration is undetermined. When ever iw want to generate the signal just i trigger the signal by switching on the port pin and load the timer for 1 ms. After the 1 ms, th eport pin will be switched off at the compare interrupt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; From the datasheet i studied that there is a latchng mechanism to be taken care while writting the compare register. otherwise the compare register will not be wriiten ar per our expectation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So i wrote code as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Main:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if((System Input Conditions) &amp;amp;&amp;amp; (InterruptStatus == DISABLED))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Switch ON the Port Pin;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Enable the Compare Interrupt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Flag holding the status of Timer Interrupt */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InterruptStatus = ENABLED;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM1C1V = TPM1CNT + One Ms Equivalent Count;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ISR:&lt;/P&gt;&lt;P&gt;{&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; /*&amp;nbsp;Interrupt Flag clearing mechanism */&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DummyVariable = TPM2CH1SC;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2CH1IF = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TPM2CH1IE = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InterruptStatus = ENABLED;&lt;/P&gt;&lt;P&gt;&amp;nbsp;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thiw code works 99 %. But at 1 % the output signal has been stopped after some hours.&lt;/P&gt;&lt;P&gt;When i debug this, InterruptStatus Flag remains ENABLED but the actual interrupt enable bit in the hardware register was disabled.so signal genartor doesnt works after that time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone encountered similar problems before? Did i make any mistake in my code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by TDKamalAru on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-11-20&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;05:09 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2009 13:01:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155891#M8892</guid>
      <dc:creator>TDKamalAru</dc:creator>
      <dc:date>2009-11-20T13:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155892#M8893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Where you set InterruptStatus to DISABLED? Where you disable interrupt? In your pseudocode you only enable interrupts and set InterruptStatus to ENABLED. Please show all writes to InterruptStatus and TPM2CH1IE. Do you clear timer flag before enabling interrupt?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2009 20:21:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155892#M8893</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2009-11-20T20:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155893#M8894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;It is hard to tell with just that pseudo. One typical cause for such unexpected, rarely appearing bugs is lack of semaphores, ie the main loop and the ISR attempt to access the same memory at the same time. Another cause could be forgetting to declare the variables shared with the ISR as volatile, which will lead to completely random behavior.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2009 21:34:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155893#M8894</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2009-11-20T21:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155894#M8895</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 might have expected that that the TPM2C1SC_CH1IE bit would be set within the main code, and would then be &lt;U&gt;cleared&lt;/U&gt; within the ISR code.&amp;nbsp; That is, once the OC interrupt has occurred, and the ISR entered, there are no further interrupts required until after the next pulse has been initiated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The additional InterruptStatus flag would appear unnecessary since the TPM2C1SC_CH1IE bit already represents the status, and may be read at any time.&amp;nbsp; I would also suggest globally disabling interrupts during the pulse start process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#define InterruptStatus&amp;nbsp; TPM2C1SC_CH1IE&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;void pulse_start( word pwidth)&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; if (!InterruptStatus) {&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DisableInterrupts;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Switch on port pin here&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2C1V = TPM2CNT + pwidth&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2C1SC = 0x50;&amp;nbsp;&amp;nbsp; // Output compare, interrupt only&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2C1SC_CH1F = 0; // Ensure flag is clear&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EnableInterrupts;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&amp;nbsp;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2009 23:55:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155894#M8895</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-11-20T23:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155895#M8896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Kef, Lundina and BigMac,&lt;/P&gt;&lt;P&gt;I am really sorry as i mistyped the main thing. Once again ask you to forgive me please.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Exact&amp;nbsp;PseudoCode :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Main:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if((System Input Conditions) &amp;amp;&amp;amp; (InterruptStatus == DISABLED))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Switch ON the Port Pin;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TPM2CH1IF = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable the Compare Interrupt */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2CH1IE = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Flag holding the status of Timer Interrupt */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InterruptStatus = ENABLED;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM1C1V = TPM1CNT + One Ms Equivalent Count;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ISR:&lt;/P&gt;&lt;P&gt;{&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; /*&amp;nbsp;Interrupt Flag clearing mechanism */&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DummyVariable = TPM2CH1SC;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2CH1IF = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Disabling the interrupt */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2CH1IE = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InterruptStatus = DISABLED;&lt;/P&gt;&lt;P&gt;&amp;nbsp;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your replies and please let me know the views on this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Nov 2009 15:41:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155895#M8896</guid>
      <dc:creator>TDKamalAru</dc:creator>
      <dc:date>2009-11-21T15:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155896#M8897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is clear now.&lt;/P&gt;&lt;P&gt;Timer is always ticking. I guess System Input Conditions&amp;nbsp;gets true not&amp;nbsp;every timer overflow period? But timer output compare match occurs every timer period.&amp;nbsp;Now,&amp;nbsp;since you update compare registers in main after clearing flag and enabling interrupt, chances are older output compare match setting will match CNT&amp;nbsp;anytime&amp;nbsp;between marked lines:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Main:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if((System Input Conditions) &amp;amp;&amp;amp; (InterruptStatus == DISABLED))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Switch ON the Port Pin;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TPM2CH1IF = 0;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable the Compare Interrupt */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2CH1IE = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Flag holding the status of Timer Interrupt */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InterruptStatus = ENABLED;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM1C1V = TPM1CNT + One Ms Equivalent Count;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You&amp;nbsp;get desired results in case older compare match doesn't occur before or during red line, before C1V gets updated. To fix it, update C1V before clearing timer flag&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Main:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if((System Input Conditions) &amp;amp;&amp;amp; (InterruptStatus == DISABLED))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Switch ON the Port Pin;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM1C1V = TPM1CNT + One Ms Equivalent Count;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TPM2CH1IF = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable the Compare Interrupt */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2CH1IE = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Flag holding the status of Timer Interrupt */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InterruptStatus = ENABLED;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also I'd move&amp;nbsp;&amp;nbsp;InterruptStatus = ENABLED; above CH1IE=1. It won't change anything while&amp;nbsp;+1ms is enough to execute code from C1V&amp;nbsp;update to Interrupts = ENABLED. But if you decide later to shorten&amp;nbsp;that drastically, you will be guaranteed&amp;nbsp;ISR always&amp;nbsp;sees&amp;nbsp;InterruptStatus == ENABLED.&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by kef on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-11-21&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;01:17 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Nov 2009 19:14:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155896#M8897</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2009-11-21T19:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155897#M8898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Kef,&lt;/P&gt;&lt;P&gt;Thanks for your reply. But in the datasheet it is given that after updating the C1V register, the value will be latched to the C1V only at the next increment of the CNT register(since it is being used as a Compare module).If we write the SC register before CNT increments, then the latching mechanism will be reset and the C1V reg will not get updated.Hope so it is clear to you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case:1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff"&gt;C1V = 0xAA;&amp;nbsp;&lt;/FONT&gt; &lt;FONT color="#339966"&gt;/* Execution point:1 - say CNT = 4 at this instant of&amp;nbsp;execution */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff"&gt;IF = 0;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff"&gt;IE = 1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff"&gt;&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;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color="#339966"&gt;/* Execution point:2 - say CNT = 5 at this instant of execution */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;So since IF and IE bits in SC register has been written before CNT increments to next value 5, the latching mechanism got reset and the C1V will be updated by 0xAA. What shall we do for this.&lt;/P&gt;&lt;P&gt;I have tested with debugger also. At the Execution point:2, the C1v doesn't holds 0xAA but the old value.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 22 Nov 2009 11:25:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155897#M8898</guid>
      <dc:creator>TDKamalAru</dc:creator>
      <dc:date>2009-11-22T11:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155898#M8899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What's your CNT clock? Is it prescaled so that you write IF=0 before CNT gets incremented? Then you should wait a bit, until CNT gets incremented and C1V updated. Anyway C1V should be updated first, then flag cleared, and only then&amp;nbsp;interrupt should be enabled.&lt;/P&gt;&lt;P&gt;Thanks for pointing me at latching mechanism issue.&amp;nbsp;I didn't take that into account because I'm not that familiar with S08. But I believe&amp;nbsp;what bites your pseudocode is previous output compare setting matched some timer overflow periods later.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 22 Nov 2009 15:26:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155898#M8899</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2009-11-22T15:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155899#M8900</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;Why don't you post your actual problem code, rather than pseudo code?&amp;nbsp; This may clarify the situation, and would permit others to also test the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For a one millisecond output compare period, you shouldn't need a high prescale value.&amp;nbsp; However, if you suspect that the write to TPM2C1SC is reseting the latching mechanism, because of the prescale setting, the maximum cycles you would need to wait would be equivalent to the prescale value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps alter the sequence so that TPM2C1V is written first, then manipulate the port pin, and set any other status flag.&amp;nbsp; This should give a delay of a few cycles.&amp;nbsp; You could add a bit more padding, if your prescale value is more than 4, before then writing to TPM2C1SC.&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>Mon, 23 Nov 2009 01:04:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155899#M8900</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-11-23T01:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155900#M8901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kef,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Yes,my CNT is prescaled&amp;nbsp;from Source Clock.There might be a chance to had a compare event interrupt due to older value. But for what ever may be the compare event, my InterruptStatus bit variable should also get updated in coherent with the timer interrupt disable right. Because in freescale interrupt architecture, they dont have any interrupt controller which controls the priorities etc. When ever an interrupt occurs, the global interrupt will be automatically disabled and will be enabled when it returns from the isr. In such a case the timer interrupt disable and InterruptStatus = DISABLED should happens with out any fail. The problem could be the wrong pulse width if the compare event occured fro older compare value. But here since timer gets disabled and the InterruptStatus Flag remains Enabled causes the no output(pulse).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Nov 2009 11:32:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155900#M8901</guid>
      <dc:creator>TDKamalAru</dc:creator>
      <dc:date>2009-11-23T11:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155901#M8902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;TDKamalAru,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please look again at your pseudocode. If old compare setting can match after you clear flag and&amp;nbsp;before you update CxV, then interrupt can fire before you set&amp;nbsp;InterruptStatus to ENABLED! It may fire immediately after you enable interrupt and before InterruptStatus is set to ENABLED. 1) ISR will be called first, 2) ISR will set InterruptStatus to DISABLED. 3)&amp;nbsp;Finally CPU will return back from ISR and&amp;nbsp;will execute the rest of MAIN, setting InterruptStatus to ENABLED. Result: interrupt mask ==0, InterruptStatus == ENABLED.&lt;/P&gt;&lt;P&gt;No coherency guaranteed, unless you set up CxV=CNT+N first, then clear flag. These two steps guarantee compare match and flag=1 won't occur for N next timer ticks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I played yesterday with latching mechanism. Clocking&amp;nbsp;TPM from bus clock and&amp;nbsp;using small prescalers no delay between CxV=.. and flag=0 is required.&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by kef on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-11-23&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;08:51 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Nov 2009 14:45:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155901#M8902</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2009-11-23T14:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected Disabling of interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155902#M8903</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Kef,&lt;/P&gt;&lt;P&gt;Thanks i got it.Yes this could be the only reason behined the death of my code.i will do change and give u the feedback. Hav confidnce that it will work more than 100%.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once again i thank Mr Kef and Mr Mac for giving our views and helped me to know the cause and to take the corrective action.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Nov 2009 17:05:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Unexpected-Disabling-of-interrupt/m-p/155902#M8903</guid>
      <dc:creator>TDKamalAru</dc:creator>
      <dc:date>2009-11-23T17:05:58Z</dc:date>
    </item>
  </channel>
</rss>

