So I found this thread where matt_s provided a code to output 8MHz from an Arduino Micro. I want to hook up my Arduino Micro to my GBA's oscillator slot so I can control it's clock speed from the Arduino, with a few buttons. I want to be able to output 1MHz, 2MHz, 4MHz, and 8MHzl. Here is the code that output's 8MHz.
All I need is help modifying it to out put 1/2/4 MHz. Thank you!
I think, you need just to set the value of ocr1aval. Try 0, 1, 2, 4. It is compare register for timer. Higher value = slower frequency. I'm also recommending to read the ATmega datasheet, Timer/Counter1 chapter.
Budvar10:
I think, you need just to set the value of ocr1aval. Try 0, 1, 2, 4. It is compare register for timer. Higher value = slower frequency. I'm also recommending to read the ATmega datasheet, Timer/Counter1 chapter.
Setting the clock source to 0 will stop the timer.
Disabling the interrupt will stop the generation of the output signal, even if the timer is running.
In both cases, you can set the output manually using digitalWrite.
Have a look how it's all done in the tone library. Keywords to search for are void tone, void notone, prescalarbits and void disableTimer.
The tone library does not support the high frequencies due to the 'unsigned int' that is used for the frequency parameter; if you change the type of the parameter to uint32_t (or 'unsigned long'), you can use the tone library.
I don't have a means to test it (no measurement equipment).