Download: AVR055: Using a 32kHz XTAL for run-time calibration of the internal RC

AVR055: Using a 32kHz XTAL for run-time calibration of the internal RC Features • Calibration using a 32 kHz external crystal • Adjustable RC frequency with maximum +/-2% accuracy • Tune RC oscillator at any operating voltage and temperature • Tune RC oscillator to any frequency within specification • Support for all AVRs with tunable RC oscillator and asynchronous timer • Selectable calibration clock frequency 1 Introduction The majority of the present AVR microcontrollers offer the possibility to run from an internal RC oscillator. The internal RC oscillator frequency can in most AVRs be cal...
Author: Tucker Shared: 8/19/19
Downloads: 5 Views: 169

Content

AVR055: Using a 32kHz XTAL for run-time

calibration of the internal RC

Features

• Calibration using a 32 kHz external crystal • Adjustable RC frequency with maximum +/-2% accuracy • Tune RC oscillator at any operating voltage and temperature • Tune RC oscillator to any frequency within specification • Support for all AVRs with tunable RC oscillator and asynchronous timer • Selectable calibration clock frequency 1 Introduction The majority of the present AVR microcontrollers offer the possibility to run from an internal RC oscillator. The internal RC oscillator frequency can in most AVRs be calibrated to within +/-2% of the frequency specified in the datasheet for the device, for some devices even +/-1% accuracy is achievable. The calibration performed in the Atmel factory is made at a fixed operating voltage and temperature. As the frequency of the internal RC oscillator is affected by both operating voltage and temperature, it is sometimes desirable to perform a secondary calibration. AVR devices with internal RC Oscillator and an OSCCAL Calibration Register can be calibrated very accurately by using an external signal with stable frequency such as a 32 kHz watch crystal. This secondary calibration can be useful if running the device at a temperature or supply voltage level different from the default values (25°C, typically 5V) matching the specific application environment, or even to tune the oscillator to a different frequency. Using an external watch crystal for internal oscillator run-time calibration results in a cost efficient solution for applications that needs an accurate system clock over the entire temperature range, and independent of operating voltage. This application note describes a fast and accurate way to calibrate the internal RC oscillator using an external 32.768 kHz crystal as input to an asynchronous Timer/Counter. 8-bit

Microcontrollers Application Note

Rev. 8002A-AVR-09/05, 2 Theory of operation – the internal RC oscillator In production the internal RC is calibrated at either 5V or 3.3V. Refer to the datasheet of the individual devices for information about the operating voltage used during calibration. The accuracy of the factory calibration is within +/-3 or +/-10% (refer to the datasheet). If a design’s need for accuracy is beyond what can be offered by the standard calibration in factory by Atmel, it is possible to perform a secondary calibration of the RC oscillator. By doing this it is possible to obtain frequency accuracy within +/-1 (+/-2% for those with an 10% accuracy from factory calibration). A secondary calibration can thus be performed to improve or tailor the accuracy or frequency of the oscillator. 3 Clock selection The AVR fuse settings control the system clock source being used. To use the internal oscillator, the corresponding fuse setting must be selected. An overview of the fuses is available in the datasheets. When calibrating using an external crystal, the system clock must run from the internal oscillator. 4 Crystal Connection In most AVR devices, external capacitors need to be connected to the TOSC1/2 pins, when connecting an external crystal. This applies to all parts with 1.8V capabilities. In other parts, the crystal can be connected directly between the TOSC1/2 pins. Refer do the device datasheet for details on crystal connections. 5 Base-frequency The following sections provide an overview of the internal RC oscillators available in the AVR microcontrollers. Some AVRs have one RC oscillator, while others have up to 4 different RC oscillators to choose from. The frequency ranges from 1MHz to 9.6MHz. To make the internal RC oscillator sufficiently accurate, an Oscillator Calibration register, OSCCAL, is present in the AVR I/O file. The OSCCAL register is one byte wide. The purpose of this register is to be able to tune the oscillator frequency. This tuning is utilized when calibrating the RC oscillator. When calibrating using an external crystal, the device timer must have the possibility to operate asynchronously of the system clock. When a device is calibrated by Atmel, the calibration byte is stored in the Signature Row of the device. The calibration byte can vary from one device to the other, as the RC oscillator frequency is process dependent. If a device has more than one oscillator, a calibration byte for each of the RC oscillators is stored in the Signature Row. The default RC oscillator calibration byte is in most devices automatically loaded from the Signature Row and copied into the OSCCAL register at start-up. For example, the default ATmega8 clock setting is the internal 1MHz RC oscillator; for this device the calibration byte corresponding to the 1MHz RC oscillator is automatically loaded at start-up. If the fuses are altered so that the 4MHz oscillator is used instead of the default setting, the calibration byte must be loaded into the OSCCAL register manually. A programming tool can be used to read the 4MHz calibration byte from the 2 AVR055,

AVR055

