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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/11/09 09:30
Read: times


 
#164531 - Post full ISR
Responding to: ???'s previous message
1) Try to post source code as code. Note the "Insret Program Code" button when you do make posts. This will make the code look like:
void Timer2(void) interrupt 5 using 1 {
    Tick --; 
    if (Tick == 0) { 
        if (DIR2 == STRAIGHT) { 
            switch (STATE2) { 
                case 0: 
                    P27 = 1; 
                    P15 = 1; 
                    P0 = 0x09; 
                    P1 = 0x29; 
                    Tick = 30; 
                    STATE2 = 1; 
                    break; 
                case 1: 
                    P0 = 0x0A; 
                    P1 = 0x2A; 
                    Tick = 30; 
                    STATE2 = 2; 
                    break;
                ...

 
As you can see, this is more readable than the inlined code you posted.

2) One thing here that worries me is your if (DIR2 == STRAIGHT) statement. Why don't define enough states to separate forward and backward direction and stopped? Then the switch statement will know what the next step will be. And note that it might be advantageous to you to keep track of which state you stop your motor in, depending on your requirements for holding torque.

3) What more are you doing in your interrupt, or what more are you using your "Tick" variable for. If all you use it for is to count down from 30 to do the next step, then you do not need to run this interrupt with 1kHz speed, but could use a longer interval such as 2ms, 3ms, 5ms or 15ms instead.

As I did write in an earlier post: If your ISR is always enough faster than 1ms that it leaves enough time for your main loop, then it should not affect the serial communication. Or is your ISR using a global variable larger than one byte that is also used by the serial code, and where the serial code may pick up a half-modified variable sometimes? Note that your processor can't atomically read or write variables larger than one byte so great care is needed when sharing larger variables between an ISR and the main loop.

Please post the full source for the ISR, and the variable declaration for all variables used by the USR together with info if any of the variables are shared with the main loop.

List of 40 messages in thread
TopicAuthorDate
how to avoid timer interrupt interrupts serial communication            01/01/70 00:00      
   Here the timing is relevant!            01/01/70 00:00      
   how to avoid timer interrupt interrupts serial communication            01/01/70 00:00      
      reply Kai            01/01/70 00:00      
         Do ms-class delays in any interrupt.            01/01/70 00:00      
            re: Per Westermark            01/01/70 00:00      
               ISR frequency * time significantly below 100%            01/01/70 00:00      
               Not sure, whether I got you...            01/01/70 00:00      
               That is not the main problem            01/01/70 00:00      
                  It's a common mistake...            01/01/70 00:00      
                     oops            01/01/70 00:00      
                        Long ISRs are no problem, unless...            01/01/70 00:00      
          instruction execution cycle/time in C language            01/01/70 00:00      
   ISR is set to 1ms but...            01/01/70 00:00      
      That is the problem            01/01/70 00:00      
         oops            01/01/70 00:00      
            What is the baud rate?            01/01/70 00:00      
               9600 baud            01/01/70 00:00      
                  He has got to be sitting in a interupt            01/01/70 00:00      
                     reply            01/01/70 00:00      
                        Many many more details needed!!            01/01/70 00:00      
                           reply Kai            01/01/70 00:00      
                              Further questions...            01/01/70 00:00      
                                 reply Kai            01/01/70 00:00      
                                    Who tells your micro how the stepper is to be moved?            01/01/70 00:00      
                                       reply            01/01/70 00:00      
                                          So, the stepper is running all the time?            01/01/70 00:00      
                                             ya...this is the purpose of having interrupt            01/01/70 00:00      
                                                Ok, then confirm this please...            01/01/70 00:00      
                                                   reply Kai            01/01/70 00:00      
                                                      Still delays in the ISR?            01/01/70 00:00      
                                                         reply per            01/01/70 00:00      
                                                      I suspect that your ISR is longer than 1msec!            01/01/70 00:00      
                                                         reply            01/01/70 00:00      
                                                         ISR code            01/01/70 00:00      
                                                            Post full ISR            01/01/70 00:00      
                                                               reply            01/01/70 00:00      
                                                                  Still not full ISR shown - and debounce?            01/01/70 00:00      
                                                                     Addendum            01/01/70 00:00      
   T_T            01/01/70 00:00      

Back to Subject List