Clock & Timer Circuit DiagramsOscillators Circuit Diagrams

MHz Oscillator using an ATtiny15 Schematic Circuit Diagram

Microcontroller-Based Clock Solution for Circuit Stability

Many engineers have encountered the challenge: a circuit requires a stable 1 or 2 MHz clock generator (as in the author’s case, for a Pong game utilizing an old AY3-8500 chip). In the absence of an appropriate crystal, an RC oscillator is hastily assembled (numerous circuits are available for such designs). However, the problem arises when the exact capacitor is unavailable, leading to the addition of a preset pot for some flexibility. Unexpectedly, the clock circuit ends up occupying more board space than anticipated. For applications where an exact clock source isn’t crucial, a miniature 8-pin microcontroller can provide a more efficient solution. Utilizing an old and cost-effective ATtiny15, this approach eliminates the need for external components. Furthermore, adjusting the clock frequency no longer requires altering external elements and is unaffected by component tolerances.

MHz Oscillator using an ATtiny15 Schematic Circuit Diagram

Utilizing Microcontroller’s Internal RC Oscillator for Clock Generation

The internal RC oscillator of the microcontroller is inherently calibrated to a precise 1.6 MHz. Additionally, leveraging its built-in PLL, internal Timer 1 can achieve frequencies up to 25.6 MHz. By configuring internal dividers, the timer can output frequencies ranging from approximately 50 kHz to 12 MHz through an output pin. However, as frequencies increase, the disparity between calculated and actual output frequency grows. For practical applications, an upper limit of around 2 MHz proves meaningful, with a deviation of approximately 15% even at this frequency. The circuit diagram is exceptionally straightforward; apart from power supply connections, the sole essential connection is the output signal on pin 6 (PB1).

Efficient Program for Clock Control

The example program, written in Assembler, consists of a mere 15 lines! Although the brevity of the program almost renders comments unnecessary, they are included for clarity. The code can be downloaded from the Elektor website [1]. Initialization of the timer is the only task required, after which it operates independently of processor control, generating the clock signal. The processor can then be placed in sleep mode to conserve power. Consuming only 1% of the program memory, the remaining 99% is available for other tasks if needed. The OSCCAL register contains a calibration byte enabling fine-tuning of the CPU clock, allowing some adjustment of the output frequency. According to Atmel’s data sheet recommendation, the CPU clock frequency should not exceed 1.75 MHz to ensure proper timer operation.

Substituting ATtiny15 with ATtiny45 for Enhanced Functionality

For those seeking enhanced capabilities, the more recent ATtiny45 can be used as a substitute for the ATtiny15. In this scenario, configuring the CKSEL fuses to align the chip’s Timer 1 with an ATtiny15-compatible mode [3] is necessary. After adapting the program accordingly, higher or more precise frequencies can be achieved from the timer, as the ATtiny45’s PLL can operate up to 64 MHz.


[2] documents/doc1187.pdf

[3] documents/doc2586.pdf


Related Articles

Leave a Reply

Your email address will not be published.

Back to top button