NPEDUCATIONS, Electronic circuits development, electronics tutorials, microcontroller tutorials and projects, advanced microcontroller (ARM) based tutorials and projects, Embedded c development, Embedded c for ARM cortex M, Intel IoT based projects, IoT projects, CC3200 launch pad projects, MSP430 Launchpad tutorials and projects, Tiva C launch pad tutorials and projects, 8051 tutorials and projects, sensor interfacing with microcontroller tutorials, data communications and networking tutorials, peripheral interfacing with microcontroller, led message scrolling display, arduino based tutorials and projects, intel galileo based tutorials and project, ADC interfacing tutorials, LED Blinking, LCD interfacing, Embedded System tutorials and projects, projects, projects, online Embedded C training

Understanding of Basic Clock System in MSP430 Launch pad

A clock system is a heart of microcontroller. If we know the functioning of this heart system then it is easier to study remaining modules (like Timers, communication interface, etc.,) of the microcontroller. You people may have an idea about the clock system in 8051 and other microcontrollers, off course they are simple and easy to configure. But in MSP430 there is a highly sophisticated and accurate clock generation system is available. This clock system makes the CPU (of MSP430) may operate in different  speeds  and also helps to reduce the power consumption of it by operating in different low power modes. The aim of this tutorial is to make the clock system as simple as that easily understandable for the beginners.
Basically the MSP430 device contains four clock sources (oscillators) that are used to generate three different clock signals. Because the MSP430 classifies the peripherals into two categories (slow and fast) based upon their operating speeds. This categorization of peripherals is mainly to reduce the power consumption of CPU and the peripherals, i.e., high frequency operations require more power that compared with low frequency.

MSP430G2553 Clock Sources:
·         XT2CLK (optional) – HIGH FREQUENCY OSCILLATOR.

MSP430G2553 Clock signals:
·         ACLK  –    for Slow Peripherals.
·         MCLK  --  to CPU and few peripherals.
·         SMCLK -- for Fast Peripherals.


·         VLO: Very low power – low frequency oscillator. It is especially for to generate low frequency signals and comes as internal feature to MSP430. It provides a frequency of 12KHz without any need of external crystal. It provides 500nA as stand by current.

·          LFXT1:  Low frequency or High frequency oscillator. This is operated in two modes.
o   Low Frequency (LF) mode – (XTS = 0) – 32768KHz.
o   High Frequency (HF) mode – (XTS = 1) – 400KHz – 16MHz.
o   There is an in-built OSC-Fault mechanism available in MSP430. If OSC – fails to work then it switches to alternate clock source available in the device.
o   The frequency can change by the changing the programmable capacitors present internally in the MSP430.

·    DCO: Digital Controlled Oscillator – It generates a frequency range from 1MHz – 16MHz. generally beginners may like this, because it’s easy configure than compared to other.

·         XT2: it is an optional high frequency oscillator similar to LFXT1 in HF mode. The frequency range is 400 KHz – 16MHz.  Generally some device these optional clock sources

You can use any one of the oscillator to generate the three different clock sources based on the power and speed requirement.
·         ACLK – used for slower devices and it can generate from one of either two clock sources (LFXT1 or VLO).
·         MCLK – used for CPU and some peripherals. It can generate from either DCO or VLO or Low/High frequency crystals. Hence a mux is used to multiplex both oscillators as shown in the figure 1.1.
·         SMCLK – used for High speed peripherals and it can generate from DCO oscillator only.

·     Up on reset, MCLK and SMCLK are source from 1.1MHz DCO clock source. And ACLK is sourced from LFXT1 oscillator in LF mode with 6pF load capacitance.
·         If LFXT1 fails, then the ACLK is source from the VLO oscillator as shown in the figure 1.1.
·    Clock speed should match with the required operating VCC to achieve the very lower power possible otherwise unreliable execution results if Vcc < the minimum required value for the selected frequency.

Coming to the MSP430 programming, there are three special Basic Clock Control registers are available to configure the different clocks to different modules in the MSP430 microcontroller.


·         BCSCTL1 – Used to ACLK frequency select (DIVAx bits) and LFXT1 mode select (LF and HF).
·         BCSCTL2 – Used to select MCLK and SMCLK sources (either DCO or LFXT1 or VLO).
      And also provides frequency range selection bits for MCLK (DIVMx bits) and SMCLK (DIVSx bits).
