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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Frieder Ferlemann
01/18/10 05:19
Read: 273 times
Old Europe


 
#172542 - PWM IRQ code in C, bitops, 45 byte
Responding to: Michael Karas'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      Yash Chitalia      01/17/10 14:47      
   executing code takes time      Erik Malund      01/17/10 15:27      
      PWM code      Steve M. Taylor      01/17/10 15:35      
         Thanks...now, about the PCA timer..      Yash Chitalia      01/17/10 16:06      
   If SDCC Then Keil      Michael Karas      01/17/10 16:15      
      PWM IRQ code in C, bitops, 45 byte      Frieder Ferlemann      01/18/10 05:19      
         Optimization having no effect.      Yash Chitalia      01/18/10 11:36      
      PWM IRQ code in C, lookup table, 32 byte      Frieder Ferlemann      01/18/10 05:29      
         I haven't understood the table lookup concept very well...      Yash Chitalia      01/19/10 00:55      
            table lookup      Frieder Ferlemann      01/19/10 02:39      
         PWM IRQ code in C, lookup table, 30 byte      Frieder Ferlemann      01/19/10 03:07      
            Compiler specifics      Andy Neil      01/19/10 04:35      
               absolutely-locating xdata at 256 byte boundary      Frieder Ferlemann      01/19/10 05:00      
                  I see.      Andy Neil      01/19/10 06:34      
            An example code..      Yash Chitalia      01/20/10 02:20      
               Keil: Specifics and non-specifics      Andy Neil      01/20/10 02:50      
                  Not really working...      Yash Chitalia      01/20/10 03:55      
                     Enough power?      Per Westermark      01/20/10 09:45      
                        RE: running 32 servo motors      Andy Neil      01/20/10 10:34      
      The chip sounds perfect...      Yash Chitalia      01/18/10 11:47      
         not worth it      Erik Malund      01/18/10 12:10      
            Servo control will become difficult then...      Yash Chitalia      01/18/10 12:42      
               output      Andy Peters      01/18/10 12:52      
               HCT chips have ...      Erik Malund      01/18/10 14:12      
                  Eval a concept with a single PCA and 3:8 HCT multiplexer?      Frieder Ferlemann      01/18/10 14:36      
               Check their website      Andy Neil      01/18/10 14:44      
                  Here is the code...      Yash Chitalia      01/18/10 15:28      
                     "sbit MTRS=P2^0;" is not OK here      Frieder Ferlemann      01/18/10 16:11      
                        Keil syntax?      Andy Neil      01/18/10 17:36      
                           "#define" not working.."sbit" works      Yash Chitalia      01/18/10 23:32      
                              Yes, you were correct originally!      Andy Neil      01/19/10 01:22      
            Seconded      Andy Neil      01/18/10 12:45      
   Servo_0.1.zip      Murray R. Van Luyn      01/18/10 15:02      
      links      James Hinnant      02/18/10 21:10      
   Eventually feed the guys at http://servomaster.sf.net ?      Frieder Ferlemann      01/18/10 15:12      
      servomaster.sf.net FLOSS      James Hinnant      02/04/10 11:48      
   Maybe of some use...      James Bowmaster      02/10/10 14:40      
      Whoops... found a bug      James Bowmaster      02/10/10 16:35      
         What bug?      Andy Neil      02/10/10 16:41      
            Bug      James Bowmaster      02/10/10 18:47      
   Improved version uploaded      James Bowmaster      02/12/10 21:26      

Back to Subject List