Signature Row, and store it in a Flash or EEPROM location, which is read by the main program and copied into OSCCAL at run-time. In addition to the oscillator tuning using the OSCCAL register, some devices feature a system clock prescaler. The prescaler register (CLKPR) can be used to scale the system clock with predefined twos complement factors. Also, this prescaler can be preset through the AVR fuses; programming the CKDIV8 fuse will set the CLKPR to divide the system clock by 8. This can be done to ensure that the device is operated below a maximum frequency specification. The CLKPR can be modified at run-time to change the frequency of the system clock internally. The base frequency of an oscillator is defined as the unscaled oscillator frequency. 6 RC Oscillator overview Different RC oscillators have been utilized in the AVR microcontrollers throughout the history. An overview of the devices and their RC oscillators is seen in Table 6-1. The device list is sorted by oscillator type, which is also more or less equivalent to sorting them by release date. Only devices with tunable oscillators, and the possibility to operate asynchronously from an external crystal are listed in the table. Table 6-1.Oscillator frequencies and features of devices with internal RC oscillator(s). Grouped by oscillator version. Oscillator Device RC oscillator CKDIV CLKPR version frequency [MHz] 2.0 ATmega163 1.0 - - 2.0 ATmega323 1.0 - - 3.0 ATmega8 1.0, 2.0, 4.0, and 8.0 - - 3.0 ATmega16 1.0, 2.0, 4.0, and 8.0 - - 3.0 ATmega32 1.0, 2.0, 4.0, and 8.0 - - 3.1 ATmega64(1) 1.0, 2.0, 4.0, and 8.0 - XDIV (2) 3.1 ATmega128(1) 1.0, 2.0, 4.0, and 8.0 - XDIV (2) 3.0 ATmega8535 1.0, 2.0, 4.0, and 8.0 - - 4.0 ATmega162 8.0 Yes Yes 4.0 ATmega169(3)(rev A-E) 8.0 Yes Yes 4.0 ATmega165 8.0 Yes Yes 5.0 ATmega48/88/168 8.0 Yes Yes 5.0 ATmega325/3250 8.0 Yes Yes ATmega645/6450 5.0 ATmega329/3290 8.0 Yes Yes ATmega649/6490 5.0 ATmega640/1280/1281 8.0 Yes Yes ATmega2560/2561 5.0 AT90CAN128 8.0 Yes Yes Notes: 1. The ATmega103 Compatible Mode fuse must be unprogrammed. Programming this fuse prevents using extended I/O and hence tuning the internal oscillator. 2. The prescaler register is in these devices named XDIV. 3. Revision F and onwards of ATmega169 use version 5 oscillator., 6.1 Version 1.x oscillators This version is the earliest internal RC for AVR that can be calibrated, though asynchronous operation is not possible. Due to this, parts having this version of the internal oscillator cannot be calibrated using an external crystal and does not appear in Table 6-1. 6.2 Version 2.x oscillators This oscillator is offered with a frequency of 1MHz. The dependency between the oscillator frequency and operating voltage and temperature is reduced significantly compared to version 1.x. 6.3 Version 3.x oscillators This version was introduced along with the first devices produced in the 35.5k process. The oscillator system is expanded to offer multiple oscillator frequencies. Four different RC oscillators with the frequencies 1, 2, 4, and 8MHz are present in the device. This version features automatic loading of the 1MHz calibration byte from the Signature Row. Due to the fact that 4 different RC oscillators are present, 4 different calibration bytes are stored in the Signature Row. If frequencies other than the default 1MHz are desired, the OSCCAL register should be loaded with the corresponding calibration byte at run-time. 6.4 Version 4.x oscillators A single oscillator frequency of 8MHz is offered in version 4.0. For later 4.x versions, two frequencies are offered: 4 and 8MHz for ATtiny2313, and 4.8 and 9.6MHz for the ATtiny13. The OSCCAL register is changed so that only 7 bits are used to tune the frequency for the selected oscillator. The MSB is not used. Auto loading of the default calibration value and system clock prescaler is present. 6.5 Version 5.x oscillators A single oscillator frequency of 8MHz is offered in version 5.0 All 8 bits in the OSCCAL register are used to tune the oscillator frequency. Auto loading of the default calibration value and system clock prescaler is present. The OSCCAL register is split in two parts. As seen in Figure 7-2, the MSB of OSCCAL selects one of two overlapping frequency ranges, while the 7 least significant bits are used to tune the frequency within this range. 7 Oscillator characteristics The frequency of the internal RC oscillator is depending on the temperature and operating voltage. An example of this dependency is seen in Figure 7-1, showing the frequency of the 8MHz RC oscillator of the ATmega3290. As seen from the figure, the frequency increases with increasing temperature and operating voltage. These characteristics will vary from device to device. For details on a specific device refer to its datasheet. 4 AVR055,

AVR055

