EmbeddedRelated.com
Forums
Memfault Beyond the Launch

To find value for 8051 Timers to program in MODE 2

Started by Unknown October 20, 2005

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

<ravikumar.n@sunlux-india.com> wrote in message
news:1129785070.092687.251930@f14g2000cwb.googlegroups.com...
> > > 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).
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
Meindert Sprang wrote:
> <ravikumar.n@sunlux-india.com> wrote in message > news:1129785070.092687.251930@f14g2000cwb.googlegroups.com... > > > > > > 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). > > 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
<ravikumar.n@sunlux-india.com> wrote in message
news:1129869615.924539.19100@f14g2000cwb.googlegroups.com...
> 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.
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

Memfault Beyond the Launch