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.

    No comments:

    Post a Comment