STOPWATCH 1/1000th SECOND with MSP430

Has anybody out there in the big wide world ever made or seen the codes

for a very accurate timer running in real time at 1/1000th of a second

on a 32,768KHz crystal ???

My thoughts are to use a 32,000KHz /32=1/1000th of a second

/320=1/100th

/3200=1/10th

But am I making an exactly accurate STOPWATCH in real time!!!

Hi Ben,

two possible ways.

1.) You can build interrupts every 32 clock tics, =1/32768 * 32 = 0,0009765625 seconds per interrupt.

it is near to 1ms, for exact timing over a long period you can use the delta scheme.

Each time you got an interrupt you add 9.765.625 to a long named myTime, each time myTime is over or equal 10.000.000 you subtract 10.000.000 from myTime and inc myMs.

The max error at a specific time will be 1ms. But the error doesn’t grow.

You can also divide the two big numbers by 5^7, so you can handle with bytes instead of longs.

unsigned char myTime;
long myMs;

interrupt void CLK_ISR(void)
{
   myTime+=125; // 9.765.625 / (5^7)
  if (myTime>=128)
  {
    myTime-=128;
    myMs++;
  }
}

2.) Build a faster DCO-Clock with syncing with the ACLK.

You can set the DCO-Clock to approx 4MHz and syncing it with the 32.768kHz (look at the Appnotes).

Then you can build an interrupt with the DCO-Clk at nearly exact 1ms period time.

But you have to syncronize the two clocks all the time.

You can achieve good results with this technic, but it is a bit complicated (I use it to build a generic CAN-BUS Module with exact timing)

have a nice day

Jan Erik

I agree with what Jan said and like to add the following to approach (2).

I think you should use MSP430F2001 (or any other MSP430F20xx) and a good 32.768kHz crystal. Set and periodically adjust DCO to 8192kHz using the 32.768kHz ACLK as a reference.

F2xx has a much better DCO as compared with F1xx or F4xx and can operate at up to 16MHz.

F2001 is cheap (<$1) and available in both 14-pin DIP for prototyping and small (3mm x 3mm) pin-less package for volume production. 1KB Flash, 128B RAM and 10 GPIO pins should be enough for your application.

Thank you Jan Erik and OldCow for replying to me. Iwas very interested

in your advice on the DCO. I know about the notes SLAA336a but I never

thought you could get really high accuracy from it. I will study more into DCO

Thanks again Ben

Hi Ben,

the SLAA336a (“Using the DCO Library”) is nice, but don’t forget to build an ACKL-Interrupt to supress the dco-error over long times.

You have to calibrate more than once, because the DCO-Frequency will change significant if the temperature is changing (a touch with a finger could be enough or changing the state of a led near to the cpu).

The DCO of F2xx is much better than that of F1xx. It has much smaller temperature and voltage dependency.

However, when you vary the voltage from 1.8V to 3.6V and vary the temperature from -40 to +105 degrees C, the DCO of F2xx still varies by typically ±2% (min -5%. max 5%). Thus in order to get better accuracy, you still need to re-calibrated DCO periodically.

New thoughts from Ben. What about using 16MHz. VCS3.Crystal ±25PPM

From www.VECTRON.com In Basic Clock = /8 = ACLK.=2,000,000

ACLK= Timer_A (slac122) Code\ASM\msp430x22x4_ta_12.s43

sit (#1000-1,&TACCR0) It uses hardware only. It will be a very powerful programmable Timer

I am using eZ430-RF2500 and later I would like to interface to (dog-me LCD)

(EA 9780-1USB) from www.lcd-module.de and use RF instead of USB

It would be nice if TI made this for me!!!

Good. But a few things to watch out:

How much does the oscillator cost?

How much current does it consume?

Can the MSP430 you use accept such external digital clock as source of ACLK?

Ben is here again

I have decided to use (VXM4) 16MHz Crystal 1/2 $$$ to Oscillator. Drive Level 50uW. It can run on 430F2274 with 2 external Capicitors

A Stopwatch can be made from 430F2012 clock running at 16MHz from (TACLK P1.0)

and only an Oscillator at 3V can be used (F330A) from www.foxonline.com

Input Current=2.5mA Standby Current=1uA ±20ppm size=3.2x2.5mm

Thanks to both of you. It has helped a lot. :lol: