Tag Archives: Code Composer Studio

Code Composer Studio Graphing Tool Tutorial banner MSP430 C2000 Tiva C

Code Composer Studio Graphing Tool Tutorial

 

In this Code Composer Studio graphing tool tutorial, graphing variables will be demonstrated in Texas Instruments IDE.  The process is fairly straightforward and will be shown in a video as well as some screenshots so it can be easily replicated.

Introduction

For the demonstration a program running on the MSP430G Launchpad was used, with the MSP430G2553 fitted.  The Launchpad was connected to a small experimental PID boc I have constructed, which I call the ‘Pocket PID’ (tutorial to follow on this), the box uses a LM35DZ temperature sensor as well as a few other components.  The voltage from the LM35DZ is sampled and then two variables are generated; a variable called Result which is comprised of a raw data set of several over samples and a variable called FilteredResult, which is a digitally filtered version of the Result variable.  Both variables can be viewed side by side which allows the effectiveness of the digital filter to be observed, the box also has a small heater and fan which allows the variables rate of change to be viewed over time in a graphical format. This provides a good example of how the code composer studio graphing tool can be used.

The graphing tool can also bee seen in action on another tutorial based on the C2000 Launchpad, where it is used to view the operation of an solar MPPT, graphing the power, voltage and PWM duty cycle.  The third part of the article concerned with this can be found here and the YouTube video here.

Code Composer Studio Graphing Tool Tutorial – Video Demonstration

Code Composer Studio Graphing Tool Tutorial – Main Steps

The main steps to access the the graphing tool in code composer studio (CCS) are carried out in debug mode, so all the screenshot images below are taken from within that mode.  As with all software there are often other ways to achieve the same results, this is just a method that works for me.

The first step is to decide which variables you want to graph and add these as Watch Expressions in CCS, this is achieved by highlighting the variable and then right clicking to bring up a properties menu, from this menu you want to choose the Add Watch Expression selection. This is shown in the below image.

Code Composer Studio Graphing Tool Tutorial Add Watch Expression MSP430 Tiva C C2000

If this has been successful then the variable chosen should then appear in the Expressions window, which is shown in the next image.

Code Composer Studio Graphing Tool Tutorial Watch Expression Visible MSP430 Tiva C C2000

You can add as many watch expressions as necessary, the video demonstration shows two variables being watched and graphed, but I have successfully watched and graphed four expressions.  I am not sure if there is an upper limit, but i have noticed stability issues when many variables are being watched over a long period of time.

After adding the variables required to the watch expression window, the next step is to add breakpoint and then edit the breakpoint properties.  Adding a breakpoint can be achieved either by double clicking on the line number, or highlighting a section of code on the line number and right clicking, then selecting the Breakpoint (Code Composer Studio) and Breakpoint option.  The image below illustrates this action.

Code Composer Studio Graphing Tool Tutorial Add Breakpoint MSP430 Tiva C C2000

Once the breakpoint has been added it should be visible in the Breakpoint window, for the breakpoint to be enabled it needs to have a tick in the far left column.  The image below shows the breakpoint window with the tick in the far left column, as well as an arrow highlighting the Action column.

Code Composer Studio Graphing Tool Tutorial Breakpoint Visible MSP430 Tiva C C2000

A breakpoint by default will halt the program at the chosen point, for the graphing tool to work all the windows simply need to be refreshed, this then allows the Expressions window and the graph to be updated.  The next image illustrates how this is achieved by editing the breakpoint properties.  I simply right click on the breakpoint symbol shown next to the line number it will activate, this then brings up a properties list and then select the Breakpoint Properties option. The image below shows this then step.

Code Composer Studio Graphing Tool Tutorial Breakpoint Properties MSP430 Tiva C C2000

Once the Breakpoint Properties window is open there are a few options that are accessible, for this tutorial only one is of interest which is the Action property.  As already mentioned the action the breakpoint will carry out by default is half the program, for the watched expressions to update, this action simply needs to be changed to Refresh All Windows.  The next image illustrates how this is changed.