Figure 7-1. Oscillator frequency and influence by temperature and operating voltage. ATmega3290 calibrated 8MHz RC oscillator frequency vs. VCC. CALIBRATED 8MHz RC OSCILLATOR FREQUENCY vs. VCC 8.6 8.4 85 ˚C 8.2 25 ˚C -40 ˚C 7.8 7.6 7.4 7.2 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) All devices with tunable oscillators have an OSCCAL register for tuning the oscillator frequency. An increasing value in OSCCAL will result in a “pseudo-monotone” increase in frequency. The reason for calling it pseudo-monotone is that for some unity increases of the OSCCAL value, the frequency will not increase, or even decrease slightly. However, the next unity increase will always increase the frequency again. In other words, incrementing the OSCCAL register by one may not increase the frequency, but increasing the OSCCAL value by two will always increase the frequency. This information is very relevant when searching for the best calibration value to fit a given frequency. An example of the pseudo-monotone relation between the OSCCAL value and the oscillator frequency can be seen in Figure 7-2, which is the 8MHz RC oscillator of ATmega3290. Note that some OSCCAL registers, that is OSCCAL registers in devices with version 5.0 oscillators, uses 7 bits for tuning the oscillator, as is the case in ATmega3290. The eight bit determines the range of operation. The two ranges are overlapping, as seen in Figure 7-2. Other devices use all 8 (or sometimes 7) bits in one continuous range FRC (MHz), Figure 7-2. ATmega3290 calibrated RC oscillator frequency as a function of the OSCCAL value. CALIBRATED 8MHz RC OSCILLATOR FREQUENCY vs. OSCCAL VALUE 85 ˚C 25 ˚C -40 ˚C 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 256 OSCCAL VALUE For all tunable oscillators it is important to notice that it is not recommended to tune the oscillator more than 10% off the base frequency specified in the datasheet. The reason for this is that the internal timing related to writing EEPROM and flash in the device is dependent on the RC-oscillator frequency. Knowing the fundamental characteristics of the RC oscillators, it is possible to make an efficient calibration routine that calibrates the RC oscillator to a given frequency, within 10% of the base frequency, at any operating voltage and at any temperature with an accuracy of +/-1%. 7.1 Frequency settling time When a new OSCCAL value has been set, it can take some time for the internal RC oscillator to settle at the new frequency. This settling time will vary on the different versions of the RC oscillator. Generally, the oscillator settles faster for small changes in OSCCAL, than for large changes. This settling time is under no circumstances any longer than 5 microseconds. Allow the oscillator to settle at its new frequency before making any frequency measurements for calibration. 8 Calibration using a 32.768 kHz crystal The calibration is executed ina6or 7 cycles loop, depending on whether the asynchronous timer/counter register is located in extended I/O space or not. In every loop, a counter is incremented, and the value of the 32 kHz timer is read. After a (predefined) number of ticks on the 32 kHz watch crystal, a counter which speed depends on the internal RC oscillator, is compared with the timer value. Then the value of the oscillator calibration register OSCCAL is written according to the desired calibration frequency, using binary and neighbor search. 6 AVR055 FRC (M Hz),

AVR055

The relation between the repeat count value and the frequency can be obtained from the following equation: Equation 8-1. Calculating the count value Loop Cycles × Count value × RC period = XTAL period × XTAL ticks where : 1 1 RC period = XTAL period = desired frequency XTAL frequency 9 Binary and Neighbor search Three different calibration methods are described in this application note. They are different in the way the search is performed and have different code sizes and durations. In section 7 it was pointed out that some internal oscillators have a divided OSCCAL register which is overlapping for some of the frequencies in the frequency range. For these oscillators, a search in both ranges of the OSCCAL is needed to guarantee calibration to all frequencies. Figure 7-2 illustrates that it may also be convenient to compare calibrations in both ranges of the OSCCAL for overlapping frequencies in order to obtain the optimal OSCCAL value since, for instance, a frequency of 8 MHz is reached for both OSCCAL values ~104 and ~144 in ATmega3290. 9.1 The binary search A binary search is used to find the OSCCAL value that will make the internal RC oscillator produce the desired frequency. The binary search works in the following way: 1. Start with an OSCCAL value in the middle of the search-range. 2. Set step-size to 1/4 of the search range. 3. Decide if the current frequency is too high or too low. 4. If the current frequency is too high, subtract step-size from OSCCAL. If it is too low, add step-size to OSCCAL. If frequency is just right, do not change OSCCAL and abort since no further calibration is needed. 5. Divide step-size by 2. 6. If step-size is 0, the search is complete. Jump to neighbor search (described later). 7. Jump to step 3 This search method is optimal (when it comes to worst-case run time) when searching data with a strictly monotone relationship. As mentioned in section 7, the relationship between OSCCAL and resulting oscillator frequency is not completely monotone. However, it is close enough for the binary search to be the most efficient way to find a value in the neighborhood of the optimal OSCCAL value. From this point it is easy to find the optimal value., 9.2 The neighbor search In this search method, the neighbor values have to be examined. A binary search has to be done prior to using this method. Since an increase in clock frequency is guaranteed when increasing OSCCAL by a value of 2 or more, problems are only expected at the last iteration of the binary search, when the step-size is 1. In this case an increased OSCCAL value might result in a decrease in clock frequency, and vice versa. One more step in the same direction guarantees a frequency change in the desired direction. This step might however just be large enough to counter the effect of the last step. Thus, to make sure that the optimal OSCCAL value is found, one more step should be taken. The Timer/Counter0 value of each of these iterations is then saved, and compared with the desired number of clock cycles. The OSCCAL value that produces the clock frequency closest to the desired frequency is used. This will be referred to as a neighbor search. Since additional code is required to implement the neighbor search, this could be omitted when the need for accuracy is less important than the code size. 9.3 Simple search This method is very easy to implement, and gives reduced code size compared to binary search and binary with neighbor search. It has, however, a higher worst-case run-time. The search works as follows: 1. Start with an OSCCAL value in the middle of the search-range i.e. ½ of the OSCCAL resolution. 2. If the frequency is to high, subtract OSCCAL with one. Add one if frequency is to low. Abort if oscillator frequency has reached desired frequency. 3. Repeat step n times, where n is OSCCAL resolution divided by two. This last method is obviously slower than the first, but occupies less memory space due to its small code size. This method can also be used in fine-tuning, where step 1 is omitted and calibration is run from current OSCCAL. The repeat factor n can in this case be reduced considerably, sometimes just a few steps might be needed. A big drawback is that the simple search does not evaluate the goodness of the calibration, and hence will continue until it has done calibration cycles equal to ½ of the OSCCAL resolution unless perfect calibration is obtained. 9.4 Accuracy The accuracy of the search depends on the search method used: If only the binary search is used, the optimal OSCCAL value is not always found. However, the frequency found should still be within +/-2% of the desired frequency for parts that can be calibrated to +/-1% of target frequency. When the binary search is used alone, the search should abort when a system clock frequency within the required accuracy limits is found. This should be done to avoid problems in the last step due to the pseudo-monotone relation between OSCCAL and internal RC oscillator frequency. When the neighbor search is used in addition to the binary search, the optimal OSCCAL value will always be found if it lies inside the search range. The resulting clock frequency will be within +/-1% of the desired frequency for parts supporting this accuracy. The search is only aborted if a perfect match is found, i.e. the measured number of CPU cycles during a given amount of ticks on the external crystal exactly matches the desired number of CPU clock cycles. When the search is finished 8 AVR055,

