Graph Visualization for MSP430

From Texas Instruments Wiki
Jump to: navigation, search

This page is intented to show an application that demonstrates the graph capabilities of CCSv4 for MSP430 users.


The capability of displaying data on a graphical display inside Code Composer Studio is a well known feature for TI DSP developers. Since the new CCSv4 extends support to the MSP430 family of devices, this capability becomes an interesting and useful feature for displaying data on-the-fly directly from memory buffers and registers. This page details the procedure to perform this task and makes some considerations about the displayed data. It uses (and slightly modifies) the well known ADC12 MSP430F149 example code available on the web.


This page refers to the following documents:

MSP430F149 Datasheet:

MSP430F1xx User's Guide:

MSP430x13x, MSP430F14x, MSP430F15x, MSP430F16x code examples:

How to create Custom Target Configurations: Creating_Custom_Target_Configurations

Q format for fixed point arithmetic article on wikipedia:

Not covered in this document

Several topics are outside the scope of this document: CCSv4 installation, emulator and hardware configuration, details about the MSP430F149 ADC12 converter, and anything else you can't find here!

How to proceed:

Download and installation of the required components

  • If you haven't done so, download and install CCSv4. Make sure the proper MSP430 emulators are installed (the parallel port emulator is not installed by default).
  • Download and unzip the code examples from the reference above; it will extract several C and assembly source files tailored for several MSP430 devices. In this example the file <fet140_adc12_01.c> will be used.

Creating the example project

  • Inside CCSv4, create a new MSP430 project: go to File -> New -> CCS Project... and name it MSP430_graph. Click Next.
  • Select MSP430 as the Project Type and click Next.
  • No dependent projects are required for this application, therefore click Next.
  • Select MSP430F149 as the Device Variant and click Finish. The project is created and you should see the screen below:
Fig. 1: New project
  • Right-click on the project name MSP430_graph and click on Add Files to Project.... Point to the directory you installed the code examples and select the file <fet140_adc12_01.c>.
  • Double-click on this source file and locate line 31 (check the modified code below). The dividers ADC12DIV0, ADC12DIV1 and ADC12DIV2 will be added to the ADC12CTL1 register in order to slow down the conversion rate. This will make the ADC run at around 5Hz and is just for displaying purposes, since it is impossible to display data if the ADC is running at 200kSPS...
  ADC12CTL0 = SHT0_2 + ADC12ON;             // Set sampling time, turn on ADC12
  ADC12CTL1 = SHP + ADC12DIV0 + ADC12DIV1 + ADC12DIV2; // Use sampling timer
  ADC12IE = 0x01;                           // Enable interrupt
  ADC12CTL0 |= ENC;                         // Conversion enabled
  • When the project was created it may have also included a target configuration in the file <MSP430F149.ccxml> that uses the USB emulator. If this does not reflect your hardware please refer to the reference above on how to create or modify a target configuration.
  • Build the project: Menu Project -> Build Active Project. If everything was successful you should have the screen below. Go to the next section.
Fig. 2: Build successful

Configuring the graph display and debugging

  • Open the debugger and load the project to the board. Menu Target -> Debug Active Project. If everything is ok you should have the screen below:
Fig. 3: Project loaded
  • In the source window locate line 48 and double-click on it to enable a breakpoint. You will see a small blue dot MSP430 graph bkpt bluedot.JPG close to the line number.
  • Right-click on the blue dot and click on Breakpoint Properties.... This will configure the action when the program reaches the breakpoint.
  • At the Property Action, click on its Value and select Refresh All Windows. This will refresh all windows instead of completely halting the program at this point. Check the screen below:
Fig. 4: Breakpoint properties
  • The register ADC12MEM0 contains the result of the conversion for this example program, therefore this is the value needed for displaying in both the graph window and the watch window. Click on Tools -> Graph -> Single Time and configure the options as below:
Property Value
Acquisition Buffer Size 1
Dsp Data Type 16 bit unsigned integer
Q_value 12
Sampling Rate HZ 5
Start Address ADC12MEM0
Time Display Unit s
  • A graph window should appear at the bottom of the screen. If needed, the graph properties can be changed by clicking on the button MSP430 graph properties btn.JPG.
  • To see the actual value of ADC12MEM0 register, click on the tab Watch (should be at the upper right portion of the screen) and click on new. Type *(0x140) which corresponds to the contents of the address 0x140
  • Now simply Run the target! You should see the graph and the watch window updating one sample at a time in animated form.

What is happening with the values displayed in the graph? Why do they look wrong?

The main reason for this is due to the fact that the display graph does not know the maximum voltage of the ADC; it is actually a normalized value referred to the Q value setting of the graph display (check the Q format reference above).

Because the ADC only reaches 12 bits and the graph display shows 16 bit unsigned integers, the Q value must be set. If the Q value is left to its default value of 0, the Y axis would only show the decimal values corresponding to the ADC output codes (from 0 to 4095).

Therefore, in order to have a better correlation with the ADC voltage input on the graph tool the Q value was set to 12, forcing the graph tool to reach 1 when the ADC data equals to 0xFFF.

This turns the graph values into the normalized values relative to the maximum input voltage of the ADC. For example, if the ADC maximum voltage (AVcc) is 2.8V the display below shows values of 0,2; 0,4; 0,6 and 0,8 that correspond to <math>2.8 \times 0,2 = 0,56V</math>; <math>2.8 \times 0,4 = 1.12V</math>; <math>2.8 \times 0,6 = 1.68V</math>; <math>2.8 \times 0,8 = 2.24V</math>

Fig. 5: Final display graph

Considerations and possible issues

  • There are plans to implement a feature that sets the maximum input on the graph tool to avoid the use of normalized values.
  • Sometimes changing the graph tool properties while running the code takes a long while to update it. The root cause was not yet found.
  • The graph display tool has the auto scaling enabled by default. This leads to highly variable measurements as the input is settled, however they refer simply to missing codes or noise in the input. This is similar to a measurement done using an auto-range oscilloscope with AC coupling and a pre-set DC level. As an example check the screen below, where a constant input voltage leads to a variable input voltage from 0,1885 through 0,1895
    • New for CCSv4 Release Candidate!!! The auto scale can be disabled; just right-click on the graph window and uncheck the option Auto Scale.

Fig. 6: Auto scale effect on values

--Rsjsouza 15:54, 28 April 2009 (CDT)