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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/18/06 03:27
Modified:
  10/18/06 03:32

Read: times


 
#126622 - Now try this!
Responding to: ???'s previous message
 
Hey Yu,

There are two things wrong with your program.

1.  Suppose you want to step the motor every 200 microseconds, but
    suppose the "RS232 processing" and "other stuff" takes a total
    of 500 microseconds.  That means that you might get two or
    three timer interrupts while the program is in the while loop,
    before it has a chance to check 't' and step the motor.  This
    is probably why you are missing steps.

2.  Now suppose that you still want to step the motor every 200
    microseconds, but now the "RS232 processing" and "other stuff"
    only takes 100 microseconds.  Everything is okay now, right?
    No!!!  There is still a big problem.  Here's why:

    If you get a timer interrupt when the CPU is just starting to do
    the RS232 processing, there will be a delay of 100
    microseconds before the loop goes back to the top to check 't'
    and actually move the motor.  However, if the timer interrupt
    happens just before the end of the loop, then the delay before
    stepping the motor will be just a few microseconds.

    This means that the timing of each motor pulse will be delayed
    by some unknown amount.  The delay depends on where the
    program happens to be within the while loop when the timer
    interrupt occurs, and it could be different for each pulse.

To fix both of these programs, I think you should move the motor
by one step inside the ISR (see below).  Doing that will
make the motor pulse timing much more precise, and it will also
solve your "missing steps" problem, even if the while loop becomes
very long.

I know that everyone says, "Keep your ISRs simple."  That is good
advice most of the time.  In this case, however, you need to step
the motor inside the ISR in order to time the motor step pulses
precisely.

-- Russ

////////////////////////////////////////////////////////////////// 

main()
{
    Initialization();
    Timer0Init();
    while (1)
    {
        // RS232 processing
        // Other stuff ...
    }
}

////////////////////////////////////////////////////////////////// 

Timer0ISR
{
    // Move one step
}
 




List of 43 messages in thread
TopicAuthorDate
How to calculate CPU usage?            01/01/70 00:00      
   Generally            01/01/70 00:00      
      multicore '52?            01/01/70 00:00      
   Keil Tools            01/01/70 00:00      
   With what tools ?            01/01/70 00:00      
      Always 100.0%            01/01/70 00:00      
      Or            01/01/70 00:00      
         LED?            01/01/70 00:00      
            A way, Not the Way            01/01/70 00:00      
               spelling and syntax, just as an aside            01/01/70 00:00      
                  Thanks guys.            01/01/70 00:00      
                     What would that tell you?!            01/01/70 00:00      
                        100% is not always 100%            01/01/70 00:00      
                           Idle Not Idle            01/01/70 00:00      
                              We can not see your code            01/01/70 00:00      
                                 60% is not arbitrary            01/01/70 00:00      
                              Run a co-operative tasker!            01/01/70 00:00      
                                 he is doing the right thing, why lead him astray            01/01/70 00:00      
                              WHY            01/01/70 00:00      
                     then this is off-topic            01/01/70 00:00      
                        This isn't the Keil forum, so why ?            01/01/70 00:00      
                  My spelling sucks            01/01/70 00:00      
   Be sure to measure what's important            01/01/70 00:00      
      Good point            01/01/70 00:00      
         ISRs            01/01/70 00:00      
         Protocol?            01/01/70 00:00      
            adding a word            01/01/70 00:00      
            Checksums are not spackle            01/01/70 00:00      
         Try this            01/01/70 00:00      
            clarification            01/01/70 00:00      
               Delay.            01/01/70 00:00      
               Thanks            01/01/70 00:00      
            I'll try this!            01/01/70 00:00      
               Now try this!            01/01/70 00:00      
                  It still qualifies as simple ...            01/01/70 00:00      
                  Stepping inside ISR            01/01/70 00:00      
                     Essential things ...            01/01/70 00:00      
                  it still applies            01/01/70 00:00      
         re; control task            01/01/70 00:00      
            an added word            01/01/70 00:00      
            Buffered UART ?            01/01/70 00:00      
               there is a reason            01/01/70 00:00      
   Done!            01/01/70 00:00      

Back to Subject List