AVR055

without finding a perfect match, the calibrated OSCCAL value is the value that best matches the desired frequency. Even if there is an OSCCAL value that produces a clock frequency closer to the desired value, we will not be able to measure the difference. Further search is thus not necessary. Accuracy can also be adjusted by increasing the amount of ticks on the external crystal, improving measurement accuracy. Few ticks will give fast calibration, but lower accuracy. Increasing the number up to a certain limit will increase accuracy. Notice that a higher amount of ticks does not necessarily increase the accuracy, since the resolution on the OSCCAL register is fixed. Improving the measurement accuracy does not improve the OSCCAL accuracy. 10 Implementation This section describes how the run-time calibration can be implemented on an AVR. 10.1 Hardware This application uses a 32.768 kHz watch crystal for oscillator calibration, as it is the optimal choice, both economically, and when it comes to frequency stability. The low- frequency crystal oscillator is designed for use with crystal running at this frequency. It is important to notice that the external watch crystal needs time to stabilize. This applies to situations when the crystal is not already running prior to calibration. 10.2 Software In the following sections, the firmware needed to do run-time calibration is described. The main idea is to run a counter asynchronously on a separate 32KHz watch crystal for a certain number of cycles. Meanwhile a simple CPU loop is done, incrementing a word. Knowing the number of cycles of the inner loop, and assuming the asynchronous timer is correct; the CPU will count to a certain level. Then comparing to a number corresponding to the desired frequency, one can adjust the CPU frequency up/down through OSCCAL. 10.2.1 Defining the search range Some devices have a divided OSCCAL register. As shown in Figure 7-2, the ATmega3290 OSCCAL register has two ranges, one going from values 0 to 127, the other from 128 to 255. When calibrating to a frequency between ~7 MHz and ~10 MHz, there are two possible OSCCAL values that gives an appropriate and satisfying frequency. Before calibration can start, knowledge about the device OSCCAL register size is needed. A macro checks if the OSCCAL register is divided in two or not for the specific device. If the OSCCAL is divided, the search is first done in the lower part of OSCCAL followed by a search in the upper part as long as no perfect match is obtained during the first search. After a second search, the two calibrations are compared, and the optimal value found. For devices with one 8 bit (or 7 bit in some devices) range containing all possible frequencies, only one search range is defined and a double search and comparison is unnecessary., 10.2.2 Initiating calibration Before starting the calibration, OSCCAL should be written according to the value equal to ½ of the search range. For parts with a two-range OSCCAL, calibration starts in the lower OSCCAL, and OSCCAL is written to ½ of the lower search range. This is done to make the binary search work properly. The asynchronous timer must be set up properly in order to use an external watch crystal as clock source. The Asynchronous (AS) bit in the ASSR register must be set to ensure that the timer is asynchronous from the CPU clock with at external crystal driving it. If interrupts are used, these must be disabled prior to using the counter function in order to ensure correct calibration. 10.2.3 Defining the count value When calibrating to a desired frequency, the count value in Equation 8-1 is needed. This equation is implemented as a macro, using the device specific loop cycle value. The number of loop cycles is 6 for devices with the TCNT register located in standard I/O space, and 7 in devices with the TCNT register located in extended I/O, using IAR workbench v4.11a. Now having the count value, and using the counter function to increment the counter, the counter and the desired count value can be compared to proceed with the calibration. Figure 10-1. The counter function Reset Wait for update Counter Set counter = 0 asynchronous on asynchronous counter < No Increment timer timer XTAL ticks counter Return Yes It is important that interrupt is disabled in order to ensure proper operation of the counter function and the asynchronous timer. 10.3 Searching When a fast calibration procedure is needed, a binary search performs better than any other search method. When combining it with neighbor search, greater accuracy is achieved, since the relation between the OSCCAL value and the oscillator frequency is pseudo-monotone. There is no guarantee that the binary search will reach the optimal value when the relationship is not strictly monotone. The neighbor search can be omitted without a considerable loss of accuracy as mentioned in section 9.4, and also improve run-time and reduce code size. The neighbor search will be omitted whenever perfect calibration is reached. 10 AVR055,

