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, assembly, timer - does the flag register need clock 2 to be monitored by a microcontroller?

Status
Not open for further replies.

RAHUL_KUMAR

Member level 5
Joined
Jun 5, 2017
Messages
90
Helped
4
Reputation
8
Reaction score
4
Trophy points
8
Location
Bhubaneswar,Odisha,India
Activity points
780
8051,assembly,timer- do flag register need clock 2 get monitored by microcontroller?

To generate time delay using timer we set the value of timer by loading TH and TL value in 8051 architecture micro controller. and start the timer by using instruction setb TR1 (if using timer 1) . the TF1 flag continuously get monitored and set to 1 when timer value roll over from FFFFH to 0000H.

Each increment produces a delay of 1.085 uS if we are using XTAL as 11.0592 MHz.
If we go for exact delay calculation we will have to consider each instruction comes in between.
each instruction need clock depend on its machine cycle . 1 byte instruction need 12 clock ,2 byte need 24 clock and so on .and timer need 12
clock .
one thing in all this is not encountered is the role of TF flag. it is continuously get monitored . dont it need any clock for this purpose?
QUESTION: To get exact delay calculation , we consider timer value and the instructions used in between for delay . But we dont consider the flag .
Dont it (the flag) need any clock to get monitored ?
if yes ,then it must be considered in exact calculation.
if no, then how is it happening? programmer dont monitor TF flag but ,uC itself do it . then it must be needed clock to execute it .
 

Re: 8051,assembly,timer- do flag register need clock 2 get monitored by microcontroll

....
If we go for exact delay calculation we will have to consider each instruction comes in between. ....

can you explain it further ?
Why you want to consider each instruction comes between .. What comes in between?
 

Re: 8051,assembly,timer- do flag register need clock 2 get monitored by microcontroll

Timer will increment for 14 times
Code:
HERE: MOV  TL0,#F2H          ;2 CYCLE
          MOV  TH0,#0FFH      ;  2CYCLE 
          CPL    P1.0                 ;1 CYCLE
          ACALL DELAY           ;  2 CYCLE
          SJMP  HERE               ;2 CYCLE
DELAY: 
           SETB   TR0               ;1 CYCLE
X1:      JNB     TF0,X1           ;14  (1*14 timer increment 14 times ,And JNB is 1 byte instruction)
           CLR     TR0               ;1 CYCLE
           CLR     TF0                ;1 CYCLE
           RET                        ;  2 CYCLE

total 28 cycle for each complement. (in between means the instruction executed between timer ON to timer OFF)
Here JNB instruction is used by programmer to monitor the flag TF1. if we dont use JNB still this flag will be monitored by ucontroller .and will be affected when timer roll over from FFFFH to 0000H.
here what my question is if we dont monitor the flag ,.. should we consider it inside the delay calculation. because in the backend it is been continuously monitored
microcontroller.

i am re writting the program....with some changes in between

Code:
HERE: MOV  TL0,#F2H         ; 2 CYCLE
          MOV  TH0,#0FFH        ;2CYCLE
          CPL    P1.0                ; 1 CYCLE
          ACALL DELAY           ;  2 CYCLE
          SJMP  HERE              ; 2 CYCLE
DELAY: 
           SETB   TR0               1 CYCLE
           nop          ; 14 times nop is written in place of 14 times monitoring the TF1 flag by JNB instruction .
           nop           
           nop
           nop
           nop
           nop  
           nop
           nop  
           nop
           nop  
           nop
           nop  
           nop
           nop    
           CLR     TR0             ;  1 CYCLE
           CLR     TF0              ;  1 CYCLE
           RET                          ;2 CYCLE
let me put the clear queation....
now when we calculate the exact delay as per the program ,total 28 cycle will be considered but , in the back end , TF1 flag is also affected during roll over ,and hence was continuously monitored by micro controller during execution of NOP instruction. should we add the monitoring of the flag inside the delay calculation ?
will it become 28+14 cycle ? or there will not be any changes ?
 
Last edited by a moderator:

Re: 8051,assembly,timer- do flag register need clock 2 get monitored by microcontroll

Timer will increment for 14 times
Code:
HERE: MOV  TL0,#F2H          ;2 CYCLE
          MOV  TH0,#0FFH      ;  2CYCLE
          CPL    P1.0                 ;1 CYCLE
          ACALL DELAY           ;  2 CYCLE
          SJMP  HERE               ;2 CYCLE
DELAY: 
           SETB   TR0               ;1 CYCLE
X1:      JNB     TF0,X1           ;14  (1*14 timer increment 14 times ,And JNB is 1 byte instruction)
           CLR     TR0               ;1 CYCLE
           CLR     TF0                ;1 CYCLE
           RET                        ;  2 CYCLE

total 28 cycle for each complement. (in between means the instruction executed between timer ON to timer OFF)
Here JNB instruction is used by programmer to monitor the flag TF1. if we dont use JNB still this flag will be monitored by ucontroller .and will be affected when timer roll over from FFFFH to 0000H.
here what my question is if we dont monitor the flag ,.. should we consider it inside the delay calculation. because in the backend it is been continuously monitored
microcontroller.

i am re writting the program....with some changes in between

Code:
HERE: MOV  TL0,#F2H         ; 2 CYCLE
          MOV  TH0,#0FFH        ;2CYCLE
          CPL    P1.0                ; 1 CYCLE
          ACALL DELAY           ;  2 CYCLE
          SJMP  HERE              ; 2 CYCLE
DELAY: 
           SETB   TR0               1 CYCLE
           nop          ; 14 times nop is written in place of 14 times monitoring the TF1 flag by JNB instruction .
           nop           
           nop
           nop
           nop
           nop  
           nop
           nop  
           nop
           nop  
           nop
           nop  
           nop
           nop    
           CLR     TR0             ;  1 CYCLE
           CLR     TF0              ;  1 CYCLE
           RET                          ;2 CYCLE
let me put the clear queation....
now when we calculate the exact delay as per the program ,total 28 cycle will be considered but , in the back end , TF1 flag is also affected during roll over ,and hence was continuously monitored by micro controller during execution of NOP instruction. should we add the monitoring of the flag inside the delay calculation ?
will it become 28+14 cycle ? or there will not be any changes ?

once you make the timer run by TR0 bit, then you need not monitor it.
ON timer 0 interrupt you can do your own processing.
 

Re: 8051,assembly,timer- do flag register need clock 2 get monitored by microcontroll

i have not asked any alternative for doing the same thing,.. i asked the question to know the operational mechanism.......
and it is required where we encounter for exact delay calculation.....

1st program i wrote above takes 28 clock
2nd program - question whether it will take same 28 or (28 + 14) clock .
why i am adding 14 clock , already elaborated above.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top