msp430 embedded c programming part2 - configuring DCO


Introduction :

MSP430 Clock system has three clocks which provides different frequencies . Need of three different clocks not only one is power consumption. That is we will use the clock with lowest frequency when we want to save the power and we will use the clock with highest frequency when we want high speed.

The three clocks present in MSP430 are
1. MCLK(Master Clock) : Used by CPU and few peripherals such as ADC. It is  a high frequency clock but can be configured to provide a low frequency

2.SMCLK(Sub-Main CLock) : Distributed to Peripherals. It can be the same frequency as MCLK,or different depending on the application

3. ACLK(Auxiliary CLock) : Basically it is a low frequency clock, used for peripherals.

There are four Sources for these clocks

1.LFXTCLK: As the name implies it is to use with low frequency crystal.A 32khz can be connected to msp430 for low power operation

2 XT2CLK:  This is not available in every device.it is to use with a second crystal

3.DCOCLK: It is internal source and it is a digitally controlled oscillator.It can be operated at a wide range of frequencies.


4. VCOCLK: Second oscillator for very low power and very low frequency applications.

MCLK,SMCLK can use any of these clock sources,whereas ACLK can use either VCOCLK,LFXTCLK.

Basically MCLK,SMCLK are sourced from DCO.
As DCO is internal clock source ,we will see how to program it and what are the registers used for  programming it.

Two registers are used for configuring DCO:BCSCTL1,DCOCTL.

The DCO Frequency range is divided into 128 unique frequencies whose values depends on the RSELx and DCO bits


To know what is the RSELx and DCOx for  a particular frequency we have to see the device specific datasheet,eg:msp430f2618 datasheet.


Suppose now we want to set the frequency to 8.60 frequency we have to write RSELx to 14 and DCOx to 3.

Code:



/**

Setting the MCLK frequency to 8.6 Mhz

**/

//step1 : include the header file

#include<msp430f2618.h>

int main(void){

//stop the watchdog timer

WDTCTL= WDTPW+WDTHOLD;

//setting the frequency, we have to use DCOCTL,BCSCTL1 registers

BCSCTL1 |= (1<<RSEL3)|(1<<RSEL2)|(1<<RSEL1)  ;

DCOCTL = DCO1| DCO0;


P5DIR = 0x20; //port 5.5 as output on which led is connected


return 0;


}





Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto