calib_values.h

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00025 #ifndef __CALIB_VALUES_H__
00026 #define __CALIB_VALUES_H__
00027 
00039 //#define CALIBRATION_METHOD_BINARY_WITHOUT_NEIGHBOR
00040 //#define CALIBRATION_METHOD_SIMPLE
00041 
00044 #define CALIBRATION_FREQUENCY 1000000
00045 
00048 #define XTAL_FREQUENCY 32768
00049 #define EXTERNAL_TICKS 100               // ticks on XTAL. Modify to increase/decrease accuracy
00050 
00056 #define FALSE 0
00057 #define TRUE 1
00058 #define RUNNING 0
00059 #define FINISHED 1
00060 #define DEFAULT_OSCCAL_MASK        0x00  // Lower half and
00061 #define DEFAULT_OSCCAL_MASK_HIGH   0x80  // upper half for devices with splitted OSCCAL register
00062 
00063 #include "device_specific.h"
00064 
00065 #define DEFAULT_OSCCAL_HIGH ((1 << (OSCCAL_RESOLUTION - 1)) | DEFAULT_OSCCAL_MASK_HIGH)
00066 #define INITIAL_STEP         (1 << (OSCCAL_RESOLUTION - 2))
00067 #define DEFAULT_OSCCAL      ((1 << (OSCCAL_RESOLUTION - 1)) | DEFAULT_OSCCAL_MASK)
00068 
00069 // **** Functions implemented as macros to avoid function calls
00070 #define PREPARE_CALIBRATION() \
00071 calStep = INITIAL_STEP; \
00072 calibration = RUNNING;
00073 
00074 #define COMPUTE_COUNT_VALUE() \
00075 countVal = ((EXTERNAL_TICKS*CALIBRATION_FREQUENCY)/(XTAL_FREQUENCY*LOOP_CYCLES));
00076 
00077 // Set up timer to be ASYNCHRONOUS from the CPU clock with a second EXTERNAL 32,768kHz CRYSTAL driving it. No prescaling on asynchronous timer.
00078 #define SETUP_ASYNC_TIMER() \
00079 ASSR |= (1<<ASYNC_TIMER); \
00080 ASYNC_TIMER_CONTROL_REGISTER = (1<<NO_PRESCALING);
00081 
00082 
00083 
00084 
00085 // For ATmega64 and ATmega128, 8 nop instructions must be run after a
00086 // change in OSCCAL to ensure stability (See errata in datasheet).
00087 // For all other devices, one nop instruction should be run to let
00088 // the RC oscillator stabilize.
00089 // The NOP() macro takes care of this.
00090 #if defined(__AT90Mega64__) | defined(__ATmega64__) | \
00091     defined(__AT90Mega128__) | defined(__ATmega128__)
00092 
00093 #define NOP() \
00094 __no_operation(); \
00095 __no_operation(); \
00096 __no_operation(); \
00097 __no_operation(); \
00098 __no_operation(); \
00099 __no_operation(); \
00100 __no_operation(); \
00101 __no_operation();
00102 
00103 
00104 #else
00105 #define NOP() __no_operation()
00106 #endif
00107 
00108 // Absolute value macro.
00109 #define ABS(var) (((var) < 0) ? -(var) : (var));
00110 
00111 #endif
00112 

Generated on Fri Feb 17 13:50:24 2006 for AVR055 - Using a 32 kHz crystal to calibrate the internal RC oscillatore by  doxygen 1.4.5