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.

Correct way to calibrate OSC

Guru 18595 points
Other Parts Discussed in Thread: MSP430F2350

Hi guys,

let me ask for some help here. I've read in the forums the DCO in the MSP430F2350 (sorry, I usually work with 8051) may have a frequency from 0.4MHz to 2MHz depending on several factors as the voltage and the temperature when starting.

I have an external chip which, after sending a SPI command to it, you have to provide 65 pulses of the frequency you wanna set it to oscillate.

// set MSP frequency
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;

..... 

// start for 65 calibration pulses
while(calibration_steps--) {
        P3OUT ^= BIT3;
        __delay_cycles(6);
}

The callibration procedure is done, because I see a change in the oscilloscope after doing it :) No problem till the moment.

Unfortunately, I would wish always the same frequency, and, perhaps due to that voltage things (the voltage in the battery is lower after some time) the callibrated value is not always the same. In fact, it varies between 28kHz and 30kHz between different runs.

Do you have a hint about how to better achieve this? I guess the __delay_cycles is NOT the best option.  We are also contemplating using a 28kHz crystal but it would be nice to know the best way to do this in software, as well as what am I doing wrong.

Thanks a lot for your time!

  • Hi kazola,

    It is much better to use a Timer (of which the MSP430F2350 has two) to generate programmable pulses, as you will not be affected with instruction cycle lengths, branching, intervening interrupts, etc etc which all contribute to the frequency error. You can source the Timer with any of the clock sources ACLK, SMCLK, MCLK, or even an external TxCLK.

    Also, the DCO factory calibrated tolerance has an overall tolerance of +/- 5% over voltage and temperature (+/-3% over voltage and +/-2.5% over temperature); if you need a tighter tolerance you should consider a crystal. A watch crystal would be the simplest and cheapest, since the load capacitance is integrated, so you just need to solder on the crystal and change the register settings. (I believe we've had a similar discussion before, if my memory serves me correct...)

    Tony

  • BTW, if you do end up using a low frequency crystal (is there a particular need for 28khz? 32.768khz is much more common and hence cheaper, not to mention binary divisible), it would actually necessitate the use of a Timer, since 32khz is too low a frequency to bit-bang the ports (you'll likely end up with just a few khz).

    Tony

  • I do not know which variant of 8051 you usually work with. Most 8051 need either a crystal or an external clock. Without that, if will not work at all. MSP430 has a DCO that is very flexible and does not need any external components. But if you need accurate frequency, MSP430 also needs either a crystal or an external clock.

    With a few lines of code, you can set up the DCO to oscillate in a wide range of frequencies. But the frequency at the same setting will vary by a few percent depending on the operating temperature and voltage. Worse still, the frequency at the same setting will vary by even more from chip to chip. TI “calibrated” each chip and wrote the proper settings for that particular chip in its Flash. If you use those settings that TI wrote in the Flash, you eliminated the large DCO frequency variations from chip to chip. But you are still left with the few percent frequency variation due to operating conditions.

    I think you probable already understood this. There is nothing wrong with you code. And the result is consistent with the inherent inaccuracy of the DCO. If you want better accuracy, you have to include an external crystal or oscillator – just like most 8051.

  • Hi Kao and Cow :)

    Thank you for your time and answers!

    I'll try your wise suggestions.

    NOTE: I'm commenting the 8051 thing just to let you know that I'm not used to MSP430, just in case this is a stupid question ;)

    NOTE 2: Kao, the 28kHz is something related to RF, the project came to me this way, I also said about the 32kHz thing. I will try to change ;)

  • kazola said:

    NOTE 2: Kao, the 28kHz is something related to RF, the project came to me this way, I also said about the 32kHz thing. I will try to change ;)

    Unfortunately it may not be a choice if you decide to use an LF crystal. I just searched on Digikey for 28khz crystals and it turned up a grand total of one part, in comparison with 300+ for watch crystals.

    What you could do, if generating 28khz is critical, is to calibrate the DCO using the watch crystal, i.e. an FLL in software. You can do it at startup, or periodically if drift is a concern.

    Or you can custom order a 28khz crystal, but that opens up a whole 'nother can o' worms...

    Tony 

  • What is the exact frequency and accuracy that the radio chip needs?

    If you use 32.768 kHz watch crystal and DCO with FLL, choose the multiplier and divider wisely.

    An alternative is to use a crystal between 1 and 16 MHz which is an integer multiple of the frequency you need. Do not use DCO or FLL. Use Timer or CPU to divide it down. This will be more accurate. The power consumption is much higher than the watch crystal, but the start-up time is much shorter and you can turn it on and off as needed.

**Attention** This is a public forum