Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/28/06 08:05
Read: times


 
#121243 - homework?
Responding to: ???'s previous message
This one sounds really like a homework, not to say that you are requesting code. That's -2 points in the scoring system here.

Usually, members of this forum prefer to give clues rather than "code" in a belief that it would help more than simply giving out the solution. If you are given any ready-made solution, first, you have learned nothing, and second, how can you know if it is correct or not?

Also, you haven't given enough information. What derivative of '51 are you using (clocks/cycle)? And what language (asm, C)? What should be the frequence of "checking" the P1.0 pin? Do you have to stick the input into P1.0 or can you use some other pin? Can you use all the resources of '51 freely, or are ther other tasks to run?

Some hints:
The simplest solution is a loop timed simply by instruction cycles, with checking the pin toggle. Two loops could be used, for both states, like in this pseudocode:
Loop:
indicate not idle on output
load counter with the timing value
repeat
  if counter=0
     indicate idle on output
  else
     decrement counter
until input=high

indicate not idle on output
load counter with the timing value
repeat
  if counter=0
     indicate idle on output
  else
     decrement counter
until input=low
goto Loop


This eats up all the resources of the controller so it can not do anything else.

A more sophisticated approach would use a timer interrupt for measuring the time, setting the "idle" signal on timeout; and a both-edge interrupt (see Peter Dannegger's solution for this here) to restart the timing.

Jan Waclawek



List of 2 messages in thread
TopicAuthorDate
help me regarding monitoring for 20sec a o/p port            01/01/70 00:00      
   homework?            01/01/70 00:00      

Back to Subject List