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:19
Read: times


 
#172542 - PWM IRQ code in C, bitops, 45 byte
Responding to: ???'s previous message
Hi,
you can boil down the code that was cited in the original code from 101 bytes to 45 bytes with:

#include <8052.h>

static unsigned char ms_tenth;
static unsigned char servo1_target;
static unsigned char servo2_target;
static unsigned char servo3_target;

void Timer0_ISR (void) interrupt 1 {

    P1_2 = (ms_tenth < servo1_target);
    P1_3 = (ms_tenth < servo2_target);
    P1_4 = (ms_tenth < servo3_target);

    if (++ms_tenth == 180)
        ms_tenth = 0;

    TF0 = 0;
}

void main(void){}
 


As a bonus the code looks more readable (at least to me:) This is the generated assembler code:

   0000                     374 _Timer0_ISR:
   0000 C0 E0               383         push    acc
   0002 C0 D0               384         push    psw
   0004 75 D0 00            385         mov     psw,#0x00
                            386 ;       servo_bitops.c:12: P1_2 = (ms_tenth < servo1_target);
   0007 C3                  387         clr     c
   0008 E5*00               388         mov     a,_ms_tenth
   000A 95*01               389         subb    a,_servo1_target
   000C 92 92               390         mov     _P1_2,c
                            391 ;       servo_bitops.c:13: P1_3 = (ms_tenth < servo2_target);
   000E C3                  392         clr     c
   000F E5*00               393         mov     a,_ms_tenth
   0011 95*02               394         subb    a,_servo2_target
   0013 92 93               395         mov     _P1_3,c
                            396 ;       servo_bitops.c:14: P1_4 = (ms_tenth < servo3_target);
   0015 C3                  397         clr     c
   0016 E5*00               398         mov     a,_ms_tenth
   0018 95*03               399         subb    a,_servo3_target
   001A 92 94               400         mov     _P1_4,c
                            401 ;       servo_bitops.c:16: if (++ms_tenth == 180)
   001C 05*00               402         inc     _ms_tenth
   001E 74 B4               403         mov     a,#0xB4
   0020 B5*00 03            404         cjne    a,_ms_tenth,00102$
                            405 ;       servo_bitops.c:17: ms_tenth = 0;
   0023 75*00 00            406         mov     _ms_tenth,#0x00
   0026                     407 00102$:
                            408 ;       servo_bitops.c:19: TF0 = 0;
   0026 C2 8D               409         clr     _TF0
   0028 D0 D0               410         pop     psw
   002A D0 E0               411         pop     acc
   002C 32                  412         reti

 


Might be enough to allow adding another one or two servos...

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