Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] 8051 timer configuration

Status
Not open for further replies.

ark5230

Advanced Member level 3
Advanced Member level 3
Joined
Jun 29, 2009
Messages
862
Helped
163
Reputation
324
Reaction score
140
Trophy points
1,323
Location
India
Visit site
Activity points
6,187
I am trying to produce delay of 1/20 s (50 ms) using Timer/counter 0.
Crystal frequency is 11.0592 MHz and machine cycle is 11.085µs.
for 50ms the machine cycles required is 46079 decimal.
The counter is to be loaded with 65536-46079=19457=4C01Hex
TH0=04CH and TL0=01H.

SETB TR0 initiates timing and Polling TF0 gives the end of the required time.

Now the problem is IF Timer 0 is to be configured for the above purpose, What should be TMOD value?
TMOD = 01010001B configures this but also configures Timer 1 as counter !!
If timer 1 is not to be configure what should be the TMOD value.
A simple explanation of these setting will be of help.
Code:
        MOV TMOD,#01010001B ; TIMER CONFIGURATION
        MOV TH0,#4CH     ; VALUE IN TH0 FOR 1/20 S DELAY
        MOV TL0,#01H     ; VALUE IN TL0 FOR 1/20 S DELAY
        SETB TR0         ; START TIMER (FOR 1/20 S DELAY) 
        JNB TF0,$        ; WAIT TILL COUNTING IS OVER
        CLR TF0          ; CLEAR TIMER FLAG TF0
        RET
 

If you are not using Timer1 have to put 0 in high nibble of TMOD. Try the following, hope will be useful.

Code:
  org 0000h                                      ;reset
  jmp init_prog
  org 000bh                                      ;timer0
  jmp t0_isr
  org 0100h                                      ;main code starts somewhere else
init_prog:    
  mov  ie,#10000010b                       ;enables timer0 interrupt
  mov  tmod,#01h                            ;TMOD = 0000 0001 which means in low nibble for timer0 mode 1 (16 bits) and soft trigger
  mov  th0,#4ch                               ;50ms using clock = 11.059 Mhz
  mov  tl0,#00h
  setb  tr0                                        ;triggers timer0
  jmp   $
t0_isr:
   mov  th0,#4ch                               ;recharge 50ms 
   mov  tl0,#00h
   ;INSERT YOUR CODE HERE ......
   reti                                                ;you don't have to clean the flag TF0 before exit
end
 
Actually I want to keep it simple without interrupts.
The TMOD value should be 0000 0001 instead of 01010001B.
I will try to understand this. The details in datasheet are too technical!
Thanks for help, I would appreciate if some one could explain this TMOD configuration issue.
 

more help: 8051 timer configuration

OK, is not a problem.
Every nibble of TMOD have the following bits GATE, C/T and M1M0.
Configurating TMOD = xxxx 0001 means GATE = 0, the timer will start by soft with instruction setb TR0 C/T = 0 means working as timer0 with the clock pulses coming from your 11.059Mhz and M1M0 = 01 means that you will use the full 16 bits of timer0 with the calculations you already made. The don`t care bits in higher TMOD means the same for timer1. Usually timer1 is involved with serial port, where the regular configuration is TMOD = 21h, the 2(0010) means autorecharge mode of 8 bits for baud rate in timer1, bibliography have the table constants for TH1 = TL1 according to your 11.059Mhz clock. the 1(0001) remains timer0 being a timer of 16 bit for general purpouse.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top