Wednesday, July 30, 2014

UART communication on Tiva C Launchpad Microcontroller

Basics of UART: 
UART stands for Universal Asynchronous Receiver Transmitter. UART is used for serial communication between peripherals and other devices. UART takes bytes of data and transmits it through wire to another UART receiving end. UART device contains shift registers to convert parallel data into serial data and vice-versa. Data in UART is transferred serially as parallel transmission requires multiple wires. 
UART is asyncronous as no extra clock signal is required for synchronization. Synchronization is acheived by what is called as Baud Rate.




Monday, July 21, 2014

How to change System Clock Frequecy of Tiva C microcontroller Tutorial - using PLLs


Video Tutorial: How to change system clock of launchpad microcontroller using PLL and TivaWare
One of the very good feature of Tiva C microcontrollers are the full control over the operating frequency of the microcotrollers. We can set any frequency up to 80 MHz used Phase-Locked  Loop (PLL).  Clocking in Tiva C devices: Tiva C microcontrollers can be clocked from several sources
  • External Oscillator
  • Internal Oscillator (+/- 50%)
  • The main oscillator
  • Precision Internal Oscillator PISOC
The information about clock source tree could be found on page no. 220 of the datasheet.
The PLL can use any of these oscillator as its input but since the internal oscillator has a very large error generally it is not preferred for input. 
The PLL could be programmed from the Tiva Ware library very easily if you get started with tiva ware please see my another blog post : http://tivaclaunchpad.blogspot.com/2014/07/new-ccs-5-project-with-tivaware-c.html
The driver is contained in driverlib/sysctl.c, with driverlib/sysctl.h containg the API definitions. Changing Frequency: Let us first check the normal system clock frequency when the system boots up normally without using any PLL. Code is shown below:
 The first three lines of code include the important header files. I initialized a variable called clock_speed. uint32_t SysCtlClockGet(void) function: This function returns the system clock frequency so we get that and save it to clock_speed variable. Lets,  now  build and debug the code and see what's the frequency is    as you can see that the current operating frequency is 16 MHz. The frequency of the system clock could be set by use of function in Tiva Ware library SysCtlClockSet(unit32_t config) fucntion. This function configures the clocking of the system, the input crystal frequency, use of the PLL, oscillator to be used and the system clock divider SYS_DIV field. config parameter is the logical OR of many different values which are group into the set.Different values are as shown in the figure below:
  • The system clock divider is chosen with one of the following values: SYSCTL_SYSDIV_1,
    SYSCTL_SYSDIV_2, SYSCTL_SYSDIV_3, ... SYSCTL_SYSDIV_64.
  • The use of the PLL is chosen with either SYSCTL_USE_PLL or SYSCTL_USE_OSC. 
  • The external crystal frequency is chosen with one of the following values:
    SYSCTL_XTAL_4MHZ, SYSCTL_XTAL_4_09MHZ, SYSCTL_XTAL_4_91MHZ,
    SYSCTL_XTAL_5MHZ, SYSCTL_XTAL_5_12MHZ, SYSCTL_XTAL_6MHZ,
    SYSCTL_XTAL_6_14MHZ, SYSCTL_XTAL_7_37MHZ, SYSCTL_XTAL_8MHZ,
    SYSCTL_XTAL_8_19MHZ, SYSCTL_XTAL_10MHZ, SYSCTL_XTAL_12MHZ,
    SYSCTL_XTAL_12_2MHZ, SYSCTL_XTAL_13_5MHZ, SYSCTL_XTAL_14_3MHZ,
    SYSCTL_XTAL_16MHZ, SYSCTL_XTAL_16_3MHZ, SYSCTL_XTAL_18MHZ,
    SYSCTL_XTAL_20MHZ, SYSCTL_XTAL_24MHZ, or SYSCTL_XTAL_25MHz.
    Values
    below SYSCTL_XTAL_5MHZ are not valid when the PLL is in operation.  
  • The oscillator source is chosen with one of the following values: SYSCTL_OSC_MAIN,
    SYSCTL_OSC_INT, SYSCTL_OSC_INT4, SYSCTL_OSC_INT30, or SYSCTL_OSC_EXT32.
    SYSCTL_OSC_EXT32 is only available on devices with the hibernate module, and then only when the hibernate module has been enabled.
Programming of PLL is shown below :   Different System Clock Divider values for different clock frequencies could be found from datasheet.
  
Lets now compile and Debug our code and see what is the new frequency after turning on the PLL

