MSP430G2553的时钟设置简析

MSP430G2553的时钟设置简析_第1张图片

基本时钟系统的寄存器

DCOCTL-DCO控制寄存器



DCOx

    DCO频率选择控制1

MODx

DCO频率校正选择,通常令MODx=0



注意:在MSP430G2553上电复位后,默认RSEL=7DCO=3,通过数据手册查得DCO频率大概在0.8~1.5MHz之间。

BCSCTL1-基本时钟控制寄存器1


XT2OFF

    不用管,因为MSP430G2553内部没有XT2提供的HF时钟

XTS

    不用管,默认复位后的0值即可

DIVAx

设置ACLK的分频数

00          /1

01          /2

10          /4

11           /8

RSELx

    DCO频率选择控制2

 

BCSCTL2-基本时钟控制寄存器2


SELMx

MCLK的选择控制位

00          DCOCLK

01          DCOCLK

10          LFXT1CLK或者VLOCLK

11           LFXT1CLK或者VLOCLK

DIVMx

设置MCLK的分频数

00          /1

01          /2

10          /4

11           /8

SELS

    SMCLK的选择控制位

    0            DCOCLK

    1            LFXT1CLK或者VLOCLK

DIVSx

设置SMCLK的分频数

00          /1

01          /2

10          /4

11           /8

DCOR

    DCO直流发生电阻选择,此位一般设0

0            内部电阻

    1            外部电阻


BCSCTL3-基本时钟控制寄存器3


XT2Sx

    不用管

 

LFXT1Sx

00          LFXT1选为32.768KHz晶振

01          保留

10          VLOCLK

11           外部数字时钟源

XCAPx

    LFXT1晶振谐振电容选择

00          1pF

01          6pF

10          10pF

11           12.5pF

 

msp430g2553.h中基本时钟系统的内容

/************************************************************

* Basic Clock Module

************************************************************/

#define __MSP430_HAS_BC2__                   /* Definition to show that Module is available */

 

SFR_8BIT(DCOCTL);                             /* DCO Clock Frequency Control */

SFR_8BIT(BCSCTL1);                            /* Basic Clock System Control 1 */

SFR_8BIT(BCSCTL2);                            /* Basic Clock System Control 2 */

SFR_8BIT(BCSCTL3);                            /* Basic Clock System Control 3 */

 

#define MOD0                   (0x01)        /* Modulation Bit 0 */

#define MOD1                  (0x02)        /* Modulation Bit 1 */

#define MOD2                  (0x04)        /* Modulation Bit 2 */

#define MOD3                  (0x08)        /* Modulation Bit 3 */

#define MOD4                  (0x10)        /* Modulation Bit 4 */

#define DCO0                  (0x20)        /* DCO Select Bit 0 */

#define DCO1                  (0x40)        /* DCO Select Bit 1 */

#define DCO2                  (0x80)         /* DCOSelect Bit 2 */

 

#define RSEL0                 (0x01)        /* Range Select Bit 0 */

#define RSEL1                 (0x02)        /* Range Select Bit 1 */

#define RSEL2                 (0x04)        /* Range Select Bit 2 */

#define RSEL3                  (0x08)        /* Range Select Bit 3 */

#define DIVA0                 (0x10)        /* ACLK Divider 0 */

#define DIVA1                 (0x20)        /* ACLK Divider 1 */

#define XTS                   (0x40)        /* LFXTCLK 0:Low Freq. / 1: High Freq. */

#define XT2OFF                (0x80)        /* Enable XT2CLK */

 

#define DIVA_0                (0x00)        /* ACLK Divider 0: /1 */

#define DIVA_1                (0x10)        /* ACLK Divider 1: /2 */

#define DIVA_2                 (0x20)        /* ACLK Divider 2: /4 */

#define DIVA_3                (0x30)        /* ACLK Divider 3: /8 */

 

#define DIVS0                 (0x02)        /* SMCLK Divider 0 */

#define DIVS1                 (0x04)        /* SMCLK Divider 1 */

#define SELS                  (0x08)        /* SMCLK Source Select 0:DCOCLK / 1:XT2CLK/LFXTCLK */

#define DIVM0                 (0x10)        /* MCLK Divider 0 */

#define DIVM1                 (0x20)        /* MCLK Divider 1 */

#define SELM0                  (0x40)        /* MCLK Source Select 0 */

#define SELM1                 (0x80)        /* MCLK Source Select 1 */

 

#define DIVS_0                (0x00)        /* SMCLK Divider 0: /1 */

