English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

On a microcontrolor (8052) if i want to use the timer2 as a time base

I want an Interruput every 50 milisecond. How will i calculate the capture value for a 10 Mhz crystal

2006-08-31 03:50:26 · 1 answers · asked by Martin T 2 in Science & Mathematics Engineering

1 answers

I haven't used an 8052 for a long time but, IIRC, Timer 2 can be configured as a 16 bit counter and driven from Fosc/2. In your case, Fosc/2 will be 200 nsec so you'll need a total count of 50ms/200nsec = 250,000 counts which you won't get out of 16 bits. You'll just have to set up an interrupt every 1000 counts and then count 250 times through that loop before you actually go off and 'service ' anything.

If that 50 ms isn't *real* critical, you can configure the internal T2 clock for Fosc/256 which is 1953.125 counts so with 1953 counts you'll get an interrupt every 49.9968 ms. If that's close enough, do it.

If you're not real happy with writing 'countdown' loops inside of interrupt handlers, you might think of using external hardware to divide that 10 MHz down to 20 Hz. That's a division ration of 500,000 so you could get it out of a CPLD with 20 flip-flops (ln(500,000)/ln(2) = 18.93) Then use that 20 Hz. as the input in INT0 or INT1 and run off of them instead of Timer 2.


Doug

2006-08-31 04:51:33 · answer #1 · answered by doug_donaghue 7 · 0 0

fedest.com, questions and answers