Tutorial 1. Creating and Testing MSP430 FFT Code
If you are using FFT Designer for the first time, it may be helpful to read through this tutorial. The following topics are covered.
1. Creating a 512 point FFT with a Kaiser window function
Starting a new design
Open FFT Designer and select File->New. This resets all design parameters to the default which is a Fixed Precision FFT and Hamming window.
Selecting the FFT Length and Window Type
For this tutorial we want an input length of 512, so select this using the "FFT Input Length" dropdown. Next use the "Window Function" dropdown to select the Kaiser window type.
Note that the α parameter is now enabled as this controls the shape of the Kaiser window type. Have a play around with different values then complete step 1 by entering a value of 2.7 as shown.
2. Selecting an output language and Class Name
First select the output language from the two available options, "Standard ANSI C" and "MSP430 Extended C". If your application requires a floating point FFT or is not for an MSP430 target, you should select "Standard ANSI C". However, in this tutorial we are going to create a fixed point FFT for the MSP430F5418 target, so select "MSP430 Extended C".
Selecting the Output Language and Class Name
The Class Name or Prefix is prepended to all FFT methods, defines and global variables. This allows you to have any number of different FFT algorithms within a single project or to avoid a conflict with existing code. For this tutorial, we will use the default "MyFFT". Complete this step by entering "MyFFT" onto the "Class Name / Prefix" box as shown.
3. Selecting an Algorithm Type and Options
Depending upon the Output Language, different algorithms and options are available. In our case, we have selected "MSP430 Extended C" so only one algorithm "Integer 16 Bit" is available. This algorithm has been specially optimised for the MSP430 and has two additional controls. We will see the effect of these controls as we examine the performance later on.
4. Investigating the dynamic range and selectivity
Now we are going to check out how the selected FFT and window function perform by using the dual frequency Test Signal Generator (TSG). Using this tool, we can quickly determine whether the FFT will do the job we require.
In this tutorial we will assume that we have a signal source sampled at 256Hz and we need to determine the dominant frequency component. First, we configure the display to represent meaningful frequencies and times. Enter 256 into the "Sample Rate" box and set the Units dropdown to Hz. Also set an initial test frequency of 32Hz by entering 32 into the "F1" box.
The first thing to note is that the "Buffer Fill Time" is 2 seconds. Since the Test Signal Generator outputs a continuous signal, this is not a problem. However, if our signal was not steady-state over the "Buffer Fill Time", the input length, and consequently the frequency resolution, may need to be reduced.
Now adjust the Display Range dropdown to -80dB. You should see one main peak at the F1 test frequency with a noise floor of roughly -70dB rising slightly towards DC. The display is effectively showing us the limitations of the 16 bit fixed-point algorithm. At this stage you may like to compare how the floating point algorithms perform whilst bearing in mind that these algorithms have much longer execution times, depending on the target platform.
Now add a second carrier by checking the F2 option and entering 36Hz with a level of -60dB. The second peak should be well defined as shown here and distinct from the first. Using the slider, move the second peak around and observe that the level is fairly constant. Now uncheck the "Use shift division ....." checkbox and repeat the test. Note how this time, the noise floor is much lower but the F2 peak amplitude varies by several dB as you sweep it from DC to Nyquist.
Using the tool, you can decide which configuration best suits your application. When you are done, check both "Use shift division ....." and "Use direct access .....".
Investigating the dynamic range and selectivity
5. Saving the finished design specification as a file
Next click the File menu and select "Save". A standard file dialogue will appear. Save your design, either to the default folder or by browsing to a folder of your choice. FFT Designer remembers the folder where you last saved or loaded a design. Once the FFT design specification has been saved, you can recall it later on, either by double clicking the file, or by opening it from the program menu. Note. When FFT Designer opens, the controls are automatically restored to where you left them so even if you haven't explicitly saved the design, you can close and re-open the program without losing your work.
Saving the finished design specification as a file
6. Generating the FFT Source-Code
Before you click the "Generate FFT Source Code" button, note that FFT Designer will write your source-code to the current "Output Folder". Each file will be prefixed by the "Class Name / Prefix" entered earlier, so you can easily avoid a conflict with existing code. If you wish to check or change the location of this folder, go to the Tools menu and select Preferences. Click the "Output Folder" tab to display the current location and if needed, click the "Change Output Folder" button to select a new location. When you click OK, FFT Designer will remember the new output folder location.
Now click the "Generate FFT Source Code" button. Your source code files will be written to the current "Output Folder". Click "View Output Folder" and confirm that there are 8 files starting with the prefix. In this case "MyFFT".
Generating the FFT Source-Code
7. Creating a test project under Embedded Workbench
The files generated by FFT Designer include an example as well as a set of test vectors. The test vectors can be used to verify that the Discrete Fourier Transform and window function calculated by the compiled source-code is an exact match of the result calculated and displayed by FFT Designer.
The first step towards verification is to create a project for the compiler we have targeted. In this tutorial, we will be using the IAR Embedded Workbench for the MSP430 - EW430.
Start Embedded Workbench and click "Create New Project" from the Project menu.
Creating a New Project in Embedded Workbench
Select the "Empty Project" template then click OK.
Selecting the "Empty Project" template
For this tutorial type "test_MyFFT" as the project name and save it to the FFT Designer "Output Folder".
Naming the project "MyFFT"
Next click the Project menu and select "Add Files".
Open the "Add Files" dialog
Select the four files, MyFFT.c, MyFFT_Example, MyFFT_Tables.c and MyFFT_Test_Harness.c as shown and click OK.
Select the four .c Files
Next open the Project Options. Change the target Device to the MSP430F5418. Also, in case you later decide to test with a double precision floating point algorithm, change parameter "size of type 'double'" to 64 bits.
Select the MSP430F5418 Device and other options
Still in Project Options, click on the "C/C++ compiler" category and select the "Optimizations" tab. Change the level to High-Speed as shown below.
Change the compiler optimization level to "High-Speed"
8. Compiling and Testing the FFT code
Save the project workspace under the same name and click "Rebuild All" from the project menu. The process should complete with no errors or warnings as shown.
Build the project
Next open up the MyFFT_Example.c and set up three break-points as shown. The first two will trigger if the calculated FFT result does not exactly match the simulation. The last break-point will trigger when the test is complete.
Set Break Points
Finally run the debugger. The simulation will take around 10 seconds to run on the average PC then break on the final while(1) as shown. Using this project, you can also use the profiler to determine how many CPU cycles were required and calculate the execution time etc.
Run the simulation
9. FFT Benchmark
The performance table below was compiled using the Embedded Workbench function profiler. FFT execution times were then calculated from the reported CPU cycle count assuming an MCLK rate of 25MHz.
Note 1. Insufficient RAM on selected MSP430 device (MSP430F5418A) for algorithm compilation.
Note 2. The above results are for method MyFFT_CalculateDft(). Besides the DFT calculation, this method also copies data from the circular input buffer to the FFT workspace, applies the Kaiser window function and performs data reordering so that the DFT result is in natural order. The DFT calculation alone accounts for approximately 85% of the overall time.
10. Tutorial CompleteThat's it! You have completed the tutorial in which you ....
11. Practical ApplicationIf you would like to put your ideas into practice, our ultra low power MSP430 Development board is an easy way to start. For more information, please visit the FFTD1A product homepage