Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Clock and Fuses

Prof. Prabhat Ranjan Dhirubhai Ambani Institute of Information and Communication Technology, Gandhinagar

Reference

WHY YOU NEED A CLOCK SOURCE - COLIN OFLYNN avrfreaks.net http://en.wikibooks.org/wiki/Atmel_AVR

Need for Clock

Clock is like heartbeat for uC defining when a processor will do an instruction Normal instructions for the chip take between one to three clock cycles to complete; a clock cycle is the low-hi-low transition of the clock So the faster the clock runs, the faster the chip works However clock is not the only thing that determines the processing capability Anyway the point is that it needs something that tells the processor when it will be doing instructions (the clock)

Selecting a Clock Source


External Clock Crystal Two pin ceramic resonator Three pin ceramic resonator Internal Oscillator

External Clock

This one is fairly easy - all you do is to have some circuit that creates TTL compatible logic pulses, and feed those pulses into pin XTAL1 External clock could be a cesium-based atomic clock or any other source The external clock should be very clean and fall and rise times should be fast Useful for synchronizing the uC

Crystal

The crystal is a very accurate and (in theory) simple way to get a clock Crystals do not change their value (much) with a changing external temperature Crystals are available in many frequencies and sizes, and needs two external 'load capacitors' to work

Two Pin Ceramic Resonator

A ceramic resonator is similar to a crystal, except that it is much cheaper However as a consequence it is also not as accurate and the value can change at different temperatures An advantage is that they are less fragile than a crystal - so in high-vibration environments they can perform (fairly) well

Two Pin Ceramic Resonator ...

The ceramic resonator may not be accurate enough for reliable serial data transfer (using the UART), but sometimes it is (depends on quality) For reliable data transfer, a crystal is a better choice The two pin ceramic resonator needs two external 'loading capacitors'

Three Pin Ceramic Resonator

The three pin ceramic resonator is similar to the two pin - except that it doesn't need the external loading capacitors as they are built in One pin of the resonator goes to ground, one to XTAL1 and one to XTAL2 (it doesn't matter which pin goes to XTAL1 or XTAL2, but the pin to ground matters!)

Internal Oscillator

A few of the chips are given an internal RC oscillator The new 'Mega' series almost all have an internal oscillator This oscillator can vary from different chips, but one of the faults of them is that the frequency will change with changing voltage on VCC pin and temperature However one can often calibrate them for relative accuracy (still not near a crystal and not quite as good as a resonator) To use them one has to enable the proper fuse

Important note!

Many chips have this selected by default, so even if one connects a 16 MHz crystal to AtMega12816AC it may only be running at 1 MHz! Make sure to select the proper fuse bits if you are using a Mega series chip (as opposed to the AT90S series)

Selection

Selection depends on application:


If we need high accuracy, then external clock or crystal is the way to go If we need low cost, then internal oscillator or ceramic resonator is the way to go If we want the easiest solution, then internal oscillator or three pin ceramic resonator is the best choice

Choice of crystal frequency on Baud Rate

http://www.wormfood.net/avrbaudcalc.php - AVR baud rate calculator

Clock Source Options - ATMega32

Clock Distribution in ATMega32

CPU Clock clkCPU

The CPU clock is routed to parts of the system concerned with operation of the AVR core Examples of such modules are the General Purpose Register File, the Status Register and the data memory holding the Stack Pointer Halting the CPU clock inhibits the core from performing general operations and calculations

I/O Clock - clkI/O

I/O clock-used by majority of the I/O modules, like Timer/Counters, SPI, and USART Also used by the External Interrupt module, but note that some external interrupts are detected by asynchronous logic, allowing such interrupts to be detected even if the I/O clock is halted Address recognition in the TWI module is carried out asynchronously when clkI/O is halted, enabling TWI address reception in all sleep modes.

Flash Clock

The Flash clock controls operation of the Flash interface The Flash clock is usually active simultaneously with the CPU clock

Asynchronous Timer Clock

The Asynchronous Timer clock allows the Asynchronous Timer/Counter to be clocked directly from an external 32 kHz clock crystal The dedicated clock domain allows using this Timer/Counter as a real-time counter even when the device is in sleep mode

ADC Clock

The ADC is provided with a dedicated clock domain This allows halting the CPU and I/O clocks in order to reduce noise generated by digital circuitry This gives more accurate ADC conversion results

Power Management and Sleep Modes

Sleep modes enable the application to shut down unused modules in the MCU, thereby saving power The AVR provides various sleep modes allowing the user to tailor the power consumption to the applications requirements

MCU Control Register MCUCR


SE Sleep Enable SM2..0 Sleep Mode

Sleep Mode Select : ATMega32

Minimizing Power Consumption

There are several issues to consider when trying to minimize the power consumption in an AVR controlled system In general, sleep modes should be used as much as possible, and the sleep mode should be selected so that as few as possible of the devices functions are operating All functions not needed should be disabled In particular, the following modules may need special consideration when trying to achieve the lowest possible power consumption

If enabled, the ADC will be enabled in all sleep modes. To save power, the ADC should be disabled before entering any sleep mode When entering Idle mode, the Analog Comparator should be disabled if not used When entering ADC Noise Reduction mode, the Analog Comparator should be disabled In the other sleep modes, the Analog Comparator is automatically disabled

If the Brown-out Detector is not needed in the application, this module should be turned off Similarly most of the other blocks should be turned off or put to minimum power mode to achieve minimum power consumption

PicoPower AVR

ultra-low power AVR microcontrollers, the ATmega169P and the ATmega165P Drawing as little as 650nA in clock sleep mode and 100nA in standby, these devices enable applications like ZigBee and keyless entry to perform for years on the same battery The new ultra low power technology for Atmel microcontrollers, dubbed "picoPower", draws only 650nA low power run current with only the 32 KHz real time clock running

Conform to ZigBee specifications for low power operation Up to 16 MIPS performance 16 KBytes of Flash memory 512 Bytes EEPROM 1 KBytes SRAM 10-bit ADC, USART, SPI 1.8 to 5.5 volt operating voltage 340 uA in active run mode 150 uA in idle mode at 1 MHz 650 nA in power-save mode with real time clock running 100 nA in power-down mode Brown-out detector 4x25 segment LCD controller (ATmega169P only) 64-pin TQFP and 64-pin QFN packages

FUSE Settings

A Fuse is a magical EEPROM bit that changes low level features and pin assignments Fuses are not mapped anywhere in memory, they can only be adjusted by a chip programmer Some pins have alternate functions that must be decided upon before a program can run and set control registers, those read their setting from a fuse

FUSE Settings

Some famous fuses

JTAG debugging or IO Port RESET or IO Pin Anything with the oscillator/crystal Brown Out Detect (BOD) enable and BOD voltage trigger points

AVRDUDE : Fuse Bit Reading

avrdude -p m32 -U hfuse:r:high.dat:b -U lfuse:r:low.dat:b cat high.dat low.dat


0b11011001 0b11100001

AVRDUDE : Fuse programming


avrdude -p m128 -U flash:w:diag.hex \ > -U eeprom:w:eeprom.hex \ > -U efuse:w:0xff:m \ > -U hfuse:w:0x89:m \ > -U lfuse:w:0x2e:m

You might also like