Code Composer Studio Graphing Tool Tutorial Breakpoint Properties Change Action MSP430 Tiva C C2000

 

Now that the variables have been added and a breakpoint has been placed and set-up to perform the required action, the variables to be graphed can be chosen and set-up.  To bring a graph up for a particular variable, right click on the variable in the Expressions window and then select the option Graph,  as per the image below.

Code Composer Studio Graphing Tool Tutorial Watch Expression Right Click MSP430 Tiva C C2000

Once the graph option is selected the graph should be visible in CCS, I find it usually defaults to the bottom left of the window, as shown in the next image.  The graph window can be manipulated to the required size as well as being picked and placed as required.  Additional graphing windows can be added for other variables in the same way.

Code Composer Studio Graphing Tool Tutorial Tutorial Add Graph Window MSP430 Tiva C C2000

Now the graphing windows also has various options which allow you to tailor the view for your requirements, by hovering over the symbols small tooltips will appear which give a good impression of the button’s action.  This tutorial will only cover two of the buttons which provide enough of an introduction for now.  The first button is the Graph Properties button which is shown in the image below.

Code Composer Studio Graphing Tool Tutorial Graph Properties MSP430 Tiva C C2000

By clicking this button a new window will open which displays some useful quick access properties.  I usually use the Grid Style option to add a Major Grid to the x and y axis, additionally the Display Data Size option allows you to determine how much data is viewable on the graph, before it is pushed off the edge of the screen.  For long data captures increasing the Display Data Size can be useful, I have had issue with instability here though so its compromise on other settings such as Sampling Rate Hz as well as other settings for CCS when in debug mode.  The Graph Properties window is shown in the next image.

Code Composer Studio Graphing Tool Tutorial Tutorial Graph Properties MSP430 Tiva C C2000

The next button that will prove useful is the Graph Display Properties button, this is shown in the next image (also note the Major Grid now shown on the graph window).

Code Composer Studio Graphing Tool Tutorial Graph Display Properties MSP430 Tiva C C2000

The Graph Display Properties window again has quite a few options, allowing things like colour, number formats, axis names and scale to be changed.  Some of these options are demonstrated in the video, the image below shows the Graph Display Properties window and the option for the Y axis Set Number Format option window open.

Code Composer Studio Graphing Tool Tutorial Graph Display Properties MSP430 Tiva C C2000

The final image shows a screen capture from the video, with both sets of data displayed side by side.

Code Composer Studio Graphing Tool Tutorial Video Result Capture MSP430 C2000 Tiva C

I take great care when writing all the tutorials and articles, ensuring all the examples are fully tested to avoid issues for my readers.  If you have found this useful or have any problems implementing, please feel free to leave a comment and I will do my best to help.

Stellaris ADS1118 Tutorial

Stellaris ADS1118 Tutorial

Stellaris ADS1118 tutorial will show how a Stellaris LM3S6965 is interfaced with a ADS1118 16 bit ADC using the SPI bus.

The ADS1118 was chosen as it can be used to interface thermocouples, in this example only the temperature data from the on-die temperature sensor will be read. The thermocouple interfacing will be covered at a later date.  The datasheet for the ADS1118 can be downloaded form here.

ADS1118 Package

The ADC was sourced in ADS1118IDGST package, then a symbol, package and device was constructed in EagleCAD.  Once this was completed a small PCB was milled out, which can be seen below.

Stellaris ADS1118 Tutorial C Code

 

 

 

 

 

The SMD decoupling capacitor was placed as close to the IC as possible (milling machine restrictions) to reduce noise, additionally the bottom layer was used as a ground plane.  This PCB layout uses male jumper pins, therefore allowing the ADS1118 to be plugged in and used with other test boards.  For testing a small piece of veroboard was used with a few discrete components, and some female headers so the ADS1118 PCB could be plugged in. This was then connected directly to the Stellaris evaluation board, using the 3.3V line as the main supply for the ADC.  The finished test board can be seen in the below image.

