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?
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. Only after reaching roll-over the first time does the value in T0H get used as a reload value.
The program below is for generating square wave of some delay. I have taken F0 as eg to
check for small duration. When I run the program in step mode, the TL0 increments directly
to F3 and then the timer stops in autoload mode.The same set of instructions function in mode 1 I use keil Uvision 2.
#include <reg51.h>
void delay(); sbit mybit = P1^5; main(); { while(1) { mybit = mybit^1; delay(); } }
void delay() { TMOD = 0x02; TH0 = 0xF0; TL0 = 0xF0; TRO = 1 while(TF0==) TR0 = 0; TF0 = 0; }
"The program below"
that's a great piece of code.
keep up the good work!
This is one of the better lines:
while(TF0==)
I have to assume that the while loop should run until TFD becomes NULL.
I am simply amazed how many people who are supposed to be savvy at least with computers, fail to grasp the advantage of using "copy-paste" (but they apparently use it with success in their homework!) and re-type their "code". Stunning.
"Stunning."
as they say, stupidity is without limit.
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.
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?
Erik
"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.
"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. "
most likely your "most likely" is mostly likely wrong;
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.
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
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?
"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.
not necessarily, reload mode is an 8bit counter other modes are 13/16 bit
"not necessarily, reload mode is an 8bit counter other modes are 13/16 bit"
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.
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.