About me‎ > ‎

dsPIC based Spectrum Analyzer

This is a project for viewing the frequency spectrum of input signal using dsPIC. The hardware uses the following: -

1. dsPIC30F4011.
2. Opamp (any one, like LM358, TL084).
3. Power supply.

Software includes the following: -

1. FFT library code from Microchip
2. Graphic LCD driver code (for line, pixel plot etc).

Graphic LCD showing spectrum of a square wave: -

Picture of setup: -

Picture of LCD (back side, to show the model number): -

Description of hardware: -

The dsPIC runs on the internal oscillator of 7.37MHz, which is then raised close to 30MHz using the PLL. This enables the board to run without external oscillators and associated loading capacitors.

The signal to be analyzed is passed through a high impedance resistor (1Mohms) and then amplified by opamp (TL084). This is done to avoid any high voltage damaging the dsPIC or associated circuit. DC offset is added to the signal to enable it to be measured by ADC (0V to 5V).

A programmable gain amplifier (MCP6S21) is used to scale the signals through software. Otherwise, we had to provide a potentiometer to select different gain. The signal is then fed into analog channel of dsPIC.

Hand drawn schematic: -

Description of software: -

This setup is created to measure the harmonics of power line. Considering the power frequency in India as 50Hz and we need to measure up to 10th Harmonics (500Hz), the sampling frequency for ADC is fixed to 1024Hz. The number of FFT bins set to 128. This gives a frequency resolution of (1024/128 = ) 8Hz. This provides enough resolution to detect the even and odd harmonics. These settings are provided in the file -- fft.h.

Once 128 samples are acquired by ADC, the signal is processed through FFT routine. This is available as ready made code from Microhip. The file names are: -

1. fft.s --> actual FFT function written in assembly. I used "in place" algorithm to save memory.
2. inittwid.s, twiddleFactors.c --> twiddle factor.
3. bitrev.s --> function to perform bit reversal function.
3. cplxsqrmag.s --> computes the "squared" magnitude or real and imaginary bins.

After the magnitude values are available, the values are plotted on GLCD using line plot algorithm. This algorithm is based on "Bresenham's line algorithm".

Video link for demonstration: -

YouTube Video

The code is attached below.
Debraj Deb,
Oct 29, 2011, 11:09 PM
Debraj Deb,
Mar 12, 2011, 2:41 AM