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?
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!
Erik
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!
/*Program for generating sqwave on pin 7 of port 2*/
#include <REG51.h>
sbit mybit = P2^7; void delay();
main() { while(1) { mybit = mybit^1; /*Invert mybit to toggle between 0 and 1*/ delay (); } }
void delay() { TMOD = 0X20; /*Timer 1 operation in mode 2*/ TH1 = -184; TR1 = 1; while(TF1==0);/*Polling mode is used instead of interupt mode*/ TR1 = 0; TF1 = 0; }
It works in autoload mode and the TL1 starts intially from 00 and later gets
loaded by the value in TH1 register.The problem is that it doesnt leave the delay routine
to go back to main program again where "mybit" is inverted to generate square wave of
50%duty cycle. The timer starts again after overflow and step mode execution is stuck at
while(TF1==0). But when it runs in mode 1, everything functions smoothly and the delay
routine returns to the main program.
'The problem is that it doesnt leave the delay routine'
you just cannot help killing yourself, can you?
Ashley,
Why don't you just help the poor chap?! Come on, the guy suffered enough (I would if I could!)
"Why don't you just help the poor chap?! Come on, the guy suffered enough (I would if I could!)"
tammy: for the same reason that I have given up on you.
at some point, a person is deemed beyond help.
<QUOTE>tammy: for the same reason that I have given up on you.</QUOTE>
i remember tapeer as a stewdent. to teech him i used code like this
while ( still_breathing ) { send_message( to_tapeer, "read abi, page x, section y" ); receive_message( from_tapeer, msg ); if ( is_response_an_insult ( msg ) ) { // msg prob from tapeer if (! is_response_like ( msg, "you are wrong, r0 is not preserved") ) { // tapeer might at finally be listening if ( is_response_like ( msg, "im very good, you dont know anything") ) { // tapeer found information but too stubborn to admit help was good break; } } } } do_some_real_work ( ); }
always yo're freind.
Zeusti
to go back to main program again
how can it 'work' when "The problem is "
for the first delay you depend on whatever is in TL1 for your delay no autoload takes place before the timer roll over. for the next delay you will get the autoload value plus whetever counts happened before TR1=0. You are confusing the whole issue by using autoload. With a lot of feniggeling I have no doubt this could be done with autoload but why use auotoload when only one run in the routine. Using illogical modes does nothing but make the issue confusing, complex. less maintainable, less understandable, and error prone.
why not just straight code
void delay() { TMOD = 0X10; /*Timer 1 operation in mode 1*/ TH1 = 0xff; TL1 = -184; TR1 = 1; while(TF1==0);/*Polling mode is used instead of interupt mode*/ TR1 = 0; TF1 = 0; }