<?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: IRQ causing unexpected result? in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156111#M8940</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;You access INP1_TMP at three different points.&amp;nbsp; Isn't that enough of a reason, when the same routine gets called from the ISR, also?&amp;nbsp; Isn't it possible that INP1_TMP gets changed (from the ISR invocation of the same routine) while in the middle of executing the non-ISR routine?&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by tonyp on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-11-20&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;11:56 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 21 Nov 2009 05:55:40 GMT</pubDate>
    <dc:creator>tonyp</dc:creator>
    <dc:date>2009-11-21T05:55:40Z</dc:date>
    <item>
      <title>IRQ causing unexpected result?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156108#M8937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm hoping someone here has some ideas on a problem with our code. We're using an MC68HC11E1CFN2 with external memory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following code snippet is in a routine that is called repeatedly in the main loop of my program. The bits in accumulator A are reversed into accumulator B then stored into a variable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDAB&amp;nbsp; #$08&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;Load for loop counter&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STAB&amp;nbsp; INP1_TMP&amp;nbsp;&amp;nbsp;&amp;nbsp; ;Move 8 bits&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CLRB&lt;BR /&gt;GET_DIP_LP&amp;nbsp; ROLA&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; ;Move MSB into carry&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RORB&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; ;Move carry into MSB&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DEC&amp;nbsp;&amp;nbsp; INP1_TMP&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BNE&amp;nbsp;&amp;nbsp; GET_DIP_LP ;If not done&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COMB&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; ;Complement bits&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ANDB&amp;nbsp; #$3F&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;Mask off unwanted bits&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STAB&amp;nbsp; INP1_TMP&amp;nbsp;&amp;nbsp;&amp;nbsp; ;and save&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The value in INP1_TMP is what I expect. I don't know how often this code gets executed (don't have a debugger) but I'd say it does what it should thousands of times in a row, but every once in a while the value in INP1_TMP is incorrect.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This routine also gets called in my interrupt handling code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any idea what could be going wrong? My only theory is that occasionally in between the ROLA and RORB statements, an interrupt happens (and the code executes again) and when it returns the carry bit is incorrect. That should have been saved correctly on the stack though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks like if I don't call this routine in the interrupt handling code everything works fine. I'd still like to know what's going wrong though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ryan&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Nov 2009 05:27:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156108#M8937</guid>
      <dc:creator>RW</dc:creator>
      <dc:date>2009-11-21T05:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: IRQ causing unexpected result?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156109#M8938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;You mean to say you've never heard of the SEI and CLI instructions and what they're good for? (Also, TPA and TAP to restore the pre-SEI condition.)&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by tonyp on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-11-20&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;11:46 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Nov 2009 05:45:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156109#M8938</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2009-11-21T05:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: IRQ causing unexpected result?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156110#M8939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SEI and CLI are used to disable and re-enable interrupts aren't there?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't see why I should have to disable interrupts during that block of code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Nov 2009 05:52:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156110#M8939</guid>
      <dc:creator>RW</dc:creator>
      <dc:date>2009-11-21T05:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: IRQ causing unexpected result?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156111#M8940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;You access INP1_TMP at three different points.&amp;nbsp; Isn't that enough of a reason, when the same routine gets called from the ISR, also?&amp;nbsp; Isn't it possible that INP1_TMP gets changed (from the ISR invocation of the same routine) while in the middle of executing the non-ISR routine?&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by tonyp on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-11-20&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;11:56 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Nov 2009 05:55:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156111#M8940</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2009-11-21T05:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: IRQ causing unexpected result?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156112#M8941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah, of course.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was only thinking about how the values in the accumulators could get messed up when I should have realized it was INP1_TMP.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Nov 2009 06:02:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156112#M8941</guid>
      <dc:creator>RW</dc:creator>
      <dc:date>2009-11-21T06:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: IRQ causing unexpected result?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156113#M8942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's usually possible to find ISR-friendly solutions that do not require interrupts to be disabled.&amp;nbsp; For example, you don't have to use a variable for counter.&amp;nbsp; Instead you can do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
                    LDAB      #$80
GET_DIP_LP          ROLA                     
                    RORB                     
                    BCC       GET_DIP_LP     

                    COMB                     
                    ANDB      #$3F    
                    STAB      INP1_TMP&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Register B is initially loaded with Bit7 ($80) which, as it gets shifted to the right, it will eventually (after exactly 8 shifts) end up in the CCR[C].&amp;nbsp; You can check for this to control your loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That way you only write the final result into INP1_TMP (once, in one atomic operation).&lt;/P&gt;&amp;nbsp;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:00:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/IRQ-causing-unexpected-result/m-p/156113#M8942</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2020-10-29T09:00:10Z</dc:date>
    </item>
  </channel>
</rss>