AVR055

Figure 10-2. The binary- and neighbor search functions Binary Search Neighbor Search Increment Compare neighbors counter with searched Counter Count Value Counter < > Count Value Count Value Sufficient neighbors searched? Set sign = 1 Set sign = -1 No Yes Perfect match Calibration Increment finished Write bestOSSCAL with OSCCAL sign Inrease OSCCAL Derease OSCCAL with stepsize with stepsize Calibration Divide stepsize by finished two Return Return It can be noticed that when the OSCCAL value of the desired calibration frequency is close to the OSCCAL value of the running frequency, the simple search method may be a better choice. Leaving the OSCCAL register unchanged prior to calibrating, only a few steps might be necessary. This may be interesting in cases such as fine-tuning or re-calibrating as it reduces code size and can outperform binary search when it comes to time consumption. 10.3.1 Calibration The calibration routine will do a binary search until the step size reaches zero, or finish if a prefect match should occur during binary searching. When the step-size has reached zero, neighbor search begins. The optimal OSCCAL is obtained by evaluating the difference between the count value corresponding to the desired frequency, and the value returned by the counter function. The lowest deviation and the corresponding OSCCAL value is saved and the OSCCAL register is written according to the lowest deviation when the search is finished, in order to obtain the optimal value.,

Figure 10-3. The calibrate routine, implementing neighbor and binary search

Calibrate Calibration status Running Binary Search Counter No Stepsize = 0? Yes Finished Not Neighbor started search status Running Compute count Compute count difference difference Count differnce decreased ? Yes Save OSCCAL Save OSCCAL No value and count value and count difference difference Prepare and start Neighbor neighbor search Search Return

In devices where the OSCCAL register contains two ranges, both of the ranges may

hold a value that matches the desired frequency, but the value in one range may give a more accurate calibration than the other. The two calibrations are compared to guarantee that the best possible solution is found. When using devices with one

OSCCAL range, double search is unnecessary.

12 AVR055,

AVR055 Figure 10-4. The main routine

Calibrate using

XTAL

Initiate Calibration Prepare Do a second calibration search Save OSCCAL Initiate Calibration value and count Calibrate difference Compute Count Value from Set search range desired frequency to higher part of

OSCCAL

No Write Default OSCCAL value Splitted Count OSCCAL Yes Difference = 0 register? ? Set Up Timer tobe driven asynchronously Yes, second by XTAL search performed Compare count Return differences No First calibration closer to desired count Write OSCCAL Yes according to first search Return 10.4 Code size

The source code included with this application note results in quite different code

sizes when compiled, depending on calibration method, timer resolution, and type of

OSCCAL register used. Table 10-1 shows some examples of code size for two

devices, ATmega3290 with a divided OSCCAL register, and ATmega32 with a continuous OSCCAL register.

Calibration cycles are also given to illustrate the duration. A calibration cycle means

running the counter with or without a write to OSCCAL, using binary, neighbor or simple search. The code is compiled with IAR workbench V4.11, using full optimization with respect to code size.

Table 10-1.Compiled code size and calibration cycles

Device Calibration method Calibration Cycles Code size Simple search max 128 ~270 B ATmega3290 Binary search max 14 ~370 B Binary with neighbor search max 22 ~380 B Simple search max 128 ~240 B ATmega32 Binary search max 8 ~280 B Binary with neighbor search max 12 ~290 B, 10.5 Performance of the Calibration firmware The code has been written with focus on efficiency: The entire calibration should be performed fairly quickly. The performance therefore depends on the size of the calibration firmware and the time it takes to complete the calibration. The calibration firmware is 240 to 380 bytes, depending on the target device and calibration method used, giving short programming time. The calibration routine is completed in less than 22 (worst-case) calibration cycles for ATmega3290 and 12 for ATmega32, using binary with neighbor search. The duration is dependent on whether perfect calibration is reached during binary search or not. 10.6 Calibration Clock Accuracy The accuracy of the calibration is highly dependent on the accuracy of the external calibration clock. It is therefore important to know the exact frequency of the crystal used and enter it into the interface specific source file. Using a 32.768 kHz watch crystal, optimal accuracy is achieved. 11 Getting started The following steps will get you started calibrating the AVR. The included source code is written for IAR Embedded Workbench V4.11. Modifications are needed to compile the source code with other compilers. The source code is compatible with all current AVR devices with a tunable internal oscillator and a timer with asynchronous operation mode. These devices are also listed in Table 6-1. Download the source code for AVR055 from www.atmel.com and unzip it. 11.1 Calibration source code The IAR workspace “calibrating_32kHz_XTAL.eww” contains all files needed to perform a calibration. All functions and the main routine are all collected in one file, “calib_32kHz.c”. Macros, calibration specific values and flags, and device specific definitions are in separate header files. 11.1.1 Source code files The root file “calib_32kHz.c” refers to the following files: 1. A device specific file, “device_specific.h”. This file will ensure that the root file uses the proper bit and register definitions corresponding to the selected device. If ATmega169 is used, uncomment the “TWO_RANGES” line if using revision F or later, since the latest versions have 2. A calibration interface specific file, “calib_values.h”. This file holds the desired calibration value along with other values relevant to the calibration. Some macros are also defined, as well as flags choosing different calibration methods. 14 AVR055,

