View Feed
group-icon
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12832 Members
Join this group to post and comment.
sparsh sharma
sparsh sharma • Nov 16, 2015

About timer operation in 8051 micro controller

I AM STUDYING MICROCONTROLLER 8051 SUBJECT, WHILE DOING PROGRAM OF TIMER OPERATION, I HAVE FOUND SOME PROBLEM IN THE MODE 2 OF TIMER OPERATION IN WHICH CONTENTS PRESENT IN THx IS AUTO RELOADED INTO THE TLx AND WHEN TLx BECOMES 00H TFx FLAG GOES HIGH AND CONTENTS AGAIN AUTO RELOADED INTO THE TLx FROM THx.
BUT THERE IS A PROBLEM WHEN TIMER STARTS BY SETTING THE TRx BIT HIGH, THE TLx STARTS FROM 00H INSTEAD OF STARTING WITH THE CONTENTS OF THx. TLx ALWAYS STARTS WITH 00H.
I HAVE ALSO ATTACHED THE IMAGE OF MY PROGRAM THAT I HAVE WRITTEN IN KEIL SOFTWARE WHERE IN THE RED CIRCLE I HAVE SHOWN THE CONTENTS OF THE TH AND TL REGISTER.
Harshad Italiya
Harshad Italiya • Nov 16, 2015
@sparsh sharma can you share your keil project .zip file here?
sparsh sharma
sparsh sharma • Nov 17, 2015
Harshad Italiya
@sparsh sharma can you share your keil project .zip file here?
@Harshad Italiya
i have written just a small program to check the working of timer in mode 2.
IanSiladi
IanSiladi • Nov 26, 2015
The problem is looking in your code. Are you enable to put the count that should be copied into the TL from the TH?
Also what about your interrupt handling?
Are you using any kind of the hardware interrupt here, specially for your timer-counter?

printed circuit board manufacturing
sparsh sharma
sparsh sharma • Nov 26, 2015
IanSiladi
The problem is looking in your code. Are you enable to put the count that should be copied into the TL from the TH?
Also what about your interrupt handling?
Are you using any kind of the hardware interrupt here, specially for your timer-counter?
This code is written just for the purpose of understanding the Timer operation in MODE 2 of 8051uc. i have also simulate it on keil uvision3 software. the snap shot of the output i have attached.
and count in TL0 is loaded with TH0 contents only if TF0 is made high internally, initially TL0 starts with 00h.
and about interrupt i am using the polling/status check method not using any hardware interrupt.
just checking the TF0 bit status
Harshad Italiya
Harshad Italiya • Nov 26, 2015
@sparsh sharma :
8051 Timer 0 Mode 1 Example Program
8051 Timer 1 Mode 2 Example Program
You can find Timer 0 example code from KEIL. Try this and see if this is working for you properly or not.
sparsh sharma
sparsh sharma • Nov 27, 2015
Harshad Italiya
@sparsh sharma :
8051 Timer 0 Mode 1 Example Program
8051 Timer 1 Mode 2 Example Program
You can find Timer 0 example code from KEIL. Try this and see if this is working for you properly or not.
yes its working but with the same way as i have mentioned, there is a need to load the TLx register first, there is no auto reload initially in this mode2. auto reload happens only after the generation of Timer Flag internally.
Thanks
Harshad Italiya
Harshad Italiya • Nov 27, 2015
sparsh sharma
yes its working but with the same way as i have mentioned, there is a need to load the TLx register first, there is no auto reload initially in this mode2. auto reload happens only after the generation of Timer Flag internally.
Thanks
I am still not getting you. Have you checked what is the difference between your code and the example code?
sparsh sharma
sparsh sharma • Nov 28, 2015
Harshad Italiya
I am still not getting you. Have you checked what is the difference between your code and the example code?
yes i checked, there is no difference, both are same
thank you sir

Share this content on your social channels -