As you can see the clock speed is now changed to 80 MHz. So the PLL on Tiva C Launchpad provide the flexibility of changing the system clock frequency based on our need which is a great feature added in Tiva microcontrollers for real time execution.
Any comment to improve the article will be highly appreciated.

    Thursday, July 17, 2014

    Blink Led Project in CCS 5 with TivaWare C library for Tiva-C Launchpad Microcontrollers

    TivaWare Library:
    TivaWare Peripheral Driver Library is an extensive C library for accessing the peripherals on Tiva C launchpad microcontrolller. This library makes it easy to use the device peripherals without knowing a lot about the internal registers. So, it is helpful as you don't need to look at the datasheet and bit banging for programming a simple application like blinking an led.
    TivaWare Library can be downloaded from here: http://www.ti.com/tool/sw-tm4c 

    Complete TivaWare Library includes:

    • Royalty free libraries(Peripheral, USB, Graphics , Sensor)
    • Kit and peripheral specific code
    • Release note and other documentation
    Documentation for TivaWare Library could be downloaded from here: http://www.ti.com/lit/pdf/spmu298

    Code Composer Studio is and Integrated development environment that supports Texas Instruments Microcontrolllers and Processors. CCS could e downloaded freely from here: http://www.ti.com/tool/ccstudio

    How to build and debug a new project in CCS with TivaWare C library:
    1. Open Code Composer Studio. 
    2. Click on the New -> CCS Project.

    3. Give a Project Name, Select Family -> ARM, Variant -> Tiva TM4C123GH6PM, Connection -> Stellaris ICDI then click on Finish.

    Now for Adding the TivaWare Library in your newly created project 
    1. Right Click on your Project and then goto Properties. A properties window will open like the shown below
    1.  
    2. Then goto Build -> ARM Compiler -> Include Options in the list Add dir to #include search path click on Add.

    3. A Add directory path dialog box will open. Click on File System , Browse to TivaWare installed location (by default it go to C:\ti\TivaWare_C_Series_version_no.) Click on Ok and then again OK.

    4. Now go to ARM Linker option, then File Search Path. Click on Add -> File System and then search for driverlib.lib in your installedLibraryPath\driverlib\ccs\debug\driverlib.lib , then Click on OK.

       
    5. If you don't do this linker step the you will get a linking error.

    Compiling and Debugging the Code:

    • In this tutorial i will be compiling a simple blinking code given below. For Compiling and Debugging your Code. Right Click on Project then Click on Build Project.

       
    • After compiling and building has been finished . Click on Run -> Debug to start debugging of your program. Tiva C lets you debug your code while running it on real hardware so that you can know whats going on inside.



    Debugger on Tiva C Launchpad is very helpful in finding small bugs as we can see full registers value and memory location. And Here is my Blinking LED on Tiva C Launchpad.


    Thank you , comments to improve this article will be appreciated.

    Tuesday, July 15, 2014

    Arduino vs. TI's TM4C123 Launchpad Board

    Hi,
    If you are wondering which micro controller board you should use for your next hobby project you may be confused between which boards to use Arduino or TI's Launchpad. If you are a beginner then of course arduino will be the best choice as it is easy to program and use while Ti's Launchpad  boards provide better flexibility and power which could be used in your project.


    First of all, lets take a look at the specification of both boards and then i will describe about the pros and cons about both boards.
      

    Arduino Uno R3
    • ATMEGA328 Micro controller , 16 MHz clock speed
    • Number of Digital IO - 20
    • Flash Memory - 32 KB
    • SRAM - 2 KB , EEPROM 1-KB
    • 1 SPI,1 I2C, 1 UART
    • 6 PWM
    • 6 ADCs etc.

     TI's TM4C123G Launchpad  Board
    • Based on ARM Cortex M4 Microcontroller, 80MHz clock  speed
    • Flash Memory - 256 KB , SRAM - 32KB , EEPROM - 2KB
    • 46 GPIOs , 8 UARTs , 4 SPIs, 4 I2C
    • 2 CAN controllers, USB Host/Device/OTG
    • 16 PWM outputs , 2 Quadrature Encoder Module for advanced motion control
    • ADCs , Analog Comparators and DMA controller etc.
    Now lets compare both,
    Pros of Arduino :
    • Easier to Program
    • Simple functions like digital read and write and Libraries from Arduino
    • A very good community support
    Cons of Arduino:
    • Lower clock speed as compared to launchpad and also no control over the clock speed.
    • Lesser memory , GPIO and peripherals
    • no USB
    Pros of TI's launcpad:
    • 32-bit ARM based architecture, faster speed and control over the clock speed of the uC
    • More GPIOs and peripherals to play with.
    • Much larger memory and RAM
    • USB and CAN are extra
    •  Sleep mode support for saving power when system remain idle
    • TivaWare C - Extensive C library for programming microcontroller by TI 
    Cons of Launcpad:
    • Programming requires knowledge about registers and interal working of microcontroller
    • Community support is not there but the product has good documentation