<?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/1194" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2008-03-17T18:31:00+02:00</updated>

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

		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-03-17T18:31:00+02:00</updated>

		<published>2008-03-17T18:31:00+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4638#p4638</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4638#p4638"/>
		<title type="html"><![CDATA[occasional transmission errors with 16.5MHz RC oscillator]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4638#p4638"><![CDATA[
USB RESET is when D+ and D- are both 0 for more than a couple of bits. The host sends USB RESET after connecting or when it sees other reasons for a reset (e.g. timeout during enumeration).<br /><br />AVR-USB detects a RESET in usbPoll(). If it sees a RESET, it runs the hook macro when the reset status begins and when it ends.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Mon Mar 17, 2008 6:31 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[iphi]]></name></author>
		<updated>2008-03-17T18:16:10+02:00</updated>

		<published>2008-03-17T18:16:10+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4637#p4637</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4637#p4637"/>
		<title type="html"><![CDATA[occasional transmission errors with 16.5MHz RC oscillator]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4637#p4637"><![CDATA[
<blockquote class="uncited"><div>We calibrate on every USB reset anyway.</div></blockquote><br /><br />It seems I don't fully understand how this works yet. How will a USB reset be initiated? Does this happen on first connection only? Can the host also initiate a USB reset?<br />Exactly on what condition and from where will calibrateOscillator be called?<br /><br />Thanks for helping me understand.<br /><br />Regards, Thomas<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=292">iphi</a> — Mon Mar 17, 2008 6:16 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-03-17T17:13:27+02:00</updated>

		<published>2008-03-17T17:13:27+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4636#p4636</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4636#p4636"/>
		<title type="html"><![CDATA[occasional transmission errors with 16.5MHz RC oscillator]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4636#p4636"><![CDATA[
We calibrate on every USB reset anyway. But if the device starts without USB connection, it's good to have a guess value available from last time. Other functionality of the firmware may require accurate timing, too.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Mon Mar 17, 2008 5:13 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[iphi]]></name></author>
		<updated>2008-03-17T17:08:19+02:00</updated>

		<published>2008-03-17T17:08:19+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4635#p4635</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4635#p4635"/>
		<title type="html"><![CDATA[occasional transmission errors with 16.5MHz RC oscillator]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4635#p4635"><![CDATA[
Hi Christian,<br /><br />thanks for this hint. It was the watchdog firing resets during calibration.<br />Now everything works fine.<br /><br />BTW:<br />The auto-calibration works very well and subjectively does not require any time. Therefore I suggest not to store the CSCCAL value in the EEPROM and reuse it but to recalibrate on every reset. This way ageing drifts and temperature drifts can be compensated.<br /><br />Thank you very much for this great new feature!<br /><br />Regards, Thomas<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=292">iphi</a> — Mon Mar 17, 2008 5:08 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-03-17T12:28:54+02:00</updated>

		<published>2008-03-17T12:28:54+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4630#p4630</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4630#p4630"/>
		<title type="html"><![CDATA[occasional transmission errors with 16.5MHz RC oscillator]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4630#p4630"><![CDATA[
This might be watchdog resets. Calibration takes a while. If your watchdog is too fast, it will cause a reset.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Mon Mar 17, 2008 12:28 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[iphi]]></name></author>
		<updated>2008-03-16T23:42:58+02:00</updated>

		<published>2008-03-16T23:42:58+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4608#p4608</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4608#p4608"/>
		<title type="html"><![CDATA[occasional transmission errors with 16.5MHz RC oscillator]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4608#p4608"><![CDATA[
I don't use interrupts in my application. Also, I don't see the code write any value into the EEPROM.<br /><br />It looks as if the AVR undergoes continuous resets. Any other idea what could go wrong?<br /><br />Did I miss out on anything else inside the usbconfig.h?<br /><br />Regards, Thomas<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=292">iphi</a> — Sun Mar 16, 2008 11:42 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-03-16T23:27:27+02:00</updated>

		<published>2008-03-16T23:27:27+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4606#p4606</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4606#p4606"/>
		<title type="html"><![CDATA[occasional transmission errors with 16.5MHz RC oscillator]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4606#p4606"><![CDATA[
If you use interrupts in your main code, enclose the call to calibrateOscillator() in cli() and sei(). Since timing is measured by counting CPU cycles, no interrupts may occur.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Sun Mar 16, 2008 11:27 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[iphi]]></name></author>
		<updated>2008-03-16T19:31:44+02:00</updated>

		<published>2008-03-16T19:31:44+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4602#p4602</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4602#p4602"/>
		<title type="html"><![CDATA[occasional transmission errors with 16.5MHz RC oscillator]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4602#p4602"><![CDATA[
Hello Christian,<br /><br />I have tried your OSCCAL auto-calibration code. In easylogger it works fine, but I can't get it running in my own application.<br /><br />Here is what I did:<br /><br />1. I have updated the drivers directory usbdrv with the latest drivers, recompiled my project and flashed it. Works fine.<br />2. I have edited my old USBConfig.h and added the following lines:<br /><div class="codebox"><p>Code: </p><pre><code>#ifndef __ASSEMBLER__<br />extern void usbEventResetReady&#40;void&#41;;<br />#endif<br />#define USB_RESET_HOOK&#40;isReset&#41;             if&#40;!isReset&#41;&#123;usbEventResetReady&#40;&#41;;&#125;<br />/* This macro is a hook if you need to know when an USB RESET occurs. It has<br /> * one parameter which distinguishes between the start of RESET state and its<br /> * end.<br /> */<br />#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH   1<br />/* define this macro to 1 if you want the function usbMeasureFrameLength&#40;&#41;<br /> * compiled in. This function can be used to calibrate the AVR's RC oscillator.<br /> */</code></pre></div><br /><br />3. I have copied the following code into my application:<br /><br /><div class="codebox"><p>Code: </p><pre><code>static void calibrateOscillator&#40;void&#41;<br />&#123;<br />uchar       step = 128;<br />uchar       trialValue = 0, optimumValue;<br />int         x, optimumDev, targetValue = &#40;unsigned&#41;&#40;1499 * &#40;double&#41;F_CPU / 10.5e6 + 0.5&#41;;<br /><br />    /* do a binary search: */<br />    do&#123;<br />        OSCCAL = trialValue + step;<br />        x = usbMeasureFrameLength&#40;&#41;;    /* proportional to current real frequency */<br />        if&#40;x &lt; targetValue&#41;             /* frequency still too low */<br />            trialValue += step;<br />        step &gt;&gt;= 1;<br />    &#125;while&#40;step &gt; 0&#41;;<br />    /* We have a precision of +/- 1 for optimum OSCCAL here */<br />    /* now do a neighborhood search for optimum value */<br />    optimumValue = trialValue;<br />    optimumDev = x; /* this is certainly far away from optimum */<br />    for&#40;OSCCAL = trialValue - 1; OSCCAL &lt;= trialValue + 1; OSCCAL++&#41;&#123;<br />        x = usbMeasureFrameLength&#40;&#41; - targetValue;<br />        if&#40;x &lt; 0&#41;<br />            x = -x;<br />        if&#40;x &lt; optimumDev&#41;&#123;<br />            optimumDev = x;<br />            optimumValue = OSCCAL;<br />        &#125;<br />    &#125;<br />    OSCCAL = optimumValue;<br />&#125;<br />/*<br />Note: This calibration algorithm may try OSCCAL values of up to 192 even if<br />the optimum value is far below 192. It may therefore exceed the allowed clock<br />frequency of the CPU in low voltage designs!<br />You may replace this search algorithm with any other algorithm you like if<br />you have additional constraints such as a maximum CPU clock.<br />For version 5.x RC oscillators &#40;those with a split range of 2x128 steps, e.g.<br />ATTiny25, ATTiny45, ATTiny85&#41;, it may be useful to search for the optimum in<br />both regions.<br />*/<br /><br />void    usbEventResetReady&#40;void&#41;<br />&#123;<br />    calibrateOscillator&#40;&#41;;<br />    eeprom_write_byte&#40;0, OSCCAL&#41;;   /* store the calibrated value in EEPROM */<br />&#125;</code></pre></div><br />I have left my main() untouched for this next step.<br /><br />The code compiles fine, but the device won't connect. <br /><br />What am I doing wrong?<br /><br />Regards, Thomas<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=292">iphi</a> — Sun Mar 16, 2008 7:31 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[iphi]]></name></author>
		<updated>2008-02-29T09:06:58+02:00</updated>

		<published>2008-02-29T09:06:58+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4424#p4424</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4424#p4424"/>
		<title type="html"><![CDATA[occasional transmission errors with 16.5MHz RC oscillator]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4424#p4424"><![CDATA[
Great! I'll try this!<br /><br />Thomas<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=292">iphi</a> — Fri Feb 29, 2008 9:06 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-02-28T23:53:09+02:00</updated>

		<published>2008-02-28T23:53:09+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4418#p4418</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4418#p4418"/>
		<title type="html"><![CDATA[occasional transmission errors with 16.5MHz RC oscillator]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1194&amp;p=4418#p4418"><![CDATA[
Just for your information: We have released EasyLogger 2008-02-28 today. This version adds self-calibration of the RC oscillator.<br /><br />In principle, this calibration algorithm can be used to calibrate the RC oscillator directly to 12 MHz. However, the precision is not high enough for the 12 MHz module (because it does not have a software PLL) and 12 MHz is outside the specified range of OSCCAL values. It's still an interesting field for experiments...<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Thu Feb 28, 2008 11:53 pm</p><hr />
]]></content>
	</entry>
	</feed>
