Raspberry Pi I2S Sound – Add Digital Sound Output to Your Raspberry Pi
30th May 2021The Games That Created the Gaming Industry – The Golden Age of Video Games
16th June 2021How to Overclock Your Raspberry Pi – Squeeze Out More Processing Power
(This page is part of the Raspberry Pi Handheld Games Console series. Please click here for the full project.)
The default speed settings on Raspberry Pi’s are quite safe when it comes to speed and performance. With a bit of tweaking we can increase both the processing and graphics power on any of the boards by a fairly significant margin.
The Raspberry Pi system makes it very easy to implement overclocking. You simply need to add a few parameters into your/boot/config.txt file and the job is done.
Caution – Overclocking Can Damage Your Board
Before we start tinkering with our Raspberry Pi’s you need to be aware that overclocking any microprocessor system can cause permanent damage to the hardware. On a Raspberry Pi this is unlikely as the processor has a lot of thermal protection features, but there is still a possibility. Some of the overclocking techniques also set an irreversible flag on the board which invalidates your warranty and signals to other people that the board has been overclocked.
Is Cooling Needed?
Any form of overclocking will generate more heat in your processor, graphics processor and memory. Extra cooling will always help the situation but depending on how hard you over clock the system it may or may not be necessary.
In this tutorial I’ll be overclocking a Raspberry Pi Zero to boost its performance in my handheld retro games console. I’m not intending to add any extra cooling so I’ll be showing you how to monitor temperatures to make sure that your system is safe from damage.
What Is Overclocking?
All microprocessor systems rely on clock signals to control the way they work. These clock signals are simply voltages that repeatedly flip from 0 V to, for example, 3.3 V, or whatever power supply the microprocessor works from.
Microprocessors turn your program commands into series of electronic steps. The processor is only able to take the next step when it receives a pulse from its clock signal.
The basic principle is that the faster you pulse the clock signal, the faster the processor will work through these steps and therefore the faster your program will run.
Frequency, Voltage and Heat
In essence overclocking is a very simple process. The clock signals operate at specified frequencies so we simply have to increase the frequency to increase the speed of a processor.
Doing this however, introduces a couple of problems.
Although we quite often draw clock signals as perfect square waves, the signals do require some time to flip between high and low, and low and high signal levels. These times are called the rise and fall times, or transition time.
As the clock signal frequency is increased the time taken for a clock signal to fall (high to low) and rise (low to high) interferes with the actual clock signal which breaks down and causes the processor to crash.
To overcome this problem we need to increase the speed at which the clock signal can flip. This is done by increasing the voltage level of the system by introducing an overvoltage. Taken to the extreme, too high a voltage can damage some of the internal components in your system.
Also, as you increase the frequency you increase the power dissipation inside the processor. Increasing the voltages also increases the participation inside the processor. This power is dumped in the form of heat. So as we overclocked our processor it’s going to get hotter. If the processor gets too hot again, it can damage some of the internal components in the system.
Safe Overclocking on Your Raspberry Pi
Overclocking does have its dangers but the Raspberry Pi has been cleverly designed to protect itself from anything you might do to it. For overvoltage protection it only allows you to adjust the voltages to safe levels. For thermal protection the system will automatically reduce its clock speeds if the system gets too hot.
Generally, the worst that will happen as you play with overclocking on your Raspberry Pi is that the system may become unstable and crash, or go into thermal protection and turn off all your overclocking settings taking you back to the standard processor speeds.
Power Usage
One consideration, especially if you’re producing a battery-powered device, is power usage. As you’ve seen every bit of overclocking increases the power used by the system. If power supply is at a premium overclocking will work against you. It will reduce your battery life or potentially require you to use a higher current power supply.
How to Overclock Your Raspberry Pi
To overclock your Raspberry Pi you simply need to add a few parameters into your /boot/config.txt file. The main parameters that I’ll be using in this tutorial are :
arm_freq
Frequency of the ARM CPU in MHz.
gpu_freq
Sets core_freq, h264_freq, isp_freq, v3d_freq and hevc_freq together
core_freq
Frequency of the GPU processor core in MHz, influences CPU performance because it drives the L2 cache and memory bus; the L2 cache benefits only Pi Zero/Pi Zero W/ Pi 1, there is a small benefit for SDRAM on Pi 2/Pi 3. See section below for use on the Pi 4.
sdram_freq
Frequency of the SDRAM in MHz. SDRAM overclocking on Pi 4B is not currently supported.
over_voltage
CPU/GPU core voltage adjustment. The value should be in the range [-16, 8] which equates to the range [0.8V, 1.4V] with 0.025V steps. In other words, specifying -16 will give 0.8V as the GPU/core voltage, and specifying 8 will give 1.4V.
force_turbo
Forces turbo mode frequencies even when the ARM cores are not busy. Enabling this may set the warranty bit if over_voltage_* is also set.
For a full list of the available options please have a look at the Raspberry Pi documentation.
https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md
This page also gives a list of the default settings for each clock frequency for the full range of Raspberry Pi models.
To add an over clock setting into your config.txt file you simply create a new line in the file and assign the setting a value.
arm_freq=1080 core_freq = 500 gpu_freq=400
The Overclocking Process
The basic process to find the best overclocking setup is to :
- increase a clock speed in the config.txt file
- reboot the Raspberry Pi to see if it still works
- if it works monitor the processor temperature
- if the temperature is fine repeat the process
- repeat the process for each of the clock speeds until you find a stable, working, cool setup
At some points you’ll find that when you reboot the Raspberry Pi the system will just crash. At this point you’ll need to turn off the Raspberry Pi, take out the SD card and edit the config.txt file in another computer. Alternatively, if you got a keyboard attached, just hold down your shift key while the system reboots and this will automatically disable any overclocked settings you’ve added.
How to Monitor Your Processor Temperatures On Your Raspberry Pi
It’s important to keep an eye on your system temperatures as you test your overclocking settings. You will need to put the processor under some load by getting it to play a video or run an intensive game on your RetroPie setup. Without this load the system won’t be making use of your overclocking settings and you won’t get a true indication of what temperature the system will run at when it’s being pushed.
The commands
cat /sys/class/thermal/thermal_zone0/temp
and
vcgencmd measure_temp
display system temperature (divide by 1000 to get Celsius) and GPU temperature respectively.
The absolute maximum stable temperature the system can run at is 80°C. Above this the system will go into thermal protection and automatically reduce all your clock speeds to cool the processor down.
Ideally, you want the system to run at least 15 to 20°C less than this upper limit if possible.
Overclocking the Raspberry Pi Zero For RetroPie
For my handheld retro gaming console I’ve been using a Raspberry Pi Zero running RetroPie. The Raspberry Pi Zero is one of the least powerful devices but it’s still able to run most of the older gaming console emulators such as SNES, MegaDrive and all the models prior to these. Even so it can still struggle with some titles at its default processor speeds.
My aim in overclocking was not so much to allow it to run more modern emulators, but more to make sure that the emulators it did run had improved performance to keep even the more taxing games running smoothly.
Using the basic overclocking process I’ve already described I settled on the following settings.
#overclocking # force full speed force_turbo=1 # separate core_freq and gpu_freq - may interfere with analog sound arm_freq=1085 gpu_freq=530 core_freq=515 over_voltage=2 sdram_freq=533 over_voltage_sdram=1
My aim was to not require any additional cooling, although I may fit a passive heatsink if there’s enough room inside the case. This also meant that there wouldn’t be as much energy wastage through heat loss and processor power which would drain the consuls battery to fast.
As usual there are always a number of compromises you need to make depending on the system your building.
Measuring the Results
There are a number of ways to measure the success of your overclocking settings.
You can use various benchmarking applications and scripts to give you an actual numerical value for how well your system is performing. The most popular one for the command line is Sysbench.
sudo apt-get install sysbench
You can then run a CPU benchmark using one of the following commands :
For a single processor system (Pi Zero)
sysbench –-test=cpu –-cpu-max-prime=10000 run
For a multi core system
sysbench –-test=cpu –-cpu-max-prime=10000 run -–num-threads=4
This test checks every number up to cpu-max-prime to see if it is a prime number by dividing it by every odd number up to its square root. You can increase the length of the test by increasing the cpu-max-prime number.
To run a RAM benchmark
sysbench –-test=memory –-memory-block-size=1M –-memory-total-size=10G run
This test creates a block of memory with size memory-block-size and then reads and writes to it continually until it has read / written memory-total-size bytes of data. Again you can increase the length of the test by adjusting the memory-total-size value.
Measuring the Results in RetroPie
In RetroPie the main outcome is to keep the game frame rate as high as possible. If the processor is unable to cope the frame rate will drop and both the video and sound quality will start to stutter. You can get RetroPie to display the current frame rate while you’re playing a game.
Go to the RetroPie configuration from the main menu and select RetroArch (use you’re a to select). Then go to Settings, On Screen Display, On Screen Notifications.. There you’ll find a Display Frame Rate option which you can turn on and off by selecting it.
Then go back (B button) until you get to the Main Menu. Select Configuration File and then Save Current Configuration.
When you next play a game you’ll see the frame rate in one of the screen corners. If you’re using a small LCD screen it can be a bit hard to read but the number doesn’t change very quickly so you should be okay.
To assess how well your overclocking settings are working try playing the same game after each change. Try to get a feel for the general frame rate and how well the sound and video performs.
To measure system temperature while running the games you can set a watch on the terminal if you’re using SSH to connect. Just type,
watch -n 2 vcgencmd measure_temp
and the system will display a temperature value that updates every 2 seconds (set by the -n 2 setting).
Summary
Hopefully you seen that overclocking a Raspberry Pi is neither difficult nor dangerous (at least of the Raspberry Pi). You can get a significant performance boost quite quickly by just tweaking a few clock speed settings.
For my handheld retro gaming console project this gives the Raspberry Pi that little bit extra processing power to make sure that the games I want to play run smoothly and glitch free.