<?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: Newbie timer help. in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141750#M3296</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;You would need to take into account timer overflows only If the pulse width to be measured exceeds the timer overflow period.&amp;nbsp; For pulse widths less than the timer overflow period, a simple 16-bit subtraction of the two values would suffice.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;If the two timer values have an intervening timer overflow, the second value would be less than the first value, but the first value would still need to be subtracted.&amp;nbsp; The correct value will&amp;nbsp;be obtained if the result is&amp;nbsp;simply considered unsigned.&amp;nbsp; For assembler this is straightforward - not sure of the implications for C code.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;The pulse duration measurement getting "out of step" shouldn't be a problem provided the input capture is set up to occur on either a positive or a negative edge - but not for the timer&amp;nbsp;mode to capture on either edge.&amp;nbsp; The opposite edge for the next capture&amp;nbsp;should be&amp;nbsp;set from&amp;nbsp;within the ISR for the timer channel.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2006-07-05&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;12:20 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 05 Jul 2006 09:05:34 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2006-07-05T09:05:34Z</dc:date>
    <item>
      <title>Newbie timer help.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141748#M3294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi to all.&lt;/DIV&gt;&lt;DIV&gt;I'm new to using this processor(MC9S12Gc32) and a a bit confused about some of the Timer module functionality.&lt;/DIV&gt;&lt;DIV&gt;I have read the datasheet , but still have a few questions.&lt;/DIV&gt;&lt;DIV&gt;If I want to measure the time that a input on say IOC4 is high I have to do the following. Set the input to trigger on high and low edges. When the edge goes high I take the value of TC4 and store it. When the edge goes low I take the TC4 reading again and subtract the 2 to get a time/count difference?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This seems to work , but seems cumbersome. It would be easier to set the counter to 0 on the rising edge and then take one reading&amp;nbsp;on the falling edge&amp;nbsp;to get a result. The only way I can see to do this is to set the main counter TCNT to 0(this can't be done directly anyway)&lt;/DIV&gt;&lt;DIV&gt;but this would mess up any other timers that are running.&lt;/DIV&gt;&lt;DIV&gt;Am I missing something here ?&lt;/DIV&gt;&lt;DIV&gt;Cheers&lt;/DIV&gt;&lt;DIV&gt;Seegoon&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Jul 2006 20:18:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141748#M3294</guid>
      <dc:creator>Seegoon</dc:creator>
      <dc:date>2006-07-03T20:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie timer help.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141749#M3295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;The way you described it initially is the way I do it.&amp;nbsp; You also need to handle the timer overflows, of course.&amp;nbsp; One problem with setting the timer to trigger on high and low edges is that it becomes possible to get out of sync with the pulses such that you may measure the time between pulses instead of measuring the pulse itself.&amp;nbsp; Your software&amp;nbsp;should check the pin to see if it is high or low to determine whether to store the value or to subtract from the previously stored value.&amp;nbsp; If the pulses are extremely short, you can tie the two pins together with a resistor and configure one to interrupt on&amp;nbsp;high edges and configure the other to interrupt on low edges and write the ISRs accordingly.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;As you said, you can reset the counter, but that interferes with multiple timers happening concurrently.&amp;nbsp; With this 'reset counter' method, you are only really saving yourself one subtraction which is only a few cycles - and the end result will be exactly the same either way.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jul 2006 05:16:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141749#M3295</guid>
      <dc:creator>rhinoceroshead</dc:creator>
      <dc:date>2006-07-05T05:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie timer help.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141750#M3296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;You would need to take into account timer overflows only If the pulse width to be measured exceeds the timer overflow period.&amp;nbsp; For pulse widths less than the timer overflow period, a simple 16-bit subtraction of the two values would suffice.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;If the two timer values have an intervening timer overflow, the second value would be less than the first value, but the first value would still need to be subtracted.&amp;nbsp; The correct value will&amp;nbsp;be obtained if the result is&amp;nbsp;simply considered unsigned.&amp;nbsp; For assembler this is straightforward - not sure of the implications for C code.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;The pulse duration measurement getting "out of step" shouldn't be a problem provided the input capture is set up to occur on either a positive or a negative edge - but not for the timer&amp;nbsp;mode to capture on either edge.&amp;nbsp; The opposite edge for the next capture&amp;nbsp;should be&amp;nbsp;set from&amp;nbsp;within the ISR for the timer channel.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2006-07-05&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;12:20 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jul 2006 09:05:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141750#M3296</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-07-05T09:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie timer help.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141751#M3297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Hi guys.&lt;/P&gt;&lt;P&gt;Thanks for the help. Nice to know that I'm at least on the right track.&lt;/P&gt;&lt;P&gt;My code is set to trigger on both edges , but I do check the current pin condition&lt;/P&gt;&lt;P&gt;to make sure I know which edge has occured. The pulse widths are in the order of about 12ms and shorter. The prescalar is set such that the timer would overflow only after about 20ms. I currently take 1 reading on the rising edge and one on the falling edge. If the second reading is bigger than the first I subtract the 2 to get a result. If it's smaller I assume the counter has rolled over and I subtract the first result from 65535 and add the second reading.&lt;/P&gt;&lt;P&gt;Is there a better weay to do this.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Seegoon&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jul 2006 13:35:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141751#M3297</guid>
      <dc:creator>Seegoon</dc:creator>
      <dc:date>2006-07-05T13:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie timer help.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141752#M3298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;As Bigmac said, there is no need to subtract from 65535 (actually it would be 65536) since that number needs 17 bits to be represented and it will be interpreted as 0 anyway when truncated to 16 bits.&amp;nbsp; In assembly you would just treat the normal subtraction result as unsigned and ignore the carry bit.&amp;nbsp; In C you would declare or cast the integer holding the result&amp;nbsp;to an 'unsigned int'.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Example:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Rising edge counter value = 0x0100&lt;/DIV&gt;&lt;DIV&gt;Falling edge counter value = 0x0080&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;0x10000 - 0x0100 + 0x0080 = 0xFF80&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;0x0080 - 0x0100 = 0xFF80 (there is a 1 in the C bit of CCR, but ignore it)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Using either method, you have to interpret the result as unsigned if you expect the pulse width to be longer than 32767 timer clock cycles.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jul 2006 01:49:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141752#M3298</guid>
      <dc:creator>rhinoceroshead</dc:creator>
      <dc:date>2006-07-06T01:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie timer help.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141753#M3299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Thanks for all the help guys. Think I've got it sorted now.&lt;/P&gt;&lt;P&gt;Now I need to figure how to save things to internal eeprom/ flash. A quick look through the datasheet shows that it looks to be quite a task :0(&lt;/P&gt;&lt;P&gt;Oh well.&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Seegoon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jul 2006 14:18:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141753#M3299</guid>
      <dc:creator>Seegoon</dc:creator>
      <dc:date>2006-07-06T14:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie timer help.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141754#M3300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Don't forget about the pulse accumulator input which can measure the width of pulses directly. It uses the timer clock/64 so the resolution is more limited that the IC channels.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2006 17:42:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Newbie-timer-help/m-p/141754#M3300</guid>
      <dc:creator>Steve</dc:creator>
      <dc:date>2006-07-10T17:42:36Z</dc:date>
    </item>
  </channel>
</rss>