Stellaris ADS1118 Tutorial LM3S6965

The ADS1118 uses the Serial Peripheral Interface (SPI) to send and receive data from a microcontroller, the Stellaris will be the master and the ADS1118 the slave.  To ensure the SPI (known as SSI on the Stellaris) connections were correct, the the datasheet for the ADS1118 was read thoroughly, this was also necessary to familiarise oneself with ADS1118 control registers and SPI mode of operation.  This is not a tutorial on SPI so there are some assumptions made, that you the reader knows some basics regarding the SPI protocol.  Some useful links for SPI reference can be found here and here

The image below shows the ADS1118IDGST pinout, for this example pins 1 to 3 and 8 to 10 were used.

Stellaris ADS1118 Tutorial LM3S6965

 

 

 

 

 

These were connecting to the Stellaris as follows:

ADS1118 SCLK —– Stellaris SSICLK

ADS1118 CS —– Stellaris SFSS

ADS1118 DIN —– Stellaris SSITX (MOSI)

ADS1118 DOUT —– Stellaris SSITX (MISO)

*These pins on the Stellaris are generally used for interfacing with the on board OLED display, in this example the OLED is not used.  There is a second SPI peripheral on the LM3S6965 evaluation board.

ADS1118 SPI Operation

From the ADC datasheet we can find some useful information regarding the transmission cycle, and what information we need to send the ADS1118 to configure the control registers.  The ADS1118 has 2 modes of operation: 32 bit data transmission cycle and a shorter 16 bit data transmission cycle, the former also allows the SS line to be tied to Gnd. The image below shows the 16 bit data transmission cycle, which is the method used in the code for this tutorial.

Stellaris ADS1118 Tutorial LM3S6965

The SS line is controlled by the master, when this goes low the the master sends a 16 bit word to the ADS1118 on the MOSI line, this word contains the control register configuration settings.  As the SPI interface allows data to be transmitted and received simultaneously, the ADS1118 sends a 16 bit word back on the MISO line.  The master then takes the SS line high, and another 16 bit word transfer can take place as soon as this is taken low again.

The control register settings for the ADS1118 are used to configure various parameters i.e. Temperature Sensor Mode, Pull-Up resistors, Programmable Gain Amplifier Configuration etc.  A full list of these parameters can be found on pages 21 and 22 of the datasheet.  For this example we will be configuring the ADS1118 to function in a basic temperature sensing mode, using the internal temperature sensor.  To configure the control register in this way the 16 bit word looks like this in binary 00000000 00010010 or 0x12 in hexadecimal.  Bit 4 is set to 1 which places the device in Temperature Sensor Mode.  Bit 1 and 2 have a fixed setting if the control register data is classed as ‘Valid data’, this is 01 anything other than this will mean the 16 bit word is invalid, and it will therefore not be written to the control register.

Information regarding the clock polarity (CPOL) and the clock phase (CPHA) can be found in Figure 1 on page 6 of the datasheet.

C Code

Now the code used in this project is loosely based on some Stellaris example code, which is bundled with Stellarisware, however this code is not in the examples for the LM3S6965 board.  As with previous posts I will list some of the code in the post, and the complete C file can be downloaded at the end of the post.

All the SSI setup code has been bundled into one function called Setup_SSI()

First of all the clock is setup which is part of any hardware setup and required not just for the SSI.  Next the SSI0 module is enabled, followed by GPIO port A being enabled which the SSI0 module uses.

After the port is enabled the next function configures the pin muxing feature for port A, which relates to the pin_map.h header file in the Stellarisware.  Not all stellaris devices support pin muxing, so check the datasheet for your device.  The GPIO pins are then configured to be used by the SSI module using the function GPIOPinTypeSSI(), this takes 2 parameters, the port base address and then the individual pins on that port.

Then SSIConfigSetExpClk() is used to configure the SSIO peripheral, with 6 parameters:

