Crowdfunding now!
View Purchasing OptionsWe’ve gotten a lot of questions asking about how accurate Game Bub’s clock speed is when emulating the Game Boy and Game Boy Advance. We’re happy to report that it’s very accurate: within 0.008%! Let’s take a look.
For a bit of background, every computer system has one or more clocks that determine how fast it performs operations. The Game Boy and Game Boy Advance have a single clock: the Game Boy runs at approximately 4.19 MHz, while the Game Boy Color adds a “double speed” mode that runs at 8.3887 MHz. The Game Boy Advance further doubles that to run at 16.7772 MHz.
When emulating one of these systems, faster isn’t necessarily better: it’s more important to match the clock frequency. If you try to run a Game Boy Advance at, say 17 MHz, you’ll be running everything ~1.3% faster. That might not sound like much, but you’ll hear the difference because all of the audio will be pitched up. The difference in timing also affects running speed.
Some of the other FPGA devices on the market have suffered from this problem to varying degrees. Even the official Super Game Boy accessory for the SNES suffered from this problem: it ran 2.4% faster than other Game Boy hardware due to clock inaccuracy.
So, let’s take a look at how the Game Bub’s emulated GBA clock speed compares to a real GBA. We connected both the Game Boy Advance and the Game Bub to a logic analyzer via their link port. By generating pulses at a constant rate (from the GBA’s perspective), we can measure how fast each device is running. Using a special link cable breakout board that plugs into the center of the GBA link cable, we can easily test both devices at the same time.
Both devices set their output high during the VBLANK period and low otherwise. This happens once per frame. The logic analyzer measures this 500 million times per second, so we can measure the frame rate very precisely and calculate the clock speed from that.
The result is a waveform that looks like this:
Measuring the average over 100 seconds, we find:
From this, we can calculate that the Game Bub is (59.7344 - 59.7293) / (59.7293) = 0.008% faster (80 PPM), an imperceptible difference. For comparison, if you played both the Game Bub and GBA for exactly one hour, the Game Bub would have run for 18 more frames than the GBA, or 0.3 seconds.
Now that we have the empirical data, let’s see how this matches up with theory.
The Game Boy Advance is designed to run at exactly (16 * 1024 * 1024) Hz, or 16.777216 MHz. Each frame takes exactly 280,896 clock cycles, based on how the video output is designed. Dividing the two, we get a theoretical frame rate of 59.7275 Hz. That’s very close to what we measured, about 0.003% faster (30 PPM).
Why doesn’t this match exactly? Well, the crystal oscillators that computers use to keep accurate timing are only accurate within a certain range: typical values for modern oscillators might be ±20 ppm or ±50 ppm. The Game Boy Advance came out in 2001, when ±100 ppm crystals were more common, but we don’t know exactly what they used. This means that even two otherwise identical GBA devices could have a clock speed difference of up to 0.02%! This inaccuracy is further affected by aging (crystals get worse over time), temperature, and voltage.
Now, let’s look at Game Bub. Game Bub uses a 50.000 MHz (±20 ppm) CMOS oscillator. To generate the required 16.777 MHz clock, the FPGA feeds the clock signal through a piece of circuitry called a phase-locked loop. When emulating the GBA, Game Bub is configured to take the input clock, multiply it by 56.375, divide it by 3, and then divide it by 56. This comes out to 16.7783 MHz, although the clock multiplication and division adds a small amount of additional inaccuracy. If we divide by 280,896 (clock cycles per frame), we get a theoretical frame rate of 59.7313, which is very close to what we measured.
We can do all of this precise clock division and multiplication because the Game Bub’s FPGA, the Xilinx XC7A100T, is equipped with advanced clocking resources.
Sort of! Since Game Bub runs a little bit fast compared to the GBA, we could pull a trick where we occasionally skip a clock cycle. With some math, we can build a fractional divider circuit, where we keep a counter, and every time it overflows, we skip a clock cycle. The downside of this is increased jitter (the variation between the time of individual clock cycles is higher), but that shouldn’t be perceptible.
One advantage of this is that you can actually tune the effective frequency to your specific device’s oscillator! Though we’d argue that this is probably overkill.
Overall, the Game Bub has a very accurate clock, which we’ve measured to run ~0.008% faster than a specific GBA SP device, an imperceptible difference.
If you’re interested in getting a Game Bub for yourself, don’t forget to back our campaign!
Game Bub is part of Soldered Electronics Inkubator