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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/18/10 11:29
Read: times


 
#172543 - PWM IRQ code in C, lookup table, 32 byte
Responding to: ???'s previous message
If P1 (or whatever port you connected the servos to) is free to use, you can also use a table lookup.
Thus you have no performance penalty within the IRQ for connecting up to 8 servos:)

#include <8052.h>

static unsigned char ms_tenth_countdown;

// dynamically setup table.
// Indexed top down.
// setup glitchlessly!
unsigned char __pdata table_P1_over_time[180 + 1];

void Timer0_ISR (void) interrupt 1 {

    // assuming P1 is only used for servos.
    P1 = table_P1_over_time [ ms_tenth_countdown ];

    TF0 = 0;

    if (!--ms_tenth_countdown)
        ms_tenth_countdown = 180;

}

void main(void){}
 


Now you'd be at:

   0000                     371 _Timer0_ISR:
   0000 C0 E0               380         push    acc
   0002 C0 00               381         push    ar0
   0004 C0 D0               382         push    psw
   0006 75 D0 00            383         mov     psw,#0x00
                            384 ;       servo_lookup.c:13: P1 = table_P1_over_time [ ms_tenth_countdown ];
   0009 E5*00               385         mov     a,_ms_tenth_countdown
   000B 24r00               386         add     a,#_table_P1_over_time
   000D F8                  387         mov     r0,a
   000E E2                  388         movx    a,@r0
   000F F5 90               389         mov     _P1,a
                            390 ;       servo_lookup.c:15: TF0 = 0;
   0011 C2 8D               391         clr     _TF0
                            392 ;       servo_lookup.c:17: if (!--ms_tenth_countdown)
   0013 D5*00 03            393         djnz    _ms_tenth_countdown,00103$
                            394 ;       servo_lookup.c:18: ms_tenth_countdown = 180;
   0016 75*00 B4            395         mov     _ms_tenth_countdown,#0xB4
   0019                     396 00103$:
   0019 D0 D0               397         pop     psw
   001B D0 00               398         pop     ar0
   001D D0 E0               399         pop     acc
   001F 32                  400         reti

 


I doubt that switching compilers would help much in this case. What's worse: coding directly in assembly code won't help much either:^)

List of 41 messages in thread
TopicAuthorDate
Controlling multiple servo motors            01/01/70 00:00      
   executing code takes time            01/01/70 00:00      
      PWM code            01/01/70 00:00      
         Thanks...now, about the PCA timer..            01/01/70 00:00      
   If SDCC Then Keil            01/01/70 00:00      
      PWM IRQ code in C, bitops, 45 byte            01/01/70 00:00      
         Optimization having no effect.            01/01/70 00:00      
      PWM IRQ code in C, lookup table, 32 byte            01/01/70 00:00      
         I haven't understood the table lookup concept very well...            01/01/70 00:00      
            table lookup            01/01/70 00:00      
         PWM IRQ code in C, lookup table, 30 byte            01/01/70 00:00      
            Compiler specifics            01/01/70 00:00      
               absolutely-locating xdata at 256 byte boundary            01/01/70 00:00      
                  I see.            01/01/70 00:00      
            An example code..            01/01/70 00:00      
               Keil: Specifics and non-specifics            01/01/70 00:00      
                  Not really working...            01/01/70 00:00      
                     Enough power?            01/01/70 00:00      
                        RE: running 32 servo motors            01/01/70 00:00      
      The chip sounds perfect...            01/01/70 00:00      
         not worth it            01/01/70 00:00      
            Servo control will become difficult then...            01/01/70 00:00      
               output            01/01/70 00:00      
               HCT chips have ...            01/01/70 00:00      
                  Eval a concept with a single PCA and 3:8 HCT multiplexer?            01/01/70 00:00      
               Check their website            01/01/70 00:00      
                  Here is the code...            01/01/70 00:00      
                     "sbit MTRS=P2^0;" is not OK here            01/01/70 00:00      
                        Keil syntax?            01/01/70 00:00      
                           "#define" not working.."sbit" works            01/01/70 00:00      
                              Yes, you were correct originally!            01/01/70 00:00      
            Seconded            01/01/70 00:00      
   Servo_0.1.zip            01/01/70 00:00      
      links            01/01/70 00:00      
   Eventually feed the guys at http://servomaster.sf.net ?            01/01/70 00:00      
      servomaster.sf.net FLOSS            01/01/70 00:00      
   Maybe of some use...            01/01/70 00:00      
      Whoops... found a bug            01/01/70 00:00      
         What bug?            01/01/70 00:00      
            Bug            01/01/70 00:00      
   Improved version uploaded            01/01/70 00:00      

Back to Subject List