You know the basics about how the chip is clocked. Every microcontroller chip uses a clock, which keeps track of time for the chip, in general one assembly code instruction is run every clock cycle.
The Clock Source can be either of the following:
‘Internal Clock‘ means the little oscillator inside the chip. This clock is good for most basic projects, but its not very precise. Having an internal oscillator means we don’t need to wire up an external crystal and hence we can use the clock pins for other tasks. Literally, ‘ External Clock‘ means that a square wave is being input into the ‘CLOCK-IN’ pin, but this option is rarely used. If we need a special clock rate (for example 12MHz) we can use an external crystal or oscillator.
Crystals come in different pacakges, with the speed printed on the body, usually in MHz. Ceramic resonator is an alternative to the common crystal. Crystal is a 2-pin component, but ceramic resonator have 3 pins.
In practice, it is required to add two ceramic capacitors (usually 22pF value) with the crystal as shown in the next figure. However, this is not required incase of a ceramic resonator because it is a combination of the crystal and capacitors, built into one compact package. Note that the internal ATMega8 clock can be set up to a maximum frequency of 8 MHz, and beyond that you need an external clock source. How can we set a clock speed? As said, we have two options; use the internal one, or use an external source. If we are writing code for a basic job, the internal clock should suffice. On the other hand, when precision timing is crucial, we need an alternate method like using suitable crystals, or ceramic resonators.
Fuses are important when it comes to uC programming, that is why fuses are well-documented in manufactures’ datasheets. The fuses determine how the chip will act, whether it has a bootloader, what speed and voltage it likes to run at, etc.
You only need to set them once, but if you don’t do this right, get ready to expect a costly disaster!
Typically, there are only two fuse bytes: a high one, and a low one. As you may well know, one byte contains 8 bits. So we have just 16 bits to set to on or off. Each of those bits, depending on whether they are on or off, impacts the critical operations of the microcontroller. For all fuses, ‘1’ means unprogrammed, and ‘0’ means programmed. As found in the datasheet, ATMega8 has the following clock source options, selectable by Flash Fuse Bits as shown in the table below.
The clock from the selected source is input to the AVR clock generator, and routed to the appropriate
In this part, we just learned that we have to set some fuse bits to indicate we are using an external crystal. Frankly speaking, learning more about fuse bits at this early stage is somewhat difficult for many beginners. So just consider this as a foundation (will treat this in near-future), and allow me to shift to next phase of this tutorial.
Fuse Bits – Short Reference
(1) These are fast startup times – not suitable for crystals
(2) Intended to use with ceramic resonators to ensure stable startup