AVR055

11.1.2 Performing a calibration Open the file “calibrating_32kHz_XTAL.eww” in IAR Embedded Workbench. This project is set up with the necessary files and settings to get started with calibration. Select device from “Processor configuration” in the “Project/Options” menu of IAR Embedded Workbench. “calib_values.h” contains several flags that must be set before compiling. Complete the following steps to tailor the source code for your needs. 1. If a search method other than binary with neighbor search is desired, uncomment one of the two CALIBRATION_METHOD_XXXXX lines. 2. Change the frequency to desired calibration frequency by modifying the CALIBRATION_FREQUENCY value, which is set to 1MHZ by default. 3. If crystals other than a 32.768 kHz watch crystal is used, change XTAL_FREQUENCY according to the crystal used for calibration. 4. EXTERNAL_TICKS can be modified to decrease/increase accuracy and calibration running time. 100 ticks are recommended to guarantee +/-1% accuracy, but this number can be reduced to speed up the calibration. The maximum value is 255 due to the size of the asynchronous timer register. For most devices 40 ticks is feasible, but a higher value gives increased accuracy.,

Disclaimer Atmel Corporation Atmel Operations

2325 Orchard Parkway Memory RF/Automotive San Jose, CA 95131, USA 2325 Orchard Parkway Theresienstrasse 2 Tel: 1(408) 441-0311 San Jose, CA 95131, USA Postfach 3535 Fax: 1(408) 487-2600 Tel: 1(408) 441-0311 74025 Heilbronn, Germany Fax: 1(408) 436-4314 Tel: (49) 71-31-67-0

Regional Headquarters Microcontrollers Fax: (49) 71-31-67-2340 Europe 2325 Orchard Parkway 1150 East Cheyenne Mtn. Blvd.

Atmel Sarl San Jose, CA 95131, USA Colorado Springs, CO 80906, USA Route des Arsenaux 41 Tel: 1(408) 441-0311 Tel: 1(719) 576-3300 Case Postale 80 Fax: 1(408) 436-4314 Fax: 1(719) 540-1759 CH-1705 Fribourg Switzerland La Chantrerie Biometrics/Imaging/Hi-Rel MPU/ Tel: (41) 26-426-5555 BP 70602 High Speed Converters/RF Datacom Fax: (41) 26-426-5500 44306 Nantes Cedex 3, France Avenue de Rochepleine Tel: (33) 2-40-18-18-18 BP 123

Asia Fax: (33) 2-40-18-19-60 38521 Saint-Egreve Cedex, France

Room 1219 Chinachem Golden Plaza ASIC/ASSP/Smart Cards Tel: (33) 4-76-58-30-00 Fax: (33) 4-76-58-34-80 77 Mody Road Tsimshatsui Zone Industrielle East Kowloon 13106 Rousset Cedex, France Hong Kong Tel: (33) 4-42-53-60-00 Tel: (852) 2721-9778 Fax: (33) 4-42-53-60-01 Fax: (852) 2722-1369 1150 East Cheyenne Mtn. Blvd.

Japan Colorado Springs, CO 80906, USA

9F, Tonetsu Shinkawa Bldg. Tel: 1(719) 576-3300 1-24-8 Shinkawa Fax: 1(719) 540-1759 Chuo-ku, Tokyo 104-0033 Japan Scottish Enterprise Technology Park Tel: (81) 3-3523-3551 Maxwell Building Fax: (81) 3-3523-7581 East Kilbride G75 0QR, Scotland Tel: (44) 1355-803-000 Fax: (44) 1355-242-743

Literature Requests

www.atmel.com/literature Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel’s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. © Atmel Corporation 2005. All rights reserved. Atmel®, logo and combinations thereof, Everywhere You Are®, AVR®, AVR Studio® and others, are the registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others.]
15

Similar documents

