Electronic – Variable Frequency on AVR Chip

avr

I am looking at programming an AVR chip as a possible avenue due to some problems I'm having with 555 circuitry, but I need to be able to adjust the frequency on the fly with a pot. Is it possible to setup an AVR chip with variable frequency so that the program execution speed can be adjusted right on the board with a simple pot and without having to go back and reprogram the chip?:

Best Answer

As others have already stated, nearly every AVR developer picks some fixed frequency for each application, and runs the AVR chip at that one fixed frequency. Just this week I wrote some code that runs on an AVR that runs at fixed 16 MHz (which is pretty common), but it generates two variable-frequency outputs independently controlled by two pots. (The pots are actually connected to another microcontroller, which reads the pots, and sends their position up a 400 ft RS485 serial cable to the AVR UART).

However, there are a few AVR developers who vary the frequency of their AVR chip at run time, such as Spritesmods (a) (b); cloudscapes (a); K0LR (a); etc.

Using an external RC oscillator

A few AVRs support an "external RC oscillator" option, which is extremely similar to a 555 RC oscillator -- you hook a resistor (such as a pot) and a capacitor directly to the AVR. Just like the 555 RC oscillator, when you turn the pot, it changes the resistance R of the pot, which changes the frequency. "Application Note AVR051: Setup and use the external rc oscillator" (a), (b)

Alas, many popular AVR chips do not support an "external RC oscillator" option. Even those that do, the frequency is limited to the range 100 kHz - 12 MHz. (The ADC doesn't work right at low frequencies, and the UART is going to be difficult to use if the frequency keeps changing).

driving the AVR at some frequency generated elsewhere

If you have some clock source that already generates the frequency you want, you can connect its output to the AVR and program the AVR to use "External Clock" option. This approach works with any AVR and any frequency from zero Hz (0 Hz) to 8 MHz. (i.e., you can go much slower than the "external RC oscillator" approach). (The ADC doesn't work right at low frequencies, and the UART is going to be difficult to use if the frequency keeps changing).

You program the AVR fuse bits to use "External Clock" option if some external source (that oscillates by itself) is driving a squared-off signal into the AVR clock input pin. (Even if technically that external clock is an RC oscillator). This external oscillator could, for example, be a 74HC132 Schmitt NAND and a capacitor and a pot, or a 555 oscillator with a capacitor and a pot, or a huge variety of other oscillators.