<?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: Internal/external clock on MC9S08SH8 in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Internal-external-clock-on-MC9S08SH8/m-p/644505#M13759</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's the entire code. We really want to get the external oscillator going.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#include "derivative.h" /* include peripheral declarations */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Clock source constants&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define LPO 0&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define IRCLK 1&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define ERCLK 2&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define CLK_SRC LPO&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define LED_DIR PTADD_PTADD2&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define LED_OUT PTAD_PTAD2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Interrupt service routine for real time counter&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;interrupt VectorNumber_Vrtc void RTC_ISR(void)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;{&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Clear interrupt flag&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCSC |= 0x80;&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;LED_OUT = !LED_OUT; // toggle the LED every second&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;void main(void) {&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Board has an LED connected to PDB7; make it output&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;LED_DIR = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#if CLK_SRC == IRCLK&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Use the higher accuracy 32kHz internal clock&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCMOD = 0b01111101; // 125 (125*8ms=1s)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCSC = 0b01010101; // CS=IRCLK, RTIE, PS=0101 (8ms)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#elif CLK_SRC == ERCLK&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Use the external clock (32.768kHz xtal)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCMOD = 0b00100000; // 32 (32*31.25ms=1s)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCSC = 0b00110111; // CS=ERCLK, RTIE, PS=0111 (/1024=31.25ms)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#else&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Use the 1kHz low power oscillator (30% margin for error)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCMOD = 0x00; // 0b00000000&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCSC = 0x1F; // 0b00011111&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#endif&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;EnableInterrupts;&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;/* include your code here */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;for( ; ; {&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;__RESET_WATCHDOG(); /* feeds the dog */&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;} /* loop forever */&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;/* please make sure that you never leave main */&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Apr 2017 04:03:25 GMT</pubDate>
    <dc:creator>eslindsey</dc:creator>
    <dc:date>2017-04-28T04:03:25Z</dc:date>
    <item>
      <title>Internal/external clock on MC9S08SH8</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Internal-external-clock-on-MC9S08SH8/m-p/644504#M13758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've got an application up and running on a MC9S08SH8 that blinks an LED once per second (as a test) using an interrupt triggered by the real time counter. I'm initializing it as follows, and this works:&lt;/P&gt;&lt;P&gt;// Use the 1kHz low power oscillator&lt;/P&gt;&lt;P&gt;RTCMOD = 0x00;&lt;/P&gt;&lt;P&gt;RTCSC = 0x1F;&lt;/P&gt;&lt;P&gt;I've read that the low power oscillator has up to a 30% error rate depending on voltage and temperature, and I need better accuracy than that, so I'd like to use the higher powered internal clock, or an external 32.768kHz crystal. However, neither of the following produce any results (no interrupts are generated):&lt;/P&gt;&lt;P&gt;// Use the higher accuracy 32kHz internal clock, based on table 13-6&lt;/P&gt;&lt;P&gt;RTCMOD = 0b01111101; // 125 (125*8ms=1s)&lt;/P&gt;&lt;P&gt;RTCSC = 0b01010101; // CS=IRCLK, RTIE, PS=0101 (8ms)&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;// Use the external clock (32.768kHz crystal), based on table 13-3&lt;/P&gt;&lt;P&gt;RTCMOD = 0b00100000; // 32&amp;nbsp;(32*31.25ms=1s)&lt;/P&gt;&lt;P&gt;RTCSC = 0b00110111; // CS=ERCLK, RTIE, PS=0111 (/1024=31.25ms)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The tables I'm referring to come from the data sheet at&amp;nbsp;&lt;A class="link-titled" href="http://www.nxp.com/assets/documents/data/en/data-sheets/MC9S08SH8.pdf" title="http://www.nxp.com/assets/documents/data/en/data-sheets/MC9S08SH8.pdf"&gt;http://www.nxp.com/assets/documents/data/en/data-sheets/MC9S08SH8.pdf&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If my values for RTCMOD and RTCSC are correct, then is there any extra initialization I need to do in software to use the internal/external clock? Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Apr 2017 03:27:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Internal-external-clock-on-MC9S08SH8/m-p/644504#M13758</guid>
      <dc:creator>eslindsey</dc:creator>
      <dc:date>2017-04-26T03:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Internal/external clock on MC9S08SH8</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Internal-external-clock-on-MC9S08SH8/m-p/644505#M13759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's the entire code. We really want to get the external oscillator going.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#include "derivative.h" /* include peripheral declarations */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Clock source constants&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define LPO 0&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define IRCLK 1&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define ERCLK 2&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define CLK_SRC LPO&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define LED_DIR PTADD_PTADD2&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#define LED_OUT PTAD_PTAD2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Interrupt service routine for real time counter&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;interrupt VectorNumber_Vrtc void RTC_ISR(void)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;{&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Clear interrupt flag&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCSC |= 0x80;&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;LED_OUT = !LED_OUT; // toggle the LED every second&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;void main(void) {&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Board has an LED connected to PDB7; make it output&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;LED_DIR = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#if CLK_SRC == IRCLK&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Use the higher accuracy 32kHz internal clock&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCMOD = 0b01111101; // 125 (125*8ms=1s)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCSC = 0b01010101; // CS=IRCLK, RTIE, PS=0101 (8ms)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#elif CLK_SRC == ERCLK&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Use the external clock (32.768kHz xtal)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCMOD = 0b00100000; // 32 (32*31.25ms=1s)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCSC = 0b00110111; // CS=ERCLK, RTIE, PS=0111 (/1024=31.25ms)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#else&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;// Use the 1kHz low power oscillator (30% margin for error)&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCMOD = 0x00; // 0b00000000&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;RTCSC = 0x1F; // 0b00011111&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;#endif&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;EnableInterrupts;&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;/* include your code here */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;for( ; ; {&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;__RESET_WATCHDOG(); /* feeds the dog */&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;} /* loop forever */&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;/* please make sure that you never leave main */&lt;/SPAN&gt;&lt;BR style="color: #191919; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #191919; background-color: #ffffff;"&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Apr 2017 04:03:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Internal-external-clock-on-MC9S08SH8/m-p/644505#M13759</guid>
      <dc:creator>eslindsey</dc:creator>
      <dc:date>2017-04-28T04:03:25Z</dc:date>
    </item>
  </channel>
</rss>

