Microcontroller › 8051 › question about digital clock project posted here.
- This topic has 7 replies, 2 voices, and was last updated 13 years, 7 months ago by romel emperado.
-
AuthorPosts
-
April 13, 2011 at 5:27 am #861romel emperadoParticipant
guys pls explain to me how did they come up with this calculation for the timer to generate a delay of 1sec..
this project is posted here: http://www.engineersgarage.com/microcontroller/8051projects/digital-clock-AT89C51-circuit
void delay() //Function to provide a time delay of approx. 1 second. using Timer 1.
{
int i;
for(i=0;i<20;i++)
{
TL1=0xFD;
TH1=0x4B;
TR1=1;
while(TF1==0);
TR1=0;
TF1=0;
}
}
FD4B is 64843 in decimal so pls tell me how would that calculation genarate 1 second? that is less that a second.. correct me IF am wrong but i think something wrong with the calculation..
I have my own code here to generate 1second using 12Mhz crystal but i dont get it how the above code geraate a second delay..
void delay(char k)
{
char i;
TR1=0;
for(i=0; i<k; i++)
{
TH1=0x3c;
TL1=0xB0;
TF1=0;
TR1=1;
while(TF1==0);
TR1=0;
}
}April 13, 2011 at 7:29 am #5967dagakshayParticipanthello romel,
How does the code you have pased above (which which given on site) is giving 1 second…
timer register is a 16 bit register since they are using it in mode1
TH1=0x4B;
TL1=0xFD;
so 4BFD = 19453 in decimal
65535 – 19453 = 46083;
they using 12MHz crystal so freq./12clock
12MH/12=1Mhz
t=1/f=1 us in the case of 12 MHz crystal
if they would have used 11.0592 Mhz it would be 1.085 us
46083*1us*20 loops= 921660 us near about 0.92 second for 12Mhz
46083*1.085us*20 loops= 1000001.1 micro second which is more closer to 1 second
ideally they would have used or calculated it for 11.0592Mhz
and the delay function(second one) which you have pasted will count = 49999 us*k (according to 12Mhz)
if k=20 the total it will give around 0.99 second… so you delay in case of 12 Mhz will be more accurate..
April 13, 2011 at 9:27 am #5971romel emperadoParticipanthaha look at my previous post… My convertion is wrong that is why i said it’s less than a second.. hehe thanks so much yar
April 15, 2011 at 1:09 am #5977romel emperadoParticipanthello again.. i have done actual hardware experiment about the accuracy of these values and i come up results.
this value below is not realy accurate 1 second delay. i compared it to a real digital clock it will be late for 20secs after 48hours..
TH1=0x3C;
TL1=0xB0;
i think this one would be better but its under observation
TH1=0x3C;
TL1=0xBB;
its beter to use RTC… less hassle .. hihi
April 15, 2011 at 5:40 am #5981dagakshayParticipantit is delayed because the crystal we use that is why for higher research ppl generally you other clock source… exaclty i dont remember what is that term… “partially it is an atomic clock” which basically some of relation with the nuclear half life period i dont know its complete details…in the case of watch for more acuracy analog clock are prefered rather then the digital one… you yourself can see the difference.. buy a local digial clock and a standard one any branded digital clock… set them with same time just in few months you can notice the dealy b/w them.. that is why standard companies digital clock are more costaly than the local one… its a very nice concept i read a long back thanks for repolishing my old dead blocks… i will surly write an artical on it and send it to you as soon as possible…..
April 15, 2011 at 6:47 am #5982romel emperadoParticipantyeah thanks for answering yar.. yes it is true…
but for some hobbyist in embedded system using real time clock(RTC) and interface with controller is much better compared of using timer interrupt..
example of RTC use in some projects is DS 1307..
April 15, 2011 at 7:43 am #5983dagakshayParticipantInterfacing RTC again makes the ckt bulier and the code goes heavier… you can use the controller which would hae inbult RTC… but again id depends on kind of application you using… sor some small applications timer is more than sufficient
April 20, 2011 at 4:44 am #6003romel emperadoParticipantI agree.. it depends on your application..
-
AuthorPosts
- You must be logged in to reply to this topic.