The first parameter specifies the module base address, SSI0 is used here.  The second parameter specifies the rate of the clock supplied to the SSI, system clock is used in this case.  The third parameter specifies the SPI mode used (there are 4 variations), in this case Mode 1 is used.  The forth parameter specifies if the Stellaris will function as a master or a slave device.  The fifth parameter specifies the clock rate, in this case the system clock is divided by 8 so 1MHz, and finally the sixth specifies the number of bits transferred per frame, 16 bits are used in the example.

As mentioned the SPI protocol has 4 transfer modes, this is dependent on the clock polarity (CPOL) and the clock phase (CPHA).  The links provided earlier in this post will prove useful in understanding the mode of choice, as well as reading the datasheet for the slave device to ascertain which mode of operation it uses.

The final function call is to enable the SSI0 module.

Now that the SSI0 module has been setup, the functions to send and receive data can be used.  In order to store the data to be sent and received, the code example uses an unsigned long array for the transmitted and received data.  Also a further unsigned long is used as a counter variable making the process easier, if further data words were being sent.  This format is overkill for this example, as only one 16 bit word is required to be transmitted and received.  However in this example two 16 bit words will be sent, one containing the correct control register data, and another with invalid control register data.  The number of data arrays is determined by a #define NUM_SSI_DATA 2.

Inside the main function contained within a while loop, the first function is called as follows

This functions gets the received data from the receive FIFO of the SSI0 module (the first parameter), and places the data into the location specified by the second parameter, which is a pointer to the storage location.  If there is no data the function returns zero.

After this the data arrays for transmit and receive are initialized, here the values previously discussed for the control register are loaded.

Next a for loop is used to control the flow of data being transmitted to the slave.

The SSIDataPut() function call takes 2 parameters, the base address of the SSI module and the data to be transmitted over the SSI interface.  This function uses a blocking send function, it places data into the transmit FIFO of the SSI module.  If there is no space available in the transmit FIFO, it waits until there is space before returning.  This then ensures all the data is sent.

The SSIBusy() function simply ensures that the program waits while the SSI0 module is busy. Lastly the SS line is taken high to indicate the end of the 16 bit word transfer.

The next piece of code uses another for loop to control the flow of data being received from the slave.

The SSIDataGet() function call takes 2 parameters, the base address of the SSI module and the data to be received over the SSI interface.  This function uses a blocking get function, it will wait until there is data in the receive FIFO of the SSI module.  The data is then placed into the function location specified by the second parameter pointer address.  If there is no data the function waits until data is received before returning.

The SSIBusy() function is used again here as with the previous for loop.

Before we look at the rest of the code, which is used to calculate the temperature data from the ADS1118, lets firstly look at the SPI timing diagram produced by the code.

Stellaris ADS1118 Tutorial LM3S6965

The timing diagram was captured with a USB logic analyzer, which also has a function to decode the SPI bus protocol.  As can be seen in the waveform the SS line drops low to allow data to be sent, and remains low while data in being trasnmitted and receieved.  The serial clock starts shortly after the SS line drops low, and data is transmitted from master to slave on the MOSI line, and from slave to master on the MISO line.  The SS line can be seen to go high between each 16 bit word transfer.

The decoded data shown at the top, is the same as displayed on the MOSI and MISO lines below, it just saves counting the 0’s and 1’s and then calculating the hexadecimal value. From this it is easy to see the transmitted data values match, the values placed in the transmit FIFO by the code.  Also it can be seen that the second invalid control register data just instigates a transmit and receive sequence.  The data coming back from the slave are temperature values, which don’t mean a great deal in their present form, so some additional code is required to interpret and calculate the current temperature.

We know the temperature data is being sent in a 16 bit word, reading the datasheet especially the chapter titled ‘Temperature Sensor’ provides all the necessary information. Only the upper most 14 bits are valid temperature data, so the last 2 LSB can be discarded. The data is also sent in 2’s compliment format, this example does not go into negative values for the temperature, but this is good to know dependent on the temperature range being measured. Also the datasheet provides a temperature constant of 0.03125 degrees C, which equals 1 bit of the 14 bit number, so a simple multiplication is required.

