From 49af025c988b13e64a6683fe65a31e2f80afe37b Mon Sep 17 00:00:00 2001 From: Christian Starkjohann Date: Mon, 20 Oct 2008 16:15:56 +0000 Subject: - updated comments to mention osctune --- libs-device/osccal.c | 5 ----- libs-device/osccal.h | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'libs-device') 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 /* 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__ -- cgit v1.2.3