1. Introduction


NXP Semconductors has a DSP library available for the LCP1300 and LPC1700 series. This DSP library is free to use for commercial and open source projects and we ported it to the CoIDE environment for the Simplecortex and can be downloaded from our repository. This DSP library has the following functions:

  1. Biquad filter
  2. Fast fourier transform
  3. Dot product
  4. Vector manipulation
  5. FIR filter
  6. Resonator (to generate sine waves in software)
  7. PID controller
  8. Random number generator

There are examples for the Biquad filter, FFT, Resonator and Random number generator. As we don't have much knowledge in DSP functions and the NXP app note doesn't explain the functions really well we only have an explanation of the FFT, Resonator and Random number generator at the moment. We are very busy with getting the PID to work as it's a widely used function so we can add it. The other functions might be added in the future but are not top priority at the moment. The original NXP App note can be found here and has a basic explanation for all the functions in the DSP library.

Warning: This is a library for people that have some experience in DSP's, even the explained examples are not for the people that just wrote a blink a led.

2. Includes


The library contains a pre-compiler library and some assembly files. To use it, drag and drop the DSP folder containing all the libraries in the project. Two extra include in the code is needed:

#include “DSP.cr_dsplib.h”

#include “math.h”

The precompiled library has to be added in the Configuration, to do this, rightclick on the project and click on configuration. In the new windows there is a section on the right called "Linked libraries". 2 libraries has to be added, the DSP library and the math library. To add the math library, press add, in the pop up window type the letter "m" and press OK. For the DSP library, press add, in the pop up window, press Workspace and navigate to the file called "cr_dsplibFFT_cm3.a" in the DSP folder and add it.

 Libraryadd

After that, compile and the DSP library is added.

 

3. Random number generator


The random number generator can be a handy function to quickly and simply generate random numbers. The numbers are not really random but pseudo random and should not be used for things like lotteries and applications requiriing real random numbers. It takes less then 0.4 uS to calcurate one random number at 100Mhz clockspeed. It uses the LCG algorithm, a well knows algorith that's fast to calcurate The command for the random number generator is:

int variable = 0;

int seed = 42;

variable = iF_RandomNumber(seed);

It uses the seed variable to calculate the random number, to get a new random number the seed variable has to be different! The random number is a 32 bits number, for smaller variables this number can be divided but a better method is to take the top bits as the are more "random". To do this the following code can be used:


variable = variable & 0xff000000;               //only keep the top 8 bits

variable = variable >> 24;                         //shift them 24 places to get an 8 bit variable


4. Resonator


The resonator can be used to generate a sine wave. It will generate a sine wave and put it in an array so it can be used for other applications. Take a look at the simple example provided here how to use it. There are a couple of settings that are interesting. FRATCSBITS and SCALEFACTOR should be keps the way they are. Amplitude changes the amplitude of the sine (cannot be more then 2.14) and TESTSIZE is the size of the sine created.Please mind, this command creates 32 bit variables for the sine, so a 512 word sine takes 512 * 4 = 2Kbyte RAM. Omega is the frequency of the sine as a fraction of the samplerate and can be changes to make the sine a higher or lower frequency. The generated sinewave can be send to the DAC to make a real life sine for example.


5. Fast fourier transform


The fast fourier transform, or FFT, is used to analyse a signal and create a graph that contains what frequency is in the signal and how much of it. FFT's can be used to measure distortion in amplifier for example. NXP has an app note on how to use FFT to decode DTMF tones that can be downloaded here. The example provided for the FFT, the Sine to FFT example, generates 2 sines, one with a 10 times higher frequency then the other, adds them together and then shows an FFT on the LCD of the added sines.

There are 4 FFT commands, one for a 64 point long FFT, one for 256 points, one for 1024 points and one for 4096 points. A 1024 point FFT on a 100Mhz clock takes 1.2 mS and on a 120Mhz clock is just over 1mS. The command for the FFT is

short OutputTESTSIZE * 2];
short Input[TESTSIZE];

vF_dspl_fftR4b16N1024(Output, Input);

For a different size then 1024 points just replace 1024 for the required points (64, 256, 1024 or 4096). As the FFT calculates the real and imaginary part for a 1024 point FFT a 2048 point variable is required for the output, one for the data the FFT will use and one for the calculated FFT data. This can be quite some RAM used. If you don't need the imaginary data just use the first half of the FFT data and ignore the last half. The example provided explains a lot, give it a look.

The output of the example on the LCD looks like this:

DSC02376

As you can see on the FFT the signal had 2 sines in it, 1 with a very high amplitude and one with a lower amplitude but a higher frequency. As it is impossible to generate a perfect sine with digital equipment the generated sines are also not perfect and are a bit distorted, also visible in the FFT as the small "bumps" between the large and less large peak from the generated sines.

Copyright 2011. Joomla 1.7 templates - Joomla template maker. The Simplecortex is developed by BRC-Electronics