Learning XMega clock sources

Any microcontroller needs some clocking mechanism. This is how it performs instructions, count time, generate signals. Normally controller comes with many clocking options as there may be different needs of clocking speed and accuracy. Sometimes you may want to squeeze maximum performance out of it, then you would probably select the highest clock speed. In this case you would loose energy efficiency over performance. Sometimes you only need to send simple control commands and keep time. Then you would choose 32.768kHz clock source which helps to preserve energy and do the job. This is why microcontrollers have so many clocking options available. Shawon wrote pretty good guide about selecting and setting Xmega microcontroller clock source. He explains internal clock sources by listing their benefits and limitations. Then he takes to external sources and usage of PLL (Phase Locked Loop) to multiply crystal clock up to limits. Then he does several experiments to check few clock settings if they are correct by measuring waveforms with scope. Be sure to understand how clocking mechanism work in any micro before you dive any… Continue reading

AVR timers do more than count time

Timer/Counters are probably one of the most complex peripherals in microcontrollers, but they are most common and no matter what complexity the program is. Designers of timers have put a lot of thought into them, making them very flexible, versatile for all timing-dependent tasks like measuring periods, generating PWM signals, generating output signals, and timed interrupts. Timers run independently from the AVR core. Once set, they do their silent job while AVR can do other tasks or go to sleep. AVR can read timer values or change operation modes whenever it needs or only can be interrupted with several available interrupts. If you see an application where the frequency is measured, music is generated, or motor is driven, a timer is involved. Continue reading