last day (17 days later) » 

18:26
1
Q: frequency counting program

Sayan1.MOV TMOD,#15H 2.SETB P3.4 3.MOV R1,#28 4.MOV TL0,#00H 5.MOV TH0,#00H 6.MOV TL1,#00H 7.MOV TH1,#00H 8.SETB TR0 9.HERE2: SETB TR1 10.HERE: JNB TF1, HERE 11.CLR TF1 12.CLR TR1 13.DJNZ R1, HERE2 14.CLR TR0 15.CLR TR1 This program written above is to count the frequency of pulse which is present ...

Please capitalise your writing properly for ease of reading and accuracy. Your compiler wouldn't tolerate it ...
@Transistor for now, I do not even care about the formalaties, I want to make sure whether the number 1 program is logically correct?
Yes, but you are expecting your readers to muddle through your writing and the lack of proper formatting is somewhat disrespectful to your audience that you are asking to give freely of their time to help you. Make it easy for your readers. See Write to the best of your ability on the site's help pages.
jay
jay
@Sayan, I did not go through 8051 datasheet, but could not find any reason why, except, as you said, the redundant adds a few more cycles in the timer loop. Meantime, though it does not matter, Line 11 & Line 15 are both CLR TF1? You can probe and adjust the timing, probably adding nop, while observing a GPIO pin toggle.
@jay yes, 15 is i think redundant, will remove that. except that any other issues?
jay
jay
18:26
@Sayan, Sorry about my nitpick. I was just reading through your code to check your question, not more than that. Some devices/u-processors have peripherals that locks some functions (resetting, writing, and configuring) until the ENABLE flag gets cleared. But, I do not remember what registers of 8051 have such a feature or not. Experiment, if possible, will immediately tell that as well.
TF1 has nothing to do with CONTROLLING timer counting. It's just a status flag. Only TR1 controls timer start and stop.
@MituRaj I am not controlling using TF1. just tell me this while TR1 is set, making RESETTING TF1 from raised state will make the timer again counting from 00 or not? i am using TF1 to start the timer again and again without refilling it with 00 again and again.
No it won't....that's not how timer works in 8051.
WHY? TR1 is still set.
If you think resetting TF1 resets timer to 0x0, it means you think you can somehow CONTROL timer with TF1. That's wrong. Only TR1 controls it.
18:26
see the last comment, it was given by you only
By 'reset', it means clear. TF1 has to be cleared. not TR1. TR1 set means counter is running regardless of TF1 value. TF1 is not a control flag, it is a status flag. If you forgot to clear TF1, you will miss subsequent timer overflow events, because timer is actually still running inside. ---- This is the comment. Where am I telling that TF1 controls the resetting of timer? I can keep TF1 '1' and timer won't care. It would still be running, rolling over, and so on. You can debug this on a simulator and confirm.
alright, I got it. thank you
one more question : suppose I want to avoid reloading of the value 00 again and again by #addressing, in that case just first clearing TR1 and TF1 and then set TR1 would work just fine?
Also i have edited the program above, would you like to tell me whether it is correct
18:39
or you must load the timer with 00 anyhow to start it again? i have edited the program according to my previous comment.
 
1 hour later…
19:46
No need to load 0 again. It's not mandatory. Because anyway after overflow, it starts from 0 again and increment. At this point, you can clear TF and move on. But if you want to load different value, then obviously you have to stop timer, reload and then start it again.
Note that clearing TF is not resetting timer.

  last day (17 days later) »