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.

Read DCO frequency

Prodigy 100 points

Replies: 22

Views: 13137

Hi guys

We are changing micro in our embedded systems MSP430F149 to MSP430F249. I have a function to read internal frequency of DCO oscillator and with this new micro dosen't work. No event capture happen if I have SMCLK with DCO. All it's ok if I use SMCLK with XT2CLK. Does anyone have any idea ?

This is my function.

//-----------------------------------------------------------------------------------------------
// GetDCOFreq
// Utilizza il TimerB e ACLK(32KHz) per misurare la frequenza del DCO (torna valore in Hz)
//-----------------------------------------------------------------------------------------------
LONG  MSP430_GetDCOFreq()
{
BYTE  SmclkFromXt2;
WORD  n1,n2;

    // Setta un flag se SMCLK è ricavato da XT2
    if (BCSCTL2 & SELS) SmclkFromXt2=1; else SmclkFromXt2=0;

    // Ricava il clock per SMCLK da DCO
    BCSCTL2 &= ~SELS;
    //BCSCTL2 |= SELS;

    // Accende TimerB: conteggio continuo a 16 bit, clock = SMCLK
    TBCTL = TBSSEL1 | MC1 | TBCLR;
    // Capture da CC16B=ACLK, rising edge
    TBCCTL6 = CM1 | CCIS0 | SCS | CAP;
    // Attende il primo evento di capture
    while ( (TBCCTL6 & CCIFG)==0 ) {};
    // Memorizza valore attuale
    n1 = TBCCR6;
    // Azzera flag di capture e overflow
    TBCCTL6 &= ~(COV|CCIFG);
    // Attende il prossimo evento di capture
    while ( (TBCCTL6 & CCIFG)==0 ) {};
    // Memorizza valore attuale
    n2 = TBCCR6;
    // Se si e' verificato un overflow azzera il valore, se no calcola la differenza
    if ( (TBCCTL6 & COV) != 0 ) n2=0; else n2=n2-n1;
    // Ferma il TimerB
    TBCTL = 0; TBCCTL6 = 0;
    // Ripristina il clock a SMCLK da XT2 se necessario
    if (SmclkFromXt2 != 0) BCSCTL2 |= SELS;
    // Ritorna il valore calcolato in KHertz
    return( (n2*32768L)/1000L );
}

22 Replies

  • Hi,

    looking into your code, it seems that you are using CCI6B as input capture. Unfortunatelly this is not available in MSP430F249

    This is the pin description of MSP430F249:

    P4.6/TB6 42 I/O       General-purpose digital I/O / Timer_B, capture: CCI6A input, compare: Out6 output

    While for MSP430F149:

    P4.6/TB6   42       I/O     General-purpose digital I/O pin/Timer_B, capture: CCI6A or CCI6B input, compare: Out6 output

    So try to change the  TBCCTL6 setting to TBCCTL6 = CM1 | SCS | CAP.

    I hope this helps you, otherwise please let me know.

    -Leo-

    Regards,

    Leo Hendrawan

  • In reply to Leo Hendrawan:

    Really thanks for the reply.

    It's possible to use Timer6 with input capture syncronized with internal ACLK ( not only for external pin... ), and I must use it to read my DCO frequency. ( SLAS547H page 23 for detail )

     

     

  • In reply to Kirk&gaard:

    Hi Kirkegaard,

    ah, sorry for have mistaken your problem. So where is the problem actually? Could you please describe what you meant with "this code doesn't work"? Does it return wrong value?

    -Leo-

    Regards,

    Leo Hendrawan

  • In reply to Leo Hendrawan:

    Don't worry Leo thanks so much for the support, I read your e-mail to Riccardo.

    "dosen't work" means that MSP430F249 micro is locked waiting first event capture.

    ...

    while ( (TBCCTL6 & CCIFG)==0 ) {}; <--- dead lock

    ...

    and there is nothing to do...

  • In reply to Kirk&gaard:

    Hi Kirkegaard,

    i tried to run your code using the following source:

    2671.main.c

    and it works fine. Here is the screencapture of the result:

    In your case, i suggest that the ACLK is failing. Could you please check whether ACLK runs properly? In the code above, i set the ACLK, MCLK, and SMCLK to be output from P5.4,5,6.

    I hope this helps, otherwise please let me know.

    -Leo-

    Regards,

    Leo Hendrawan

  • In reply to Leo Hendrawan:

    Ok Leo I suppose I found it. In your code you are using DCO as MCLK ? Only for debug can you set BCSCTL2 = SELM2 and use XT2 as MCLK..

    Thanks in Advance.....

     

     

  • In reply to Kirk&gaard:

    Hi Kirkegaard,

    yes, i use DCOa s MCLK. Unfortunately i have problem using XT2 on my hardware board so i can only use DCO.

    So does this solve the problem? Was my suggestion with the failing ACLK true?

    -Leo-

    Regards,

    Leo Hendrawan

  • In reply to Leo Hendrawan:

    Hi Leo

    My embedded system is locked using XT2 as MCLK. Before to call my function I must switch MCLK to DCO. ( like you ...  this is not good things... anyway ). This is what seems to happen . Can you find a board with XT2 ?

    ACLK it's ok anyway thanks for your helpful support...

     

     

     

     

  • In reply to Kirk&gaard:

    Hi Kirkegaard,

    i will try to get a board with working XT2 and modify the code to work with XT2. Could you also try to run my code above on your hardware and tell me the result whether it works or not?

    -Leo-

    Regards,

    Leo Hendrawan

  • In reply to Leo Hendrawan:

    sure ! the code it's ok...

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.