8-bit RISC Microcontroller Application Note
8-bit RISC Microcontroller Application Note Rev. 1981A–AVR–03/05 AVR155: Accessing an I2C LCD Display using the AVR® 2-wire Serial Interface Features • Compatible with Philips' I2C protocol • 2-wire Serial Interface Master Driver for Easy Transmit and Receive Function • Initialization and Use ofa2x1
AVR107: Interfacing AVR serial memories
AVR107: Interfacing AVR serial memories Features • Devices: AT25128A/256A, AT25F1024/2048/4096 • Full Serial Memory Functions Support • Memory Array Burst Read • Page Burst Write • Write Protection Detection • On Going Access Detection • Non-blocking Write Access • Access Status Information 1 Introd
AVR120: Characterization and Calibration of the ADC on an AVR
AVR120: Characterization and Calibration of the ADC on an AVR Features • Understanding Analog to Digital Converter (ADC) characteristics • Measuring parameters describing ADC characteristics • Temperature, frequency and supply voltage dependencies • Compensating for offset and gain error Introductio
AVR001 Conditional Assembly and portability macros
AVR001 Conditional Assembly and portability macros Features • Increased portability • Easier Code Writing • Simplified I/O Register Access • Improved Assembly Status Feedback 1 Introduction This application note describes the Conditional Assembly feature present in the AVR Assembler version 1.74 and
8-bit Microcontroller Application Note
8-bit Microcontroller Application Note Rev. 2527A–AVR–9/02 AVR223: Digital Filters with AVR Features • Implementations of Simple Digital Filters • Coefficient and Data Scaling • Fast Implementation of 2nd Order FIR Filter • Compact Implementation Of 8th Order FIR Filter • Fast Implementation of 2nd
8-bit Microcontroller Application Note AVR040: EMC Design Considerations Scope
8-bit Microcontroller Application Note Rev. 1619C–AVR–01/04 AVR040: EMC Design Considerations Scope This application note covers the most common EMC problems designers encounter when using microcontrollers. It will briefly discuss the various phenomena. The refer- ence literature covers EMC design i
8-bit RISC Microcontroller Application Note
8-bit RISC Microcontroller Application Note Rev. 2508B–AVR–01/04 AVR182: Zero Cross Detector Features • Interrupt Driven • Modular C Source Code • Size Efficient Code • Accurate and Fast Detection • A Minimum of External Components Introduction One of the many issues with developing modern applicati
AVR242: 8-bit Microcontroller Multiplexing LED Drive anda4x4Keypad Multiplexing Features reduced to fifteen with a bit of ingenuity,
AVR242: 8-bit Microcontroller Multiplexing LED Drive anda4x4Keypad Multiplexing Features reduced to fifteen with a bit of ingenuity, allowing the smaller 20-pin AVR to be LED Drive and a • 16 Key Pushbutton Pad in4x4Matrix • 4 Digit Multiplexed LED Display with used. The circuit diagram is shown in
8-bit Microcontroller Application Note AVR180: External Brown-out Protection
8-bit Microcontroller Application Note Rev. 1051B–AVR–05/02 AVR180: External Brown-out Protection Features • Low-voltage Detector • Prevent Register and EEPROM Corruption • Two Discrete Solutions • Integrated IC Solution • Extreme Low-cost Solution • Extreme Low-power Solution • Formulas for Compone
8-bit Microcontroller Application Note
8-bit Microcontroller Application Note Rev. 1259D–AVR–04/05 AVR134: Real Time Clock (RTC) using the Asynchronous Timer Features • Real Time Clock with Very Low Power Consumption (4 µA @ 3.3V) • Very Low Cost Solution • Adjustable Prescaler to Adjust Precision • Counts Time, Date, Month, and Year wit
  Wiring Diagram
Wiring Diagram Samsung Electronics 6-1
8-bit Microcntroller Application Note
8-bit Microcntroller Application Note Rev. 2532A–AVR–01/03 AVR243: Matrix Keyboard Decoder Features • 64-key Push-button Keyboard in8x8Matrix • No External Components Required • Wakes Up from Sleep Mode on Keypress • Easily Implemented into Other Applications • Low Power Consumption • Software Conta
  Alignment and Adjustments
Alignment and Adjustments 1. Tuner FM THD Adjustment FMOutput Antenna GND SETSSG FREQ. 98 MHz Terminal Oscilloscope Adjustment FM S.S.G Input point FM DETECTOR COIL Speaker (FM DET) Terminal output Input Output 60 dB Distortion Meter Minumum Distortion (0.4% below) (Figure 1-1) Figure1-1 IF CENTER
8-bit Microcontroller Application Note
8-bit Microcontroller Application Note Rev. 2540A–AVR–07/03 AVR104: Buffered Interrupt Controlled EEPROM Writes Features • Flexible Multi-byte EEPROM Buffer • Power Efficient EEPROM Access • Access Control on Buffers • EEPROM Buffer Rewrite Introduction Many applications use the built-in EEPROM of t
  Schematic Diagram - This Document can not be used without Samsung’s authorization -
Schematic Diagram - This Document can not be used without Samsung’s authorization - 7-1 MAIN 7-1 Samsung Electronics 7-2 FRONT - This Document can not be used without Samsung’s authorization - Samsung Electronics 7-2 7-3 DSP - This Document can not be used without Samsung’s authorization - 7-3 Sam
  TroubleShooting
