1

I want to overclock my Game Boy Advance SP. It has a built-in 4 MHz crystal, and I was able to temporarily replace it with an 8 MHz crystal to see if I was able to overclock it, which I was :).

However I'm wondering if it's possible to emulate/simulate a crystal using an Arduino? Like instead of a crystal soldered to the Game Boy, two output pins from the Arduino? If not, is there a such thing as a variable oscillator? Like a crystal with a potentiometer to change the frequency when the potentiometer is adjusted?

3
2

You want to use the Uno? You can set up a timer to output varying frequencies and output them on a pin. I have a page about timers which might help. The fastest you can get with a 16 MHz processor is 8 MHz output however you can get other frequencies by changing the timer parameters.

The ATtiny85 can output higher frequencies if you use the PLL clock option, I think you can then adjust the resulting frequency.

If not, is there a such thing as a variable oscillator?

Adafruit make a Clock Generator Breakout Board - 8KHz to 160MHz. You connect that via I2C to your Arduino and then program assorted frequencies as a clock output. That uses the Si5351A clock generator chip.


Example code to output 8 MHz on a Uno or Mega2560:

#ifdef __AVR_ATmega2560__
  const byte CLOCKOUT = 11;  // Mega 2560
#else
  const byte CLOCKOUT = 9;   // Uno, Duemilanove, etc.
#endif

void setup ()
  {
  // set up 8 MHz timer on CLOCKOUT (OC1A)
  pinMode (CLOCKOUT, OUTPUT); 
  // set up Timer 1
  TCCR1A = bit (COM1A0);  // toggle OC1A on Compare Match
  TCCR1B = bit (WGM12) | bit (CS10);   // CTC, no prescaling
  OCR1A =  0;       // output every cycle
  }  // end of setup

void loop ()
  {
  // whatever 
  }  // end of loop

To output 4 MHz change OCR1A to 1 rather than 0.

6
  • Thanks for the reply! So I understand my UNO can output 8mhz. Now this might sound like a stupid question, but since it outputs on only 1 pin, how would I connect it to a device that would normally use a 2-Pin crystal oscillator? Would I connect that one pin to both sockets of where the crystal would be, or would I connect the one output pin to one side and GND to another?
    – Leo Takacs
    Oct 30 '16 at 22:47
  • Ok, so I found this code which outputs 8MHz on an Arduino Micro (which I own). I'm trying to figure out how to output 4MHz instead, while keeping the code similar. pastebin.com/JFP7pUiF
    – Leo Takacs
    Oct 31 '16 at 2:09
  • Would I connect that one pin to both sockets of where the crystal would be, or would I connect the one output pin to one side and GND to another? Yes, but the Gameboy might not be designed for that. A circuit that expects a crystal should probably be given a crystal. You could get different value crystals from eBay for a couple of dollars.
    – Nick Gammon
    Oct 31 '16 at 4:04
  • Hmm. that's what I was thinking but then I saw this: youtu.be/nwJQxD8LLNY. He said he used a frequency generator, which to my knowledge, outputs a set frequency, so I thought he result would be the same with an Arduino. Can you show me how I'd go about changing this code (pastebin.com/JFP7pUiF) to output 4MHz, and show me how you did it? I checked out your page, and I'm normally pretty good with Arduinos, but I am COMPLETELY lost with this timer thing.
    – Leo Takacs
    Oct 31 '16 at 4:40
  • Since you tagged your question with "Uno" I've amended my answer to show how to do it on a Uno. The register OCR1A is what you count up to. If it contains 0 then it toggles the pin every clock cycle. If you count to 1 it toggles the pin every other clock cycle.
    – Nick Gammon
    Oct 31 '16 at 5:03
2

A crystal oscillator connection to a microcontroller typically consists of two pins - an output "driving" pin, and an input "amplifying" pin. The crystal sits between the two pins (basically between the input and the output of the amplifier) and the amplifier oscillates at the frequency of the crystal.

In general you can bypass the crystal itself and just provide a clock signal on the input pin (often labelled OSC1 or OSCI) and ignore the output pin since it isn't needed to drive a crystal.

Some microcontrollers provide a special "EC" mode (External Clock) which disables the amplifier and just expects a clock signal.

1
  • Thanks so much for the clarification! This clears it up alot!
    – Leo Takacs
    Oct 30 '16 at 23:34
0

Using the Arduino platform as a signal generator (oscillator) results in too high a granularity factor. Software that has been suggested can only change between 8 and 4 MHz but not output anything between those two frequencies.

It would be better to use some sort of DDS or Frequency Synthesizer circuit that can be adjusted incrementally with a granularity of 1 Hz or better.
My suggestion would be to use the Arduino to control a modern synthesis IC like the S15351a. This combination can output any frequency from 3KHz to 160 MHz in 1 Hz steps. The device is inexpensive and has 3 outputs which can be adjusted independently. Google "Si5351a Arduino" to find some circuit suggestions. https://www.qrp-labs.com/progrock.html

1
  • On many Arduinos, including Arduino Uno, the main microcontroller uses a poor ceramic oscillator with a 0.5% tolerance (the crystal is only used for the USB side) Jan 21 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.