for example:
...
BCSCTL1 = CALBC1_8MHZ; // Set range DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation */
dosomething();
BCSCTL1 = CALBC1_16MHZ; // Set range DCOCTL = CALDCO_16MHZ;
DCOCTL = 0; // just in case CALDCO_8MHZ is much bigger than CALDCO_16MHz
Or you can order the DCOCTL assignment first
DCOCTL = CALDCO_16MHZ;
BCSCTL1 = CALBC1_16MHZ;
This way the DCO will not exceed the range defined by CALBC1_8MHZ as you switch to 16MHz.
Of course you then need to do the opposite as you lower the DCO frequency, but this can be easily implemented with two inline functions.
inline void SetDCO8MHz(void) { BCSCTL1 = CALBC1_8MHZ; //set range first DCOCTL = CALDCO_8MHZ; } inline void SetDCO16MHz(void) { DCOCTL = CALDCO_16MHZ; //set step/modulation first BCSCTL1 = CALBC1_16MHZ; }
Tony
TonyKaoOr you can order the DCOCTL assignment first
It is recommended to add a divider to MCLK before you do so. E.g. MCLK/4. This will ensure that the spike is only 1/4 of one MCLK cycle, so the one MCLK period during the switch is min. 1/3 of the target period, keeping you on the safe side. (or go for MCLK/8 when nearing the MSP maximum frequency).Keep in mind that you must not program the DCO for maximum MSP frequency, as DCO is an average frequency, some cycles higher, soem cycle slower than the target frequency. And the 'some cycles higher' may be too high.
_____________________________________Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.