This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2553 DCO clock totally inaccurate - ~1 MHz instead of 8Mhz

Other Parts Discussed in Thread: MSP430G2553

Hi there,

I have a hard time getting the MSP430G2553 DCO clock to work. Here is what my initialization code looks like:

if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)
{
while(1); // If cal constants erased, trap CPU!!
}
__delay_cycles(10000);

/* DCO 13, 3 = 7.8 Mhz */

BCSCTL1 &= ~BIT1;
BCSCTL1 |= BIT3 + BIT2 + BIT0;
DCOCTL &= ~BIT7;
DCOCTL |= BIT6 + BIT5;

BCSCTL2 = 0;
BCSCTL3 = 0;

Instead of 7.8 Mhz (as written in datasheet), I'm getting approximately 1 Mhz. Of course, I also tried the precalibrated settings of DCO, but with no success. Have any of you come across something like this?

  • Michal,

    How did you measure it?
    Can you show the whole program?
    Please use the syntax highlighter in rich text formatting when posting code.

    Dennis
  • I just let one of the pins toggling in a while loop, and I measured it with oscilloscope. Here is the whole code:

    static void Clock_Init(void);
    void Port_Create (void);
    
    int main(void)
    {
    WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
    
    Clock_Init();
    Port_Create();
    __enable_interrupt(); // enable maskable interrupts
    
    LED_GREEN_OFF;
    LED_RED_OFF;
    
    /* should never return */
    while(1U)
    {
    P2OUT ^= BIT1;
    }
    }
    
    static void Clock_Init(void)
    {
    if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
    {
    while(1); // If cal constants erased, trap CPU!!
    }
    __delay_cycles(10000);
    BCSCTL1 &= ~BIT1;
    BCSCTL1 |= BIT3 + BIT2 + BIT0;
    DCOCTL &= ~BIT7;
    DCOCTL |= BIT6 + BIT5;
    
    BCSCTL2 = 0;
    BCSCTL3 = 0;
    
    }
    
    void Port_Create (void)
    {
    P1DIR &= ~BIT3; // Input : ADC
    P2DIR |= BIT0 | BIT1 | BIT5; // Output : LED_RED, LED_GREEN, PWM_LED
    P3DIR |= BIT5; // Output : PWM_FAN
    P3DIR &= ~BIT6; // Input : FAN_TACH
    P2DIR &= ~BIT4; // Input : DALI_RX
    P2DIR |= BIT3; // Output : DALI_TX
    }

  • Michal,

    that is not the way you can measure your clock frequency. Toggling a pin takes more than one CPU cycle, so your pin will not toggle at the same frequency your processor is running. You have to lead the clock out of your processor to one of the portpins. This is a special function. Look at P1.4 of the MSP430G2553 - one of it's special functions is SMCLK. If you enable it the processor will output the buffered SMCLK on that pin. Try the following code and measure the frequency at P1.4 of the device.

    #include "msp430g2553.h"
    
    void main( void )
    {
      WDTCTL  = WDTPW | WDTHOLD; // Stop watchdog timer
      
      BCSCTL1 = CALBC1_8MHZ;     // Set range to 8MHz
      DCOCTL  = CALDCO_8MHZ;     // Set DCO step and modulation to 8MHz
    
      P1SEL |= 0x10;             // Enable special function for P1.4 - SMCLK
      P1OUT |= 0x10;             // Set P1.4 to output direction
    
      while( 1 )
      {
      }
    }

    Dennis

  • Yes, I know about this feature.
    Anyway, I started digging in the clock module because I had problems with communication with temperature sensor DS18B20 (using 1-wire interface). I couldn't get it to work, because the timing was off (as I found out using oscilloscope). I'm using common __delay_cycles() function for my delay function. Also when I tried to toggle some pin every 100 us (in a while loop of main function), it took something around 170 us to toggle.
  • You should now first try if you get your clock at the frequency you are expecting.
  • Dennise, your lines #5 & #6 are no where to be found in his 47 lines.
  • That is correct, but he wrote he tried the calibrated frequencies as well and he also told, that they did not work, either - so I would recommend to start from there and see if the clock works as expected in general.

**Attention** This is a public forum