To find value for 8051 Timers to program in MODE 2

Oct 20, 2005 3 Replies

Dear Experts, I am Ravikumar.N, working on Atmel At89c52 microcontroller. I have an issue regarding the Timers of the controller to be used in mode 2.


1)I want to generate a delay of 200 microseconds in MODE 2.


2) I dont know what value to be loaded to the TH and TL register of the TIMER.


3) I need to know how to calculate these value(which are to be loaded to TH and TL register).

I went through the manual of the controller, I didn't get any explaination regarding the calculation of the value to be loaded to the TIMER registers(TH, TL).



I am in need of the calculation



Please guide me.


With Regards, Ravikumar.N



You need to know that the counters count up. When it rolls over, you get an interrupt, if enabled. The counter can be clocked from the CPU's clock and there is a prescaler between the clock and the counter. So the frequency of the counter is the clock frequency divided by the prescale factor.

Example: Your CPU clock is 8MHz. The prescaler is set to 1. Then T2 counts up in

125ns increments. You need 200us. 200us / 125ns = 1600 ticks. Since the counter counts up, you need to load 65536 - 1600 = 63936 or 0xF9C0 in TH,TL.

The clock source, prescaler and counter interoperation is in the datasheet.

Regards, Meindert

Thanks Sprang, The problem is MODE 2 is an 8-bit counter,the value that is obtained from your calculation is a 16-bit value. I need an 8-bit value to program the TIMERS in MODE 2. Please tell me how to get this

8-bit value.

Regards, Ravikumar.N Me> >

The same way as to obtain the 16 bit value. You just need to program a higher prescaler value in order to get the result of the calculation below

256.

Meindert

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required