<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forums.obdev.at/app.php/feed/topic/1202" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2008-02-18T04:00:08+02:00</updated>

	<author><name><![CDATA[Objective Development Forums]]></name></author>
	<id>https://forums.obdev.at/app.php/feed/topic/1202</id>

		<entry>
		<author><name><![CDATA[Grendel]]></name></author>
		<updated>2008-02-18T04:00:08+02:00</updated>

		<published>2008-02-18T04:00:08+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4263#p4263</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4263#p4263"/>
		<title type="html"><![CDATA[Watchdog reset doesn't work properly]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4263#p4263"><![CDATA[
Funny, I just ran into the same thing after I switched from a mega8 to a tiny461 <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":)" title="Smile" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=101">Grendel</a> — Mon Feb 18, 2008 4:00 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[iphi]]></name></author>
		<updated>2008-02-09T22:01:34+02:00</updated>

		<published>2008-02-09T22:01:34+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4193#p4193</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4193#p4193"/>
		<title type="html"><![CDATA[Watchdog reset doesn't work properly]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4193#p4193"><![CDATA[
I can fonfirm that the above was the reason for my watchdog problems.<br />After having added the following piece of code suggested in AVR-libc my watchdog reset works perfectly.<br /><br /> <div class="codebox"><p>Code: </p><pre><code>#include &lt;stdint.h&gt;<br />    #include &lt;avr/wdt.h&gt;<br /><br />    uint8_t mcusr_mirror _attribute_ &#40;&#40;section &#40;&quot;.noinit&quot;&#41;&#41;&#41;;<br /><br />    void get_mcusr&#40;void&#41; \<br />      __attribute__&#40;&#40;naked&#41;&#41; \<br />      __attribute__&#40;&#40;section&#40;&quot;.init3&quot;&#41;&#41;&#41;;<br />    void get_mcusr&#40;void&#41;<br />    &#123;<br />      mcusr_mirror = MCUSR;<br />      MCUSR = 0;<br />      wdt_disable&#40;&#41;;<br />    &#125;<br /></code></pre></div><br /><br />Regards, Tom<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=292">iphi</a> — Sat Feb 09, 2008 10:01 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[iphi]]></name></author>
		<updated>2008-02-09T19:10:36+02:00</updated>

		<published>2008-02-09T19:10:36+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4192#p4192</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4192#p4192"/>
		<title type="html"><![CDATA[Watchdog reset doesn't work properly]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4192#p4192"><![CDATA[
Hi Grendel,<br /><br />thanks for your proposal. I'll try that.<br /><br />All,<br /><br />I think I have found the reason for the strange behavior of my ATTINY45 compared to the ATMEGA8:<br /><br />The watchdog remains on even after watchdog reset, thus the system won't stay in the 0.5 second delay loop. This is described in the AVR-libc documentation:<br /><br /><blockquote class="uncited"><div>Note that for newer devices (ATmega88 and newer, effectively any AVR that has the option to also generate interrupts), the watchdog timer remains active even after a system reset (except a power-on condition), using the fastest prescaler value (approximately 15 ms). It is therefore required to turn off the watchdog early during program startup, the datasheet recommends a sequence like the following:...</div></blockquote><br /><br />Regards, Tom<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=292">iphi</a> — Sat Feb 09, 2008 7:10 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Grendel]]></name></author>
		<updated>2008-02-09T09:26:52+02:00</updated>

		<published>2008-02-09T09:26:52+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4191#p4191</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4191#p4191"/>
		<title type="html"><![CDATA[Watchdog reset doesn't work properly]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4191#p4191"><![CDATA[
How is that delay() function defined ?<br /><br />Do you  have a &quot;dynamic&quot; speed R that allows you to use usbDeviceConnect() and usbDeviceDisconnect() ? I use the same logic to reset my converter but w/ a usbDeviceDisconnect() just before the forever loop. Works every time <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":)" title="Smile" /> Plus, you don't need to create a reset condition on the bus after a usbDeviceConnect():<br /><br /><div class="codebox"><p>Code: </p><pre><code>    wdt_enable&#40; WDTO_500MS &#41; ;                  // Unleash watchdog<br /><br />    sei&#40;&#41; ;                                     // Enable interrupts<br />                                                // Preset report<br />    usbSetInterrupt&#40; sw_report, SW_REPORTSZ &#41; ;<br /><br />    usbDeviceConnect&#40;&#41; ;                        // Activate ID resistor<br /><br />    for &#40; ;; &#41;                                  // Forever..<br />    &#123;<br />        wdt_reset&#40;&#41; ;                           // Calm watchdog<br /><br />        usbPoll&#40;&#41; ;                             // Do USB stuff<br /></code></pre></div><br /><br />No problems whatsoever.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=101">Grendel</a> — Sat Feb 09, 2008 9:26 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[iphi]]></name></author>
		<updated>2008-02-08T23:40:34+02:00</updated>

		<published>2008-02-08T23:40:34+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4186#p4186</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4186#p4186"/>
		<title type="html"><![CDATA[Watchdog reset doesn't work properly]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4186#p4186"><![CDATA[
Hi Christian,<br /><br />my confusion is growing. I have made the following experiments:<br /><br />1. Done the modification you suggested with the global variable and suppressing the wdtreset in the main loop.<br />=&gt; doesn't work, same as my first attempt<br /><br />2. Tried a hardware reset on pin 1 instead:<br />a) An initial hardware reset works fine, also repeatedly.<br />b) A hardware reset after the above software reset doesn't bring the device back to life. It continues sending strange signals out the USB bus.<br /><br />I thought there's nothing higher priority than a hardware reset!???<br /><br />Do you have any more ideas?<br /><br />Regards Tom<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=292">iphi</a> — Fri Feb 08, 2008 11:40 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[iphi]]></name></author>
		<updated>2008-02-08T20:40:37+02:00</updated>

		<published>2008-02-08T20:40:37+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4185#p4185</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4185#p4185"/>
		<title type="html"><![CDATA[Watchdog reset doesn't work properly]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4185#p4185"><![CDATA[
<blockquote class="uncited"><div>BTW: 1400000 is an integer constant, it would be 1400000L otherwise. Do you get a compiler warning for this?</div></blockquote><br /><br />No, there's no compiler warning. As I'm a C beginner I'm quite paranoic to avoid any compiler warnings as I have learned that C warnings are serious in contrast to Pascal warnings. My code compiles with zero errors and zero warnings. I have also checked functionality of the delay loop inside the AVR Studio simulator in sourcecode and in disassembler. All is definitely fine here.<br /><br />Regards, Tom<br /><br />P.S. Think I have a hint: I have connected an oscilloscope to one of the USB data lines. I do see the 0.5 second pulse at first connection. But when I invoke the watchdog I do see many and more short pulses but no 0.5 second pulse. Now I just have to think about how to explain this.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=292">iphi</a> — Fri Feb 08, 2008 8:40 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-02-08T19:46:21+02:00</updated>

		<published>2008-02-08T19:46:21+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4183#p4183</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4183#p4183"/>
		<title type="html"><![CDATA[Watchdog reset doesn't work properly]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4183#p4183"><![CDATA[
Just because it works with 12 MHz does not mean that the code does what it's intended to do. Many problems depend on tiny deviations in the timing.<br /><br />BTW: 1400000 is an integer constant, it would be 1400000L otherwise. Do you get a compiler warning for this?<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Fri Feb 08, 2008 7:46 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[iphi]]></name></author>
		<updated>2008-02-08T19:42:25+02:00</updated>

		<published>2008-02-08T19:42:25+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4182#p4182</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4182#p4182"/>
		<title type="html"><![CDATA[Watchdog reset doesn't work properly]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4182#p4182"><![CDATA[
<blockquote class="uncited"><div>You force a RESET in the middle of a USB command. This may confuse the host. It would be cleaner to set a global variable so that the main loop does not call wdt_reset(), but still calls usbPoll() until the reset occurs. </div></blockquote><br />Good point. But why is it working every time without fault on a crystal driven atmega8 then? I'll give it a try.<br /><br /><blockquote class="uncited"><div>Other than that: Did you check whether delay(1400000) really generates a long enough (&gt; 250 ms) delay? There might be an integer overflow.</div></blockquote><br />I use long integer here which doesn't overflow. Also identical code which works on the atmega8/12MHz.<br /><br />Could there be something connected to the RC oscillator or the 16.5MHz driver?<br /><br />Best regards, Tom<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=292">iphi</a> — Fri Feb 08, 2008 7:42 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-02-08T17:07:58+02:00</updated>

		<published>2008-02-08T17:07:58+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4181#p4181</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4181#p4181"/>
		<title type="html"><![CDATA[Watchdog reset doesn't work properly]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4181#p4181"><![CDATA[
You force a RESET in the middle of a USB command. This may confuse the host. It would be cleaner to set a global variable so that the main loop does not call wdt_reset(), but still calls usbPoll() until the reset occurs.<br /><br />Other than that: Did you check whether delay(1400000) really generates a long enough (&gt; 250 ms) delay? There might be an integer overflow.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Fri Feb 08, 2008 5:07 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[iphi]]></name></author>
		<updated>2008-02-08T08:26:19+02:00</updated>

		<published>2008-02-08T08:26:19+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4179#p4179</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4179#p4179"/>
		<title type="html"><![CDATA[Watchdog reset doesn't work properly]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1202&amp;p=4179#p4179"><![CDATA[
Hello,<br /><br />I have AVRUSB running on ATTINY45 with RC oscillator on 16.5MHz. I have coded such that I can reset the device via Watchdog timer like this:<br /><div class="codebox"><p>Code: </p><pre><code>USB_PUBLIC uchar usbFunctionSetup&#40;uchar data&#91;8&#93;&#41;<br />&#123;<br />usbRequest_t *rq = &#40;void *&#41;data;<br />...<br />   if&#40;rq-&gt;bRequest == 0xf&#41;&#123;             // Reset by Watchdog<br />        for &#40;;;&#41;&#123;&#125;;<br />        return 0;<br />    &#125;<br /></code></pre></div><br /><br />When I invoke the watchdog the device will fail to enumerate again. <br />Here's my main code:<br /><div class="codebox"><p>Code: </p><pre><code>int main&#40;void&#41;<br />&#123;<br />    OSCCAL=0x5b;<br />    DDRB = &#40;1 &lt;&lt; USB_CFG_DMINUS_BIT&#41; | &#40;1 &lt;&lt; USB_CFG_DPLUS_BIT&#41;;<br />    PORTB = 0;             // indicate USB disconnect to host */<br />    delay&#40;1400000&#41;;         // delay 6x1.4=8.4 million clocks = 0.51secs<br />    DDRB = 0;            //all inputs<br />    wdt_enable&#40;WDTO_15MS&#41;;<br />    usbInit&#40;&#41;;<br />    sei&#40;&#41;;<br />    for&#40;;;&#41;&#123;    /* main event loop */<br />           wdt_reset&#40;&#41;;<br />           usbPoll&#40;&#41;;<br />    &#125;<br />&#125; </code></pre></div><br /><br />The OSCCAL value is experimentally determined and optimum.<br />What am I doing wrong?<br /><br />BTW: Basically the same code on an ATMEGA8 with 12MHz reenumerates fine after watchdog reset.<br /><br />BR Tom<br /><br />Regards, Tom<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=292">iphi</a> — Fri Feb 08, 2008 8:26 am</p><hr />
]]></content>
	</entry>
	</feed>
