aboutsummaryrefslogtreecommitdiffstats
path: root/libs-device
diff options
context:
space:
mode:
authorChristian Starkjohann <cs+github@obdev.at>2008-10-20 16:15:56 +0000
committerChristian Starkjohann <cs+github@obdev.at>2008-10-20 16:15:56 +0000
commit49af025c988b13e64a6683fe65a31e2f80afe37b (patch)
tree9a074c138776d06df5390fe934b840462398559f /libs-device
parentebbb33ad837a582b9efa735a62b7fcbb6e21e5ea (diff)
downloadv-usb-49af025c988b13e64a6683fe65a31e2f80afe37b.tar.gz
v-usb-49af025c988b13e64a6683fe65a31e2f80afe37b.tar.bz2
v-usb-49af025c988b13e64a6683fe65a31e2f80afe37b.zip
- updated comments to mention osctune
Diffstat (limited to 'libs-device')
-rw-r--r--libs-device/osccal.c5
-rw-r--r--libs-device/osccal.h18
2 files changed, 14 insertions, 9 deletions
diff --git a/libs-device/osccal.c b/libs-device/osccal.c
index 5734a84..01f9002 100644
--- a/libs-device/osccal.c
+++ b/libs-device/osccal.c
@@ -17,11 +17,6 @@
* signal (a single SE0 bit) repeating every millisecond immediately after
* a USB RESET. We first do a binary search for the OSCCAL value and then
* optimize this value with a neighboorhod search.
- * This algorithm may also be used to calibrate the RC oscillator directly to
- * 12 MHz (no PLL involved, can therefore be used on almost ALL AVRs), but this
- * is wide outside the spec for the OSCCAL value and the required precision for
- * the 12 MHz clock! Use the RC oscillator calibrated to 12 MHz for
- * experimental purposes only!
*/
void calibrateOscillator(void)
{
diff --git a/libs-device/osccal.h b/libs-device/osccal.h
index 8bd0209..e2fdb07 100644
--- a/libs-device/osccal.h
+++ b/libs-device/osccal.h
@@ -17,7 +17,17 @@ immediately after a USB RESET condition. Timing is done by counting CPU
cycles, so all interrupts must be disabled while the calibration runs. For
low level timing measurements, usbMeasureFrameLength() is called. This
function must be enabled in usbconfig.h by defining
-USB_CFG_HAVE_MEASURE_FRAME_LENGTH to 1.
+USB_CFG_HAVE_MEASURE_FRAME_LENGTH to 1. It is also recommended to call
+calibrateOscillator() from the reset hook in usbconfig.h:
+
+#ifndef __ASSEMBLER__
+#include <avr/interrupt.h> /* for sei() */
+extern void calibrateOscillator(void);
+#endif
+#define USB_RESET_HOOK(resetStarts) if(!resetStarts){cli(); calibrateOscillator(); sei();}
+
+This routine is an alternative to the continuous synchronization described
+in osctune.h.
Algorithm used:
calibrateOscillator() first does a binary search in the OSCCAL register for
@@ -33,9 +43,9 @@ optimum value is far below 192. It may therefore exceed the allowed clock
frequency of the CPU in low voltage designs!
Precision depends on the OSCCAL vs. frequency dependency of the oscillator.
Typical precision for an ATMega168 (derived from the OSCCAL vs. F_RC diagram
-in the data sheet) should be in the range of 0.4%. Only the 16.5 MHz version
-of AVR-USB (with built-in receiver PLL) can tolerate this deviation! All other
-frequency modules require at least 0.3% precision.
+in the data sheet) should be in the range of 0.4%. Only the 12.8 MHz and
+16.5 MHz versions of AVR-USB (with built-in receiver PLL) can tolerate this
+deviation! All other frequency modules require at least 0.2% precision.
*/
#ifndef __OSCCAL_H_INCLUDED__