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?:
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 oscillatorA 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 elsewhereIf 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. |
|||||||||
|
While in principle I don't see a problem you're limited to a range of 100KHz to 12MHz when using an external RC oscillator. You'd need to use an additional resistor to make sure those constraints are met so you don't get erratic operation and possible damage to the AVR. The long wires and the pot itself will probably also radiate quite a bit of RF interference. The usual way would be to use the pot as a voltage divider and read the value using an analog input. Then use that value to vary the frequency of your timing loop while the CPU keeps running at the same clock frequency. |
|||
|
It's not clear, but it seems from your question that you want to have a variable frequency waveform that responds to a Pot value for adjustment. Just staying in the AVR mode (there are many different ways to do this) you could also do this without changing the operating frequency of the device. You would just need to read the POT value with the ADC input and use that value to adjust the PWM output accordingly. |
|||
|