<?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のトピックCan't read correct RTC counter of 9S08PA4 ?!</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Can-t-read-correct-RTC-counter-of-9S08PA4/m-p/244882#M19663</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; To share an experience here.&lt;/P&gt;&lt;P&gt;We are using the RTC counter of PA4 as a free run counter to calculate motor speed. The RTC counter is a 16bit counter split into a high byte and a low byte register.&lt;/P&gt;&lt;P&gt;As following:&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-fareast-font-family: SimSun; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="8474_8474.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/119689i0E10B2F115C88621/image-size/large?v=v2&amp;amp;px=999" role="button" title="8474_8474.png" alt="8474_8474.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="RTC 16bit counter2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/42118i1A471B96A51F9DCE/image-size/large?v=v2&amp;amp;px=999" role="button" title="RTC 16bit counter2.png" alt="RTC 16bit counter2.png" /&gt;&lt;/span&gt;&amp;nbsp; &lt;span class="lia-inline-image-display-wrapper" image-alt="8464_8464.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/119690iF3BE61146781DFAD/image-size/large?v=v2&amp;amp;px=999" role="button" title="8464_8464.png" alt="8464_8464.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="RTC 16bit counter1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/42023iBE6EDDAD8214E7BA/image-size/large?v=v2&amp;amp;px=999" role="button" title="RTC 16bit counter1.png" alt="RTC 16bit counter1.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; We found the high byte will not carry immediately when the low byte is changed from 0xFF to 0x00. &lt;BR /&gt;For example: we got 0x00FE -&amp;gt; 0x00FF -&amp;gt; 0x0000 -&amp;gt; 0x0101…&lt;BR /&gt;It has a chance to get a 0x0000 value which is wrong and results in wrong speed calculation.&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Solution:&lt;/SPAN&gt; To read the low byte first, then high byte.&lt;BR /&gt;&amp;nbsp; You can use a 16bit variable to store the result of the 16bit counter, but you must read the RTC_CNTL first, then RTC_CNTH.&lt;BR /&gt;It is also not recommend to use the register window or the memory window in the Codewarrior IDE to view these registers.&lt;/P&gt;&lt;P&gt;Instead, you can read the two SFRs in order and print it to terminal for check.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Reason:&lt;/SPAN&gt; The reason is the design of lock mechanism.&lt;/P&gt;&lt;P&gt;&amp;nbsp; The RTC_CNTL must be read first to lock the counter and then read RTC_CNTH to correctly read 16bit counter. &lt;/P&gt;&lt;P&gt;The design is to avoid the case: When RTC_CNT counter is 0x01FF, read RTC_CNTL to be 0xFF, the high byte of counter&lt;/P&gt;&lt;P&gt;is locked to be 0x01, then read RTC_CNTH will get 0x01. If the counter is not locked, 0x02 will be read from RTC_CNTH.&lt;/P&gt;&lt;P&gt;Then 0x02FF will be read which is wrong.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Dec 2013 13:45:46 GMT</pubDate>
    <dc:creator>StanleyH</dc:creator>
    <dc:date>2013-12-05T13:45:46Z</dc:date>
    <item>
      <title>Can't read correct RTC counter of 9S08PA4 ?!</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Can-t-read-correct-RTC-counter-of-9S08PA4/m-p/244882#M19663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; To share an experience here.&lt;/P&gt;&lt;P&gt;We are using the RTC counter of PA4 as a free run counter to calculate motor speed. The RTC counter is a 16bit counter split into a high byte and a low byte register.&lt;/P&gt;&lt;P&gt;As following:&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-fareast-font-family: SimSun; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="8474_8474.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/119689i0E10B2F115C88621/image-size/large?v=v2&amp;amp;px=999" role="button" title="8474_8474.png" alt="8474_8474.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="RTC 16bit counter2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/42118i1A471B96A51F9DCE/image-size/large?v=v2&amp;amp;px=999" role="button" title="RTC 16bit counter2.png" alt="RTC 16bit counter2.png" /&gt;&lt;/span&gt;&amp;nbsp; &lt;span class="lia-inline-image-display-wrapper" image-alt="8464_8464.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/119690iF3BE61146781DFAD/image-size/large?v=v2&amp;amp;px=999" role="button" title="8464_8464.png" alt="8464_8464.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="RTC 16bit counter1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/42023iBE6EDDAD8214E7BA/image-size/large?v=v2&amp;amp;px=999" role="button" title="RTC 16bit counter1.png" alt="RTC 16bit counter1.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; We found the high byte will not carry immediately when the low byte is changed from 0xFF to 0x00. &lt;BR /&gt;For example: we got 0x00FE -&amp;gt; 0x00FF -&amp;gt; 0x0000 -&amp;gt; 0x0101…&lt;BR /&gt;It has a chance to get a 0x0000 value which is wrong and results in wrong speed calculation.&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Solution:&lt;/SPAN&gt; To read the low byte first, then high byte.&lt;BR /&gt;&amp;nbsp; You can use a 16bit variable to store the result of the 16bit counter, but you must read the RTC_CNTL first, then RTC_CNTH.&lt;BR /&gt;It is also not recommend to use the register window or the memory window in the Codewarrior IDE to view these registers.&lt;/P&gt;&lt;P&gt;Instead, you can read the two SFRs in order and print it to terminal for check.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Reason:&lt;/SPAN&gt; The reason is the design of lock mechanism.&lt;/P&gt;&lt;P&gt;&amp;nbsp; The RTC_CNTL must be read first to lock the counter and then read RTC_CNTH to correctly read 16bit counter. &lt;/P&gt;&lt;P&gt;The design is to avoid the case: When RTC_CNT counter is 0x01FF, read RTC_CNTL to be 0xFF, the high byte of counter&lt;/P&gt;&lt;P&gt;is locked to be 0x01, then read RTC_CNTH will get 0x01. If the counter is not locked, 0x02 will be read from RTC_CNTH.&lt;/P&gt;&lt;P&gt;Then 0x02FF will be read which is wrong.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 13:45:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Can-t-read-correct-RTC-counter-of-9S08PA4/m-p/244882#M19663</guid>
      <dc:creator>StanleyH</dc:creator>
      <dc:date>2013-12-05T13:45:46Z</dc:date>
    </item>
  </channel>
</rss>

