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?
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.
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.
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!
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.
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.
"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.
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
The code clearly states
Nonsense. What "code" you showed us here doesn't state anything clearly.
that its polling and interupt mode.
And that's an obvious self-contradiction.
all I am getting are replies which does not solve my problem.
That's because you failed quite spectacularly at presenting what your problem even is.
the above code works perfectly well when run on keil simulator in mode 1. It does work when using mode 2.
So it works in both modes, you say. What was your problem, again?
"Nonsense."
no reason to be so harsh.
yes, his posts were not the clearest; and his mastery of english words wasn't as smooth as yours.
but he got the gist of his points across after a few tries.
maybe you can ask him for more clarification, but there is no point in beating down a newbie to establish your superiority, because everyone of us was a newbie in the not-so-distant past and will be a newbie in the not-so-distant future on some matters.
so be kind and stop being an @#$@
"show some actual, complete, indented, commented code"
his code is actual and complete, sufficient to get you to his "problem", as is.
but here is his code presented in a nicer way, per your request.
#include <reg51.h> void delay(); sbit mybit = P1^5; main() { while(1) { mybit = mybit^1; delay(); } } void delay() { TMOD = 0x02; TH0 = 0xF0; TL0 = 0xF0; TR0 = 1; while (TF0==0); TR0 = 0; TF0 = 0; }
"so be kind and stop being an @#$@"
Oh brother! That from the like of you, who is without question the biggest, most overt "@#$*" we've had on this forum, the Microchip forum, and the HI-TECH forum! Sheesh!
his code is actual and complete,
You're either deluding yourself, or you're deliberately talking nonsense. I'm sure of that because it's blatantly clear that you have no way of knowing what you just claimed.