Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/05/99 05:46
Read: times


 
#130 - RE: 8052 timers
> I have to set up a timer that
> increments to 428ms. The
> controller is running at 4 Mhz.
> Is this possible at this clock rate?
> I assume it will take 3 usec to
> increment the timer ie. > 4Mhz/12=333,333.333 =>3usec. > 428ms/3usec=142,667. How do I set
> up the registers tlx, thx.

The 8052 timers, by themselves, cannot implement a 428ms interval timer since you are limited to a 16-bit timer, which is 65,536--much less than 142,667.

Instead, set timer 0 to 16-bit mode and initialize it with 463Dh (TH0=46h, TL1=3Dh). Every time timer 0 overflows (i.e., the TF0 flag is set), clear the TF0 flag and reset the timer to 463Dh.

When the timer has overflowed a third time, 428ms has passed (+/- a few microseconds). Depending on your application, this might be a good candidate for an interrupt routine.

Such as:

ORG 0000h
LJMP MAIN

ORG 000Bh
MOV TH0,#46h
MOV TL0,#3Dh
DEC R0
RETI

ORG 0040h
MAIN:

SETB EA ;Enable all interrupts
SETB ET0 ;Enable Timer 0 interrupt
MOV TH0,#46h ;Initialize timer
MOV TL0,#3Dh
MOV TMOD,#01h ;16-bit Timer 0
SETB TR0 ;Turn on timer 0

MOV R0,#03h ;Wait for 3 iterations

REPEAT:
CJNE R0,#00h,REPEAT
...your code continues here

The above code first enables timer 0 interrupt. It then initializes timer 0 to 16-bit mode with the initial value. It sets R0 to #3 since we need to wait for 3 iterations.

The CJNE loop then waits until R0 is decremented to 0. The interrupt will automatically decrement R0 every time the timer overflows. Thus when R0 reaches 0, the timer has overflowed 3 times and 428ms has passed.

Of course, modifying R registers within an interrupt is not recommended practice, but this is more of a practical example rather than a style example.

Good luck!

Craig Steiner


List of 4 messages in thread
TopicAuthorDate
8052 timers            01/01/70 00:00      
   RE: 8052 timers            01/01/70 00:00      
RE: 8052 timers            01/01/70 00:00      
RE: 8052 timers            01/01/70 00:00      

Back to Subject List