#define DIVS_1                (0x02)        /* SMCLK Divider 1: /2 */

#define DIVS_2                (0x04)        /* SMCLK Divider 2: /4 */

#define DIVS_3                (0x06)        /* SMCLK Divider 3: /8 */

 

#define DIVM_0                (0x00)        /* MCLK Divider 0: /1 */

#define DIVM_1                (0x10)        /* MCLK Divider 1: /2 */

#define DIVM_2                (0x20)        /* MCLK Divider 2: /4 */

#define DIVM_3                (0x30)        /* MCLK Divider 3: /8 */

 

#define SELM_0                (0x00)        /* MCLK Source Select 0: DCOCLK */

#define SELM_1                (0x40)        /* MCLK Source Select 1: DCOCLK */

#define SELM_2                (0x80)        /* MCLK Source Select 2: XT2CLK/LFXTCLK */

#define SELM_3                (0xC0)        /* MCLK Source Select 3: LFXTCLK */

 

#define LFXT1OF               (0x01)        /* Low/high Frequency Oscillator Fault Flag */

#define XT2OF                 (0x02)        /* High frequency oscillator 2 fault flag */

#define XCAP0                 (0x04)        /* XIN/XOUT Cap 0 */

#define XCAP1                 (0x08)        /* XIN/XOUT Cap 1 */

#define LFXT1S0               (0x10)        /* Mode 0 for LFXT1 (XTS = 0) */

#define LFXT1S1               (0x20)        /* Mode 1 for LFXT1 (XTS = 0) */

#define XT2S0                 (0x40)        /* Mode 0 for XT2 */

#define XT2S1                 (0x80)        /* Mode 1 for XT2 */

 

#define XCAP_0                (0x00)        /* XIN/XOUT Cap : 0 pF */

#define XCAP_1                (0x04)        /* XIN/XOUT Cap : 6 pF */

#define XCAP_2                (0x08)        /* XIN/XOUT Cap : 10 pF */

#define XCAP_3                (0x0C)        /* XIN/XOUT Cap : 12.5 pF */

 

#define LFXT1S_0              (0x00)        /* Mode 0 for LFXT1 : Normaloperation */

#define LFXT1S_1               (0x10)        /* Mode 1 for LFXT1 : Reserved */

#define LFXT1S_2              (0x20)        /* Mode 2 for LFXT1 : VLO */

#define LFXT1S_3              (0x30)        /* Mode 3 for LFXT1 : Digital input signal */

 

#define XT2S_0                (0x00)        /* Mode 0 for XT2 : 0.4 - 1 MHz */

#define XT2S_1                (0x40)        /* Mode 1 for XT2 : 1 - 4 MHz */

#define XT2S_2                (0x80)        /* Mode 2 for XT2 : 2 - 16 MHz */

#define XT2S_3                (0xC0)        /* Mode 3 for XT2 : Digital input signal */

 

基本时钟系统例程(DCO)

    MSP430G2553在上电之后默认CPU执行程序的时钟MCLK来自于DCO时钟。TI提供的Launch Pad上,P1.0和P1.6分别接了红色和绿色的LED灯,下面写一个程序让它们交替闪烁;之后我们来改变DCO的频率,进而使软延时时间变化,可以看到LED闪烁间隔有变化。

#include "msp430g2553.h"

void main(void)

{

    WDTCTL = WDTPW + WDTHOLD;

    P1DIR |= BIT0 + BIT6;

    while(1)

    {

       P1OUT ^= BIT0 + BIT6;

       __delay_cycles(100000);

    }

}

这段程序采用430上电后默认的DCO频率,假设是1MHz的话,则延时100000个DCO提供的MCLK大概是0.1s左右。

下面一段程序,将DCOx设置为1,RSELx设置为1,通过数据手册查得DCO频率大概在0.06~0.14MHz之间,所以明显MCLK要慢得多了,因此LED闪烁时间延长。

 

 

 

#include "msp430g2553.h"

void main(void)

{

    WDTCTL = WDTPW + WDTHOLD;

   DCOCTL |= DCO0;

    DCOCTL &=~(DCO1 + DCO2);

    BCSCTL1 |= RSEL0;

    BCSCTL1 &=~ (RSEL1 + RSEL2 + RSEL3);

    P1DIR |= BIT0 + BIT6;

    while(1)

    {

       P1OUT ^= BIT0 + BIT6;

       __delay_cycles(100000);

    }

}

 



你可能感兴趣的:(MSP430)