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.

MSP430 Clock Module

Other Parts Discussed in Thread: MSP430G2121

Hello,

May I know how to set the clock module of MSP430 to 6MHZ?

Thanks,

Joy

  • Hi Joy,

    In order to get help, please provide more informations.

    Which device are you using? you should mention it, since MSP430 families have different clock modules.

    Which clock source (ACLK, MCLK, or SMCLK) do you want to source with the 6MHz clock? The reason is that for example in 1xx, you can only source ACLK from LFT1CLK, so the only option in this case is to use an external 6 MHz oscillator and set the LFXT1 to work with high frequency oscillator.

  • The easiest way with the best results is to attach a 6MHz quartz crystal or provide a digital 6MHz signal from an external oscillator.

    getting reliable (accurate and stable) 6MHz with the built-in DCO (digitally controlled oscillator) is more complicated and requires some software one the newest and even more on the older MSPs. And highly depends on the device you want to use.

  • Dear Jens-Michael,

    Thank you for your replied.

    I am using MSP430G2121. According to specification it can be configure to 6MHz at the software side.

    Will you be able to advise what are the setting that I need to change?

    I will like to know the complexity and weight from there which are the easier way.

    thank you so much,

    Joy

  • Joy Tan said:
    According to specification it can be configure to 6MHz at the software side.

    Yes, it can. That's right.

    Joy Tan said:
    Will you be able to advise what are the setting that I need to change?

    No. Not because I don't want, but because nobody can.

    The problem is that the DCO (digitally controlled oscillator) output frequency differs largely across individual devices. The DCO is designed for flexibility on low power consumption. It is not designed for precision. So a settign that results in exatcly 6MHz on one device, can result in 5MHz or 7MHz on a different device of the same brand. Even across devices of the same wafer, the output frequency of a particular configuration will be different.
    Also, the DCO output frequency has a large temperature coefficient too.
    And last but not least, there is only a handful of frequencies you can produce with the DCO. There are 16 different frequency ranges which partly overlap. After selecting one of these, the DCO can only output one of 8 discrete frequencies, equally distributed across the selected range.

    To allow more than these 128 discrete frequencies (which may contain doubles too, even if not very likely), the DCO can be modulated to switch between two adjacend output frequencies with a certain pattern. There are 32 pattern available, so the resulting average frequency is in the middle of two discrete DCO outputs. THis is, however, only an average frequency. And still there is no guarantee that your desired frequency is exactly what you want.

    But if you only want roughly 6MHz, maybe less or more, then check the datasheet for the proper RSEL range and try soem settings until you find the best. The MSP should be able to output the resulting DCO frequency (actually the SMCLK or MCLK signal that is derived from the DCO) to one of its I/O pins, so you can compare the result using an external oscilloscope or a counter/timer.

    One alternative way is to apply an external low frequency (such as a 1kHz signal), and count the DCO clock ticks during this period, adjusting the DCO until the outcome is exaclty (or as exact as possible) 6000:1. Then write the current configuration into the info memory and use it in future.
    Many MSP devices of the F series do have these calibraiton values already written to the info memory for 1MHz and maybe 4/8/16MHz. Teh 5x family has an FLL module that does this calibration process in hardware during program execution. Usually based on an external 32768Hz crystal.

    The G series (low-cost) devices have none of them, so you'll have to do it yourself.

    In a different thread not too old (1 or two weeks) someone posted code that exactly does that: adjust the DCO in comparison to an external clock signal and store the best choice fo rthe DCO registers.

     

  •  

    I agree.  There are too many variables (manufacturing differences, temperature, voltage,...) to give the correct parameters.

    However, this should be a good starting point:

    #define TYPDCO_6MHZ ((3<<5)|14)
    #define TYPBC1_6MHZ  12

    int main()
    {
        // Stop watchdog timer to prevent time out reset
        WDTCTL = WDTPW | WDTHOLD;

        // Set clock frequencies

        // MCLK = 16 MHz (about); SMCLK=MCLK
        DCOCTL = TYPDCO_6MHZ;
        BCSCTL1 = TYPBC1_6MHZ;
        BCSCTL2 = 0;

        // ACLK = VLO @ 12 kHz
        BCSCTL3 = LFXT1S_2;

    ...

    }

  • Peter Fry said:
    However, this should be a good starting point:[...]


    Well, for an approximate target frequency this would be sufficient. In fact, I used somethign similar for the 1232 and 1611, as emergency fallback when the crystal was not starting. But even if using values derived from calibrating a handful of MSPs of the same type, the result was not good enough to get an 38.4k serial connection to the PC. It was, however, sufficient for a 9600Bd connection in the very most cases.

    However, the FLL controlled DCO in the 54xx series, stabilized with the internal REFO, seems good enough for a mostly stable 115.2k serial connection.

    Peter Fry said:
    // ACLK = VLO @ 12 kHz

    That's a very optimistic assumption :) The VLO is even less stable or predictable than the DCO. Much less. 'some kHz' would be the best description. It's sometimes useful anyway.

  • Dear Jens,

    Thanks for the advise and reply. Will apply the method of apply low freq.

    Thanks,Joy

**Attention** This is a public forum