I use Keil sometimes and while using a timer in autoload mode, the TH0 is loaded with the calculated value but TL0 starts incrementing from 00 instead of the calculated value F0.Am I missing something while using or configuring the keil simulator?
The code clearly states that its polling and interupt mode. The code you show "clearly states" that no interrupt is involved
Interupt register is not included as you can all see in the lines of the code. so, how did you imagine we would know
All it does is check the flag and reset it after stopping the timer mixing polling and interrupt must be done with other means than the SFRs
Someone stated that "Why use autoload mode". Is there a ban in using autoload mode if the pulse duration is small. absolutely not, but the code you show does not have any autoload use
so, show some actual, complete, indented, commented code and someone will help you
Erik
"so if you were to step through the disassembly, you should see TL0 starting from 0xf0, rather than 0xf3."
stepping through the code in assembly, TF0 is set right after the roll over, and TL0 is at 0xf1.
the reading of 0xf3 is likely because of the time lapse on testing the TF0 flag while the tmr0 continues to run and increment TL0.
I agree that whatever mode the timer runs on is irrelevant for your question. so let's move on from that distraction.
"When running on mode 2, the TL0 register jumps directly to F3 and stops the timer in between. "
but you wrote earlier: "while using a timer in autoload mode, the TH0 is loaded with the calculated value but TL0 starts incrementing from 00 instead of the calculated value F0."
two comments:
1) the two statements are inconsistent; so you may want to tell us which is accurate. 2) as to the timer jumping to 0xf3 rather than 0xf0: because you are likely stepping through the code in C. each C statement may correspond to multiple asm instructions. so if you were to step through the disassembly, you should see TL0 starting from 0xf0, rather than 0xf3.
The code clearly states that its polling and interupt mode. Interupt register is not included as you can all see in the lines of the code. All it does is check the flag and reset it after stopping the timer and all I am getting are replies which does not solve my problem. Someone stated that "Why use autoload mode". Is there a ban in using autoload mode if the pulse duration is small. The above is for generating square wave and my question was the above code works perfectly well when run on keil simulator in mode 1. It does work when using mode 2. When running on mode 2, the TL0 register jumps directly to F3 and stops the timer in between. Anyone on this forum can run the code using keil simulator and see the difference when it runs in mode 1 and mode 2. Check the timer peripheral registers while running the debug.
since you have trouble understanding it, please allow me to restate it:
THE code would behave the same regardless if a reload mode is used or not. it seems that it mis you that have "trouble understanding it"
TH0 = 0xF0; TL0 = 0xF0;
in reload mode (8 bit) would count up from 0xF0 to 0 (expressed as 16 bit: 0xFFF0 to 0) in other (16bit) modes wold count up from 0xF0F0 to 0 - a whole lot longer!
"not necessarily, reload mode is an 8bit counter other modes are 13/16 bit"
THE code would behave the same regardless if a reload mode is used or not.
I did not say that ANY code would behave the same regardless if a reload mode is used or not.
hope it help with your comprehension of what I wrote.
"why do you use reload mode?"
but that's 2ndary to his question: aka the code would behave the same regardless if a reload mode is used or not.
not necessarily, reload mode is an 8bit counter other modes are 13/16 bit
"This example will exhibit the same issue you see"
I am not sure. I think his code appears to be correct. it is not clear what he observed (no auto-reloading or incorrect auto-reloading?). but if all he is concerned is that the first observable tmr count in the isr is not 0xf0 - that's due to interrupt latency.
but from what he wrote, it doesn't sound like that's he is complaining.
" - that the hardware is clearing the flag when it jumps to the Timer 1 interrupt vector."
I am pretty sure that's not his issue, and I am pretty sure that's supposed to have happened.
most likely your "most likely" is mostly likely wrong;
And that weak baloney is really all you managed to come up with, given three days it took you to work on your retort?
You're not seriously accusing me of not taking into account informaion that was only presented by the OP several back-and-forths after I replied, are you?
You can use this example as a reference:
http://www.keil.com/download/docs/97.asp
This is a Timer 1, 8 bit auto-reload example that is being serviced by a Timer ISR.
This example will exhibit the same issue you see - that the hardware is clearing the flag when it jumps to the Timer 1 interrupt vector.
Are you using an Timer ISR? In the above example, if you set EA = 0 or go to Peripheral -> Interrupt, and set EA =0, you will see the timer flag 1 (TF1) will never get cleared.
You can also observe the timer values under Peripherals -> Timer 1.
You can read more about how timers work on an 8051 here:
www.8052.com/tuttimer.phtml
"Most likely you're missing the fact that you are supposed to load the initial count into T0L the first time round if you want the first interval to be the same length as all the later ones. "
and most likely you would have lots of trouble to load the initial count into "T0L".
and most definitely loading anything into "T0L" isn't going to solve the problem.
I have not invited comments on my copy paste abilities , but wamt solns from the experts in this forum. you can hardly expect 'solons' when posting incorrect 'code'
void delay() { TMOD = 0x02; TH0 = 0xF0; TL0 = 0xF0; TRO = 1 while(TF0==0) // corrected by information from last post TR0 = 0; TF0 = 0; }
why do you use reload mode?
while(TF0==0) TR0 = 0; stopping the timer TF0 = 0; Reset the flag, When the lines of the code is as stated above its obvious that while loop is being executed till TF0 remains 0 and once its set to 1 the next steps are executed. The next two liines stops the counter and I dont understand what great coding techniques is involved to detect the missing number 0 in the while loop.I have not invited comments on my copy paste abilities , but wamt solns from the experts in this forum.
"Stunning."
as they say, stupidity is without limit.