<?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: Watchdog enables itself after reset in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Watchdog-enables-itself-after-reset/m-p/233184#M19429</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your answer and useful tips. I would be glad to hear &lt;EM&gt;any&lt;/EM&gt; criticism to my code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With your helpful answer, I have started investigating the problem and tried writing to WDOG_CS1 at once. Also, I have tried adding this code (WDOG_CS1=0;) into the startup code so that it is processed very early (within 128 bus clocks) after reset. However, that did not solve my problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, I have run across this sentence in page 615 of the &lt;A href="http://cache.freescale.com/files/microcontrollers/doc/ref_manual/MC9S08PT60RM.pdf" rel="nofollow noopener noreferrer" target="_blank"&gt;reference manual&lt;/A&gt;, under section 23.3.2:&lt;/P&gt;&lt;BLOCKQUOTE&gt;
&lt;P&gt;The new configuration takes effect only after all registers except WDOG_CNTH:L are&lt;/P&gt;
&lt;P&gt;written once after reset. Otherwise, the WDOG uses the reset values by default. If&lt;/P&gt;
&lt;P&gt;window mode is not used (WDOG_CS2[WIN] is 0), writing to WDOG_WINH:L is not&lt;/P&gt;
&lt;P&gt;required to make the new configuration take effect.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I have added following code to my &lt;SPAN style="color: #000000; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; background-color: #ffffff;"&gt;initialize_CPU()&lt;/SPAN&gt; function and it works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13719829607169637" jivemacro_uid="_13719829607169637"&gt;
&lt;P&gt;&amp;nbsp; WDOG_CS1 = 0x60;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; WDOG_CS2 = 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; WDOG_TOVAL = 0x04;&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 23 Jun 2013 10:04:24 GMT</pubDate>
    <dc:creator>abdullahkahrama</dc:creator>
    <dc:date>2013-06-23T10:04:24Z</dc:date>
    <item>
      <title>Watchdog enables itself after reset</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Watchdog-enables-itself-after-reset/m-p/233182#M19427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using &lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.freescale.com%2Fwebapp%2Fsps%2Fsite%2Fprod_summary.jsp%3Fcode%3DTWR-S08DC-PT60%26tid%3DvanTWR-S08DC-PT60" rel="nofollow noopener noreferrer" target="_blank"&gt;TWR-S08DC-PT60&lt;/A&gt; board which has a MC9S08PT60 microcontroller.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to disable the watchdog timer in my application. After configuring it in the software, it is disabled in the first run after programming, as wanted. However, after a reset occurs, either by reset button or power down, it is automatically enabled by itself. This happens when I debug, run or flash using CodeWarrior 10.4. Here is how I disable it:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="c++" name="code"&gt;&amp;nbsp; _WDOG_CS1.Bits.UPDATE = 1; // Enable changes to WDOG. &amp;nbsp; WDOG_CNT = 0xC520; // write the 1st unlock word &amp;nbsp; WDOG_CNT = 0xD928; // write the 2nd unlock word&amp;nbsp; &amp;nbsp; _WDOG_CS1.Bits.EN = 0; // Kill the dog. &amp;nbsp; _WDOG_CS1.Bits.INT = 1; // Enable WDOG interrupt. &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I debug the application, I can see that UPDATE bit is set and the watchdog timer is disabled, also, it behaves as desired when I reset using the debugger. However, in case of a reset by the reset button or power down, watchdog timer is enabled again and reset the MCU, since I do not feed it in the main loop. Also, it doesn't create an interrupt before resetting the MCU, although its interrupt is enabled. I can see, by the help of SYS_SRS (system reset source) register that the MCU is last reset by watchdog timer. Commenting out 2nd and 3rd line (WDOG_CNT=...) does not help.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my full code:&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fpastebin.com%2F37169VuV" rel="nofollow noopener noreferrer" target="_blank"&gt;main.c&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fpastebin.com%2FBwMedHff" rel="nofollow noopener noreferrer" target="_blank"&gt;init.h&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fpastebin.com%2FgPzCcq91" rel="nofollow noopener noreferrer" target="_blank"&gt;init.c&lt;/A&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Links are to pastebin.com online source code sharing service.)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jun 2013 12:19:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Watchdog-enables-itself-after-reset/m-p/233182#M19427</guid>
      <dc:creator>abdullahkahrama</dc:creator>
      <dc:date>2013-06-21T12:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: Watchdog enables itself after reset</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Watchdog-enables-itself-after-reset/m-p/233183#M19428</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, the watchdog timer is enabled by default, after each reset.&amp;nbsp; To disable, you will need to write to the WDOG_CS1 register early within your CPU_Init() function, i.e. WDOG_CS1 = 0; should suffice.&amp;nbsp; Since this is occurring immediately after a reset has occurred, this is the initial configuration process, and not a "re-configuration" of the watchdog.&amp;nbsp; The UPDATE bit should not be set unless you will require to enable the watchdog later.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I note that many of the registers within the watchdog module are "write once".&amp;nbsp; For these registers, all bits need to be simultaneously written.&amp;nbsp; Writing individual bits will not work as intended.&amp;nbsp; I would also suspect that write once would&amp;nbsp; apply to the re-configuration of a register, after it has been unlocked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I notice that you are enabling interrupts prior to the initialisation functions.&amp;nbsp; Interrupts should generally not be globally enabled until after the initialisation has been completed.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Jun 2013 18:40:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Watchdog-enables-itself-after-reset/m-p/233183#M19428</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2013-06-22T18:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Watchdog enables itself after reset</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Watchdog-enables-itself-after-reset/m-p/233184#M19429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your answer and useful tips. I would be glad to hear &lt;EM&gt;any&lt;/EM&gt; criticism to my code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With your helpful answer, I have started investigating the problem and tried writing to WDOG_CS1 at once. Also, I have tried adding this code (WDOG_CS1=0;) into the startup code so that it is processed very early (within 128 bus clocks) after reset. However, that did not solve my problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, I have run across this sentence in page 615 of the &lt;A href="http://cache.freescale.com/files/microcontrollers/doc/ref_manual/MC9S08PT60RM.pdf" rel="nofollow noopener noreferrer" target="_blank"&gt;reference manual&lt;/A&gt;, under section 23.3.2:&lt;/P&gt;&lt;BLOCKQUOTE&gt;