3 variables are used to calculate the temperature sensor reading.

Firstly the raw 16 bit word is assigned to the unsigned int Raw_Value.  Looking back at the SPI timing diagram this value would be 0x0BF8 or 0000101111111000 in binary. We are however only interested in the 14 MSB, shown in bold.

This value is turned from a 16 bit word to a 14 bit word by shifting to the right by 2 places. After the binary value has been shifted it reads 00001011111110 or 766 in decimal.

The next step is to multiply the 14 bit raw value with the temperature constant for the ADS1118 temperature sensor.  Therefore 766 multiplied by 0.03125 equals 23.9375 degrees C.

Using Code Composer Studio v5.5 the next screen shot shows the data captured in the debug mode.  A breakpoint was set and adjusted to simply update the view, therefore the variables could be seen to change in real time.  The Raw_Value 767 is 3068 divided by 4 which is basically the operation the right shift is performs.

Stellaris ADS1118 Tutorial LM3S6965

Example Code

The link below contains the zip file with the complete C code, there is a small advert page first via Adfly, which can be skipped and just takes a few seconds, but helps me to pay towards the hosting of the website.

Stellaris ADS1118 SPI C code

I take great care when writing all the tutorials and articles, ensuring all the code is fully tested to avoid issues for my readers.  All this takes time and a great deal of work, so please support the site by using the Adfly links etc.  If you have found this useful or have any problems implementing, please feel free to leave a comment and I will do my best to help.

Doxygen tutorial banner

Eclipse Doxygen Installation

This is a quick tutorial on how to install Doxygen on a Windows 7 machine, running Doxygen with Eclipse or Code Composer Studio V5.x (CCS).  In the example I will be using CCS v5.4, but essentially this is the same for Eclipse.

Firstly download the latest version of Doxygen from here, at the time of writing this is version 1.8.5. I downloaded the doxygen-1.8.5-setup.exe and ran this to install Doxygen.

Eclipse Doxygen Installation

Once Doxygen is installed open Eclipse or CCS v5.x.  It’s important that the CCS version is 5 or above as older versions do not include the full Eclipse installation, so using all the plugins is not possible.

While CCS is opening a further program is required, which enables the Doxygen frontend to plugin to Eclipse. This program is called Eclox and can be found here .  You need to open this in a browser and scroll down the page looking for the link circled in the below image, then copy this link (will be used shortly).

Eclipse Doxygen Installation

With CCS open browse to the Help menu and select Install New Software from the drop down.

Eclipse Doxygen Installation

Once select the Install New Software tab will open up a new window shown below, select the Add button.

Eclipse Doxygen Installation

Then paste the Eclox link into the Location text bar, and click the OK button.

Eclipse Doxygen Installation

This will start a process as CCS checks the link, and when finished you should be presented with a window similar to below.  Ensure the tick box is ticked and press the Next button.

Eclipse Doxygen Installation

The next window is showing the software to be installed, clicking Next will contiune with the installation.

Eclipse Doxygen Installation

The next window is a chance to review the license.

Eclipse Doxygen Installation

You will then be presented with a security warning, as far as I am aware there are no issues with this software, but if you have any concerns then I suggest you refrain from continuing with the installation.

Eclipse Doxygen Installation

All that is needed after this is to restart CCS, you should then have a new icon shown in the drop down menu, as shown in the below image.

Eclipse Doxygen Installation

Your ready to start using Doxygen.  I intend to write some basic tutorials on the usage of Doxygen with C Programming code sometime soon when I have time.

I take great care when writing all the tutorials and articles, ensuring all the code is fully tested to avoid issues for my readers.  All this takes time and a great deal of work, so please support the site by using the Adfly links etc.  If you have found this useful or have any problems implementing, please feel free to leave a comment and I will do my best to help.