Real-Time Audio Spectrum Analyser on PIC18F4550

This project implements a real-time audio spectrum analyser using a PIC18F4550 8-bit microcontroller from Microchip. The spectrum frequency analysis is performed by a highly optimised 16-bit Fast Fourier Transformation (FFT) routine coded entirely in C. The output from the FFT is displayed using a 128×64 graphical LCD ATM12864D to allow a real-time view of an audio signal.

Real-Time Audio Spectrum Analyser on PIC18F4550


YouTube Demonstration Video

Hardware

In order to perform a FFT calculation on an audio signal it is necessary to prepare the audio so the PIC18F4550 can sample the signal. The PIC18F4550 provides several analogue to digital converters (ADCs) which can be used to measure a voltage from 0V to 5V with 10-bit accuracy (0-1023). A typical audio line-out signal is an analogue wave with a peak-to-peak intensity of 1V centred around 0V (i.e. it is an AC signal) as shown by the following oscilloscope trace (from pin W2 of the demo board):

full-volume 5000Hz sine wave

The picture shows a full-volume 5000Hz sine wave generated by a PC. If we were to feed this signal directly to the PIC we would only have a very small range of input voltage (0-0.5V) and also we would only be able to sample the top-half of the signal which would make the FFT incorrect.

In order to correctly sample the signal we have to do two things. Firstly we need to amplify the signal to ensure we can use as much of the 0-5V range as possible. Secondly we have to move the signal's ground (of 0 volts) to a 'virtual ground' of 2.5Vs. This will allow the PIC to sample both the positive and the negative sides of the input signal. To do this the demonstration board uses a simple amplifier IC (the LM386-1). Since the IC is powered from a 0V and 5V power supply it has the handy side-effect of also moving the signal into the middle of our required power range. The LM386-1 was used because it is cheap and simple, however you could use a rail-to-rail opamp to achieve the same thing with a few more external components.

The following oscilloscope trace shows the output signal from the LM386-1 (for the signal shown above), the scope voltage range is set to 5 volts (from pin W3 of the demo board):

move the signal's ground (of 0 volts) to a 'virtual ground' of 2.5Vs

The hardware mixes the stereo line-in using two 10K resistors which act as a simple mixer. The signal is then passed to the LM386-1 via a 10K potentiometer which allows the signal strength to be adjusted. Next the LM386-1 amplifier output is passed through a simple RC Filter which rolls off the signal at about 10Khz. The resulting signal is then fed into an ADC pin on the PIC18F4550. The 10Khz filter acts as an 'anti-aliasing' filter for the FFT which cannot correctly detect signals with a frequency of greater than 10KHz. An RC filter is a very simple type of filter (and very ineffective) but it was chosen since it is easy to build and only requires 2 passive components. Typically a professional spectrum analyser would implement the anti-alias filter at 80% of the Nyquist frequency for the FFT, but since we are so speed-limited with the PIC this is not possible to do in the design.

The demo board also controls a standard 128×64 dot-matrix LCD as well as 3 LEDs (for testing sound-to-light conversion). In addition there are 2 switches to allow the user to control the LCD's output depending on what is being measured and how it is to be displayed. The second phono socket allows you to pass-through the input signal to another audio device such as headphones or speakers.

Here is the circuit schematic for the demonstration board:

Принципиальная схема: анализатор спектра на PIC18F4550
Click to enlarge

The circuit board design is a single-layer PCB using only through-hole components to make it as easy as possible to duplicate. I used a PIC18F4550 for the extra I/O pins however it can be directly replaced with the smaller PIC18F2550 which is code-compatible. The circuit is also simple enough to be built easily on a breadboard if you wish to experiment with the design. Here is a picture of the PCB artwork which is included in the downloads section below:

Печатная плата: анализатор спектра на PIC18F4550
Кликните для увеличения

Downloads

The PCB artwork and schematics in expressSCH and expressPCB format - download

Part 2. Firmware

waitingforfriday.com

You may have to register before you can post comments and get full access to forum.
EMS supplier