Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Urgent question about 8051 timer

Status
Not open for further replies.

amsung2

New Member
in order to generate 5ms delay using 11.0592mhz crystal, what are the values to be loaded into TH0 and TL0? (mode1, 16 bit counter)
in mazidi, the values say:
5ms/1.085us=60926 thus TH=EE and TL=00
but another book tells me to do the no. to be loaded is19457
and also instructs to perform the following calculation before lading the values in TH and TL:
TH0 * 256 + TL0 = 19457
assuming TL0=1
TH0=76.
thus the values to be loaded are:th=4c and tl=01
which one is correct?
please help!!!
 
The timer is incremented every machine cycle.
With a 11.0592Mhz crystal, the timer is incremented every 1.085us.
If you want to know how many times the counter is incremented in 5ms, it's
0.005 * 921,583 = 4607.915

65,536 - 4607.915 = 60928

TH = ED
TL = 00
 
Last edited:
alright that seems to to suggest that first solution is the way to go, does that mean that the other is wrong? it comes from a reliable source...
please check out the link and let me know if you can:
**broken link removed**
thank you very much for the reply
 
That link you posted is right but it's probably confusing.
Instead of using a formula, understand how it works. A 8051 machine cycle is 12 clock cycles, which is what it takes for the timer to increment.

To keep it simple, first take a 12MHz crystal, since a machine cycle takes exactly 1us. If you load the 16-bit timer with zero, it counts from 0 to 65535. Which takes 65536us. That's the max delay.

So to get a delay of 5ms, you subtract 5000 from 65536, and load the timer with the result. That's all.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top