&lt;P&gt;The new configuration takes effect only after all registers except WDOG_CNTH:L are&lt;/P&gt;
&lt;P&gt;written once after reset. Otherwise, the WDOG uses the reset values by default. If&lt;/P&gt;
&lt;P&gt;window mode is not used (WDOG_CS2[WIN] is 0), writing to WDOG_WINH:L is not&lt;/P&gt;
&lt;P&gt;required to make the new configuration take effect.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I have added following code to my &lt;SPAN style="color: #000000; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; background-color: #ffffff;"&gt;initialize_CPU()&lt;/SPAN&gt; function and it works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13719829607169637" jivemacro_uid="_13719829607169637"&gt;
&lt;P&gt;&amp;nbsp; WDOG_CS1 = 0x60;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; WDOG_CS2 = 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; WDOG_TOVAL = 0x04;&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 23 Jun 2013 10:04:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Watchdog-enables-itself-after-reset/m-p/233184#M19429</guid>
      <dc:creator>abdullahkahrama</dc:creator>
      <dc:date>2013-06-23T10:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Watchdog enables itself after reset</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Watchdog-enables-itself-after-reset/m-p/233185#M19430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;BLOCKQUOTE&gt;
&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;Abdullah Kahraman wrote:&lt;/P&gt;
&lt;P&gt;The new configuration takes effect only after all registers except WDOG_CNTH:L are&lt;/P&gt;
&lt;P&gt;written once after reset. Otherwise, the WDOG uses the reset values by default. If&lt;/P&gt;
&lt;P&gt;window mode is not used (WDOG_CS2[WIN] is 0), writing to WDOG_WINH:L is not&lt;/P&gt;
&lt;P&gt;required to make the new configuration take effect.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Now I have added following code to my &lt;SPAN style="background-color: #ffffff; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; color: #000000; font-size: 12px;"&gt;initialize_CPU()&lt;/SPAN&gt; function and it works: &lt;/P&gt;
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;
&lt;DIV class="dp-highlighter"&gt;&lt;DIV class="bar"&gt;&lt;DIV&gt; WDOG_CS1 = 0x60;&lt;BR /&gt; WDOG_CS2 = 1;&lt;BR /&gt; WDOG_TOVAL = 0x04;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The watchdog timer is much more finicky than the COP timer within other MCU derivatives!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I would expect that this should still work with WDOG_CS1 = 0;&lt;/P&gt;&lt;P&gt;Enabling the watchdog interrupt is somewhat pointless since the watchdog counter is disabled, and the interrupt will never occur.&amp;nbsp; And as I said previously, the update bit would only need to be set if you intended to enable the watchdog counter later in your code.&amp;nbsp; Generally, the update facility would only apply to the use of a bootloader.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A general observation about the watchdog operation concerns the ANSI code for copy down of global variable initial values, whichis executed prior to main() being called.&amp;nbsp; After POR the watchdog timer will be operational, and will time out after a period of 3.2 milliseconds, with worst case tolerance.&amp;nbsp; This means that the copy down process should be completed in less than this period, when executed at the POR default bus frequency.&amp;nbsp; This period should be satisfactory for most projects.&amp;nbsp; However, if a particular project had an abnormally large number of globals, including large arrays, the copy down process might need to be eliminated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jun 2013 18:57:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Watchdog-enables-itself-after-reset/m-p/233185#M19430</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2013-06-25T18:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Watchdog enables itself after reset</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Watchdog-enables-itself-after-reset/m-p/233186#M19431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you are very right about the value of WDOG_CS1 register, it is set pointlessly. I am new to Freescale microcontroller world and I am trying to learn. So, for learning purposes, I am aware that I am doing pointless things :smileyhappy:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, thanks again for these &lt;EM&gt;wonderful&lt;/EM&gt; tips!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 06:14:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Watchdog-enables-itself-after-reset/m-p/233186#M19431</guid>
      <dc:creator>abdullahkahrama</dc:creator>
      <dc:date>2013-06-26T06:14:30Z</dc:date>
    </item>
  </channel>
</rss>