TroubleShooting 9-1 Main 9-1 Samsung Electronics Samsung Electronics 9-2 9-3 Samsung Electronics Samsung Electronics 9-4 9-2 DVD Servo parts 9-5 Samsung Electronics Samsung Electronics 9-6 9-7 Samsung Electronics Samsung Electronics 9-8 9-9 Samsung Electronics Samsung Electronics 9-10 9-11 Samsung
AVR054: Run-time calibration of the internal RC oscillator
AVR054: Run-time calibration of the internal RC oscillator Features • Calibration of internal RC oscillator via UART • LIN 2.0 compatible synchronization/calibration to within +/-2% of target frequency • Alternate run-time synchronization/calibration to within +/-1% of target frequency • Support for
SERVICE Manual
DVD RECEIVER AMP HT-DB120 SERVICE Manual DVD RECEIVER AMP SYSTEM CONTENTS 1. Alignment and Adjustments 2. Exploded Views and Parts List 3. Electrical Parts List 4. Block Diagrams 5. PCB Diagrams 6. Wiring Diagram 7. Schematic Diagrams 8. IC block Diagrams 9.Troubleshooting - Confidential - ELECTRONI
8-bit Microcontroller Application Note AVR131: Using the AVR’s High-speed PWM
8-bit Microcontroller Application Note Rev. 2542A–AVR–09/03 AVR131: Using the AVR’s High-speed PWM Features • Analog Waveform Generation using PWM • High-speed Prescalable PWM Clock Introduction This application note is an introduction to the use of the high-speed Pulse Width Mod- ulator (PWM) avail
8-bit RISC Microcontroller Application Note AVR042: AVR® Hardware Design Considerations
8-bit RISC Microcontroller Application Note Rev. 2521B–AVR–01/04 AVR042: AVR® Hardware Design Considerations Features • Providing Robust Supply Voltage, Digital and Analog • Connecting the RESET Line • SPI Interface for In-System Programming • Using External Crystal or Ceramic Resonator Oscillators
8-bit Microcontroller Application Note AVR240: 4x4Keypad – Wake-up on Keypress Features Introduction
8-bit Microcontroller Application Note AVR240: 4x4Keypad – Wake-up on Keypress Features • 16 Key Pushbutton Pad in4x4Matrix • Very Low Power Consumption • AVR in Sleep Mode and Wakes Up on Keypress • Minimum External Components • ESD Protection Included if Necessary • Efficient Code • Complete Progr
Microcontrollers for Fluorescent and High Intensity Discharge Lamp Ballasts SMARTER, MORE FLEXIBLE LIGHTING SOLUTIONS
LIGHTINGMICROCONTROLLERSMicrocontrollers for Fluorescent and High Intensity Discharge Lamp Ballasts SMARTER, MORE FLEXIBLE LIGHTING SOLUTIONS Developed together with the industry leading lamp ballast manufac- turers, Atmel® microcontrollers are optimized for Linear and Dimmable Fluorescent tubes, as
AVR121: Enhancing ADC resolution by oversampling
AVR121: Enhancing ADC resolution by oversampling Features • Increasing the resolution by oversampling • Averaging and decimation • Noise reduction by averaging samples 1 Introduction Atmel’s AVR controller offers an Analog to Digital Converter with 10-bit resolution. In most cases 10-bit resolution
  IC Block Diagrams 8-1 Main
IC Block Diagrams 8-1 Main 8-1-1. FAN8082D 8-1 Samsung Electronics 8-1-2. LC87F66C8A Samsung Electronics 8-2 8-3 Samsung Electronics Samsung Electronics 8-4 8-5 Samsung Electronics 8-1-3. M62446AFP Samsung Electronics 8-6 8-7 Samsung Electronics 8-1-4. M66010FP 8-1-5. SI-8050SE 8-1-6. SI-8090JFE S
AVR053: Calibration of the internal RC oscillator Features Introduction
AVR053: Calibration of the internal RC oscillator Features • Calibration using STK500, AVRISP, JTAGICE or JTAGICE mkII • Calibration using 3rd party programmers • Adjustable RC frequency with +/-1% accuracy • Tune RC oscillator at any operating voltage and temperature • Tune RC oscillator to any fre
8-bit Microcontroller Application Note AVR230: DES Bootloader Features
8-bit Microcontroller Application Note Rev. 2541D–AVR–04/05 AVR230: DES Bootloader Features • Fits All AVR Microcontrollers with Bootloader Capabilities • Enables Secure Transfer of Compiled Software or Sensitive Data to Any AVR with Bootloader Capabilities • Includes Easy To Use, Configurable Examp
AVR106: C functions for reading and writing to Flash memory
AVR106: C functions for reading and writing to Flash memory Features • C functions for accessing Flash memory - Byte read - Page read - Byte write - Page write • Optional recovery on power failure • Functions can be used with any device having Self programming Program memory • Example project for us
8-bit Microcontroller Application Note AVR201: Using the AVR® Hardware Multiplier
8-bit Microcontroller Application Note Rev. 1631C–AVR–06/02 AVR201: Using the AVR® Hardware Multiplier Features • 8- and 16-bit Implementations • Signed and Unsigned Routines • Fractional Signed and Unsigned Multiply • Executable Example Programs Introduction The megaAVR is a series of new devices i
  Printed Circuit Board Diagram
Printed Circuit Board Diagram 5-1 MAIN 5-1 Samsung Electronics 5-2 FRONT Samsung Electronics 5-2 5-3 DSP 5-3 Samsung Electronics 5-4 JACK * RCA JACK * SCART JACK Samsung Electronics 5-4 5-5 DVD PACK * TOP VIEW * BOTTOM VIEW 5-5 Samsung Electronics
8-bit Microcontroller Application Note AVR105: Power Efficient High Endurance Parameter Storage in Flash Memory
8-bit Microcontroller Application Note Rev. 2546A–AVR–09/03 AVR105: Power Efficient High Endurance Parameter Storage in Flash Memory Features • Fast Storage of Parameters • High Endurance Flash Storage – 350K Write Cycles • Power Efficient Parameter Storage • Arbitrary Size of Parameters • Semi-redu