·         BCSCTL3 – used to select LFXT1 oscillator frequency range.
·         DCOCTL – DCO control register – used to select DCO frequency (1MHz, 4MHz, 8MHz, and 16MHz).

Status register contains some control bits (SCG0, SCG1, OSCOFF, and CPUOFF) used to enable or disable some portions of the Basic clock module and also used to configure the MSP430 operating modes.

C Program to generate 1 sec delay using low frequency oscillator (VLO). Here in this program LED blinks for every one second and also we can see the lowest frequency of operation. This can be achieved by taking the VLO oscillator which is the very low frequency oscillation (~12KHz) and divide it with maximum dividend which is 8 in this context.

Step 1: Stop the watch dog timer, to avoid unnecessary resets of the microcontroller. 
            We will discuss more on watch dog timer later
                WDTCTL = WDTPW + WDTHOLD; // stop watch dog timer

Step 2: Select the VLO as clock source.
                BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO, check out theMSP430x2xx family 
                                                         // user  guide page number 290.

Step 3: In the basic clock system by default OFIFG (oscillator-fault flag) bit is set and force the 
           MCLK to use DCO as its source. But our intension is to make the MCLK should use VLO 
           as its source. So we need to clear the OFIFG bit.
                IFG1 &= ~OFIFG;                           // Clear OSCFault flag

Step 4: The OSC_Fault flag takes 50 milliseconds to react, so single instruction is enough to produce 
            that delay since the clock speed is 12KHz. That single instruction is used to block the DCO 
            source for MCLK. It is better to disable the DCOCLK and this can be done by setting the  
            bits ‘SCG0’ and ‘SCG1’ in the status register.
__bis_SR_register(SCG1 + SCG0);  // Stop DCO clock and this ‘__’ indicates that                                                      
                                                     // this instruction is an assembly level call from c language.

                Step 5: Now source the MCLK with the VLO oscillator and divide the value by 8 why because 
                            here we are trying to achieve the lowest frequency of operation in MSP430 (~ 1.5KHz)
                                BCSCTL2 |= SELM_3 + DIVM_3;               // MCLK = LFXT1/8 = VLO/8

   Step 6: Make port1 bit 0 as output, which is connected to RED LED on the LAUNCH PAD 
               board. This can be done by placing 1 on direction register (P1DIR)
                P1DIR = 0x01; // (output – 1, input – 0)

    Step 7: place zero on the P1.0 pin, to make output zero.
                P1OUT = 0x00; // all port1 pins are at logic low.

     Step 8: Blinking LED code using _delay_cycles() functions, this function produces delay equal to 
               that the number passed to that function. For example, if the operating clock frequency is 
               1MHz then _delay_cycles(1) produce 1microsecond delay. Likewise _delay_cycles(10) 
               produce 10 microseconds. In this program, we are operating with 1.5KHz, hence one 
               _delay_cycles(1) may take (1/1.5KHz = 0.666 milliseconds) Here one question arises that   
            how many delay cycles that are needed to produce 1 second with our clock source. Answer 
             is 1500 (1/0.66m = 1500).

P1OUT = 0X01;
P1OUT = 0X00;



void main(void)
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  BCSCTL3 |= LFXT1S_2;                      // LFXT1 = VLO
  IFG1 &= ~OFIFG;                           // Clear OSCFault flag
  __bis_SR_register(SCG1 + SCG0);           // Stop DCO and to wait 50 milliseconds
  BCSCTL2 |= SELM_3 + DIVM_3;               // MCLK = LFXT1/8
  P1DIR = 0x01                              // make P1.0 as output and remaing all are output
  P1OUT = 0x00;                             // All P1.x reset
  for (;;)
    P1OUT |= 0x01;                          // P1.0 set
    P1OUT &= ~0x01;                         // P1.0 reset



  1. nice one, but your code markup is messed up

  2. Best one for learning Clock System, But why image is not visible.


Thanks for visiting NPEDUCATIONS. We will contact you soon


Anonymous said...

nice one, but your code markup is messed up

Lovakiranvarma Myla said...

I will repair it! thank you

Mallappa T said...

Best one for learning Clock System, But why image is not visible.

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

If you really like this tutorial, Don't forget to give the comment or please subscribe to the RSS feed by submitting your E-mail or like our Facebook page.
Related Posts Plugin for WordPress, Blogger...

Powered by Blogger