<?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: infinite loop inside an interrupt in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/infinite-loop-inside-an-interrupt/m-p/190810#M14617</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;If you are timing the blink of a LED, where is your timing reference?&amp;nbsp; At the moment, any timing will be associated with execution cycles of the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suspect that you should be utilising say the TPM overflow interrupt, rather than the ADC interrupt.&amp;nbsp; The &lt;FONT face="courier new,courier"&gt;count&lt;/FONT&gt; &lt;FONT face="arial,helvetica,sans-serif"&gt;variable would then count each TPM overflow, and then test whether a threshold value had been reached.&amp;nbsp; This would give a more consistent timing, not dependent on execution cycles.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The approach might be to commence the first single ADC conversion during initialisation.&amp;nbsp; Then, when each TPM overfow occurs, to read the previous conversion result, and to start a new single&amp;nbsp;conversion, to be read during the next overflow.&amp;nbsp; You might even delay the use of the previous conversion until the threshold count is reached, and you commence a new LED flash period.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that where tha ADC value directly determines the count value, the LED flash period (and not the frequency) will be directly proportional to the control voltage.&amp;nbsp; If the frequency is required to be proportional to the control voltage, the ADC value will require further mathematical processing to determine the current threshold value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that any local variables within an ISR (such as &lt;FONT face="courier new,courier"&gt;count &lt;FONT face="arial,helvetica,sans-serif"&gt;and&lt;/FONT&gt; set_time&lt;/FONT&gt;) will need to be static or global type.&amp;nbsp; Other variables used be the ISR that require access by other functions within the main loop&amp;nbsp;will need to be volatile global type.&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, 12 Apr 2010 13:56:41 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2010-04-12T13:56:41Z</dc:date>
    <item>
      <title>infinite loop inside an interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/infinite-loop-inside-an-interrupt/m-p/190808#M14615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was experimenting with my QG8 micro the other day and was using the ADC. So below is a piece of code i used to make a VCO(voltage controlled oscillator) which increases the&amp;nbsp;frequency&amp;nbsp;of blinking of the LED. &amp;nbsp;I got the result I wanted for low&amp;nbsp;frequencies but at higher&amp;nbsp;frequencies the pattern is not right. So I wanted to know what sort of effect an infinite loop in an interrupt has on the MCU?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice will be much appreciated. Thanks guys&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;__interrupt void isrVadc_complete(void)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;&amp;nbsp;unsigned int set_time;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;unsigned int ADC_val;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;unsigned int count = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for( ;; )&amp;nbsp;&lt;/P&gt;&lt;P&gt;{ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;ADC_val = ADCRL; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set_time = ADC_val * 256;&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;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if(count == set_time)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;{PTAD_PTAD0 = ~PTAD_PTAD0;&amp;nbsp;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;else if( count &amp;gt; set_time)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;{count=0; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; count++; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Apr 2010 10:35:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/infinite-loop-inside-an-interrupt/m-p/190808#M14615</guid>
      <dc:creator>karthick1987</dc:creator>
      <dc:date>2010-04-11T10:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: infinite loop inside an interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/infinite-loop-inside-an-interrupt/m-p/190809#M14616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello karthick&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have your toggle condition as equals and you are comparing to basically a live ADC result.&lt;/P&gt;&lt;P&gt;Because of this it is very possible you can miss the compare due to the ADC result jittering around due to noise etc.&lt;/P&gt;&lt;P&gt;Also, locking yourself in interrupt here is pretty pointless. It means the only thing this processor can do is this code.&lt;/P&gt;&lt;P&gt;The reason you use an interrupt is to get very fast response to an event, here you don't get that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Apr 2010 06:17:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/infinite-loop-inside-an-interrupt/m-p/190809#M14616</guid>
      <dc:creator>peg</dc:creator>
      <dc:date>2010-04-12T06:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: infinite loop inside an interrupt</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/infinite-loop-inside-an-interrupt/m-p/190810#M14617</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;If you are timing the blink of a LED, where is your timing reference?&amp;nbsp; At the moment, any timing will be associated with execution cycles of the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suspect that you should be utilising say the TPM overflow interrupt, rather than the ADC interrupt.&amp;nbsp; The &lt;FONT face="courier new,courier"&gt;count&lt;/FONT&gt; &lt;FONT face="arial,helvetica,sans-serif"&gt;variable would then count each TPM overflow, and then test whether a threshold value had been reached.&amp;nbsp; This would give a more consistent timing, not dependent on execution cycles.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The approach might be to commence the first single ADC conversion during initialisation.&amp;nbsp; Then, when each TPM overfow occurs, to read the previous conversion result, and to start a new single&amp;nbsp;conversion, to be read during the next overflow.&amp;nbsp; You might even delay the use of the previous conversion until the threshold count is reached, and you commence a new LED flash period.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that where tha ADC value directly determines the count value, the LED flash period (and not the frequency) will be directly proportional to the control voltage.&amp;nbsp; If the frequency is required to be proportional to the control voltage, the ADC value will require further mathematical processing to determine the current threshold value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that any local variables within an ISR (such as &lt;FONT face="courier new,courier"&gt;count &lt;FONT face="arial,helvetica,sans-serif"&gt;and&lt;/FONT&gt; set_time&lt;/FONT&gt;) will need to be static or global type.&amp;nbsp; Other variables used be the ISR that require access by other functions within the main loop&amp;nbsp;will need to be volatile global type.&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, 12 Apr 2010 13:56:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/infinite-loop-inside-an-interrupt/m-p/190810#M14617</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-04-12T13:56:41Z</dc:date>
    </item>
  </channel>
</rss>

