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.

1mSec tick for OS from XT1 with 32768 Hz crystal

Other Parts Discussed in Thread: MSP430F5437

Hi all,

Due to UCS10 errata for MSP430F5437 we are trying to use external 32768Hz crystal for 1 mSec tick of operation system. Unfortunatelly it's impossible to produce an accuyrate 1kHz tick. Any idea for us ?

 

Thanks

  • Hi Sergey,

    One nice way is to have your ISR keep a running "count" of the error in thousandths of a tick.  There are 32.768 ticks in every millisecond.  So you'll have more 33-tick periods than 32-tick periods, but the running count of error will help your ISR decide which interrupt period to use next (32 or 33 ticks).  Over a full second your clock is perfect.

    This same approach also allows you to insert corrections for crystal calibration and even temperature correction by periodically adding small values to the running count.

    Jeff

  • Jeff Tenney said:
    One nice way is to have your ISR keep a running "count" of the error in thousandths of a tick.

    Yep, that's the easiest way. But don't use division to get the excess tick from the error count. It's convenient but very sloooow. And not necessary.

    Set up the timer interrupt for a base tick count of 31 (remember, '0' is a tick too). Or, if you are using a 'moving timer count', 32.
    Add 768 to a variable. Then check whether its content is >1000. if it is, increment the base tick count by 1 and subtract 1000 from the variable.

    This way you'll get an average tick of 32,768 tierm ticks = 1ms per tick.

**Attention** This is a public forum