Tutorial 3. Creating FFT code for Code Composer Studio (MSP430)

If you are using Code Composer Studio for an MSP430 target, it may be helpful to read through this tutorial. The following topics are covered.

  • Creating a 512 point FFT with a Kaiser window function
  • Selecting an output language and Class Name
  • Selecting an Algorithm Type and Options
  • Investigating the dynamic range and selectivity
  • Saving the finished design specification as a file
  • Generating the FFT Source-Code
  • Creating a test project under Code Composer Studio
  • Compiling the FFT code

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 MSP430F5418A 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. Changing the FFT Designer Output Folder

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. For the purposes of this tutorial, we will save the generated code directly into a specific tutorial project folder.

To do this, go to the Tools menu and select Preferences. Click the "Output Folder" tab to display the current location then click the "Change Output Folder" button and change the location to C:\Tutorial_3 using the Create New Folder button as required. Once you click OK, FFT Designer will remember the new output folder location.

changing the output location

Changing the output location to C:\Tutorial_3

7. Generating the FFT Source-Code

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

8. Creating a test project under Code Composer Studio

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 compilation is to create a project for the compiler we have targeted. In this tutorial, we will be using Code Composer Studio for the MSP430 version 6.0.1.

Start Code Composer Studio and click "New CCS Project..." from the Project menu.


Creating a new project in Code Composer Studio

In the New CCS Project window, make the following selections / entries.

  • Target: MSP430F5418A
  • Project name: Tutorial_3
  • Location: C:\Tutorial_3 (uncheck "Use default location")
  • Template: Select the "Empty Project" template
Once the details are correct, click the Finish button to create the project.


Creating a new project with the "Empty Project" template

Since the FFT Designer generated code was saved directly into the CCS project location, the files will automatically be added to the project which should resemble the image below".


CCS Project showing FFT Designer Files

9. Doing a Test Compile

Next, do a test compile. You will get a number of errors as shown in the window below. Don't Panic! This is expected.


Compiling unmodified FFT Designer generated code will result in errors

10. Removing unsupported compiler directive "__no_init"

The problem is due to variations in the way C is implemented by different compilers. In IAR Embedded Workbench for the MSP430 (EW430), global variables are always initialised at startup. However, since this variable initialisation is done at the default CPU speed and before application code can turn off the watchdog, the standard practice of initialising all global variables can cause problems. If the application requires a large global array, the watchdog may trigger before main() is called resulting in code that will never run. To get round this problem, compiler manufacturers have come up with various workarounds but unfortunately there is no standard. For example, IAR's EWB430 compiler offers the compiler directive "__no_init" which when added before a variable declaration will ensure initialisation of that variable is skipped during C startup. This directive is used by FFT Designer. However, CCS does not use or recognise this directive and instead does not initialise global variables unless an explicit value is assigned. E.g. int my_global_variable=0; (initialised) as opposed to int my_global_variable; (non initialised).

So the errors are due to the "__no_init" directive which is specific to the IAR compiler and not recognised by Code Composer Studio.

Fortunately, correcting the problem is simple. Just use search and replace with "__no_init " in the search field (ensure you include the trailing space) and an empty replace field. This will remove the compiler directives causing the error. The files affected are MyFFT_Example.c and MyFFT.c source files. Once the search and replace has been done, rebuild the project. There should be no errors.

11. Compiling the modified code

compiler settings

12. Tutorial Complete

That's it! You have completed the tutorial in which you ....
  • Selected your FFT algorithm and window function
  • Simulated and analysed the performance
  • Generated the source code and test harness
  • Compiled it using Code Composer Studio for the MSP430

13. Practical Application

If 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