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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/20/10 08:20
Read: times


 
#172609 - An example code..
Responding to: ???'s previous message
I've never really worked with a lookup table before,so I'm not at all sure about my code.There are definately some syntactical errors. But here it is..

#include<reg51.h>
#include<stdio.h>
# define servoport P2
static unsigned char ms_tenth_countdown;

// dynamically setup table.
// Indexed top down.
// setup this table glitchlessly (IRQ save).
// (located absolutely at the start of a 256 byte block)
unsigned char __xdata __at(0x0000) table_P2_over_time[200 + 1];

table_P2_over_time[200 + 1]={0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0d,0x0d,0x0d,0x0d,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
// for executing the function servo(23,10,14,21); of my previous code.

void Timer0_ISR (void) interrupt 1 {

    // assuming P2 is only used for servos.
    P2 = table_P2_over_time [ ms_tenth_countdown ];

    if (!--ms_tenth_countdown)
        ms_tenth_countdown = 200;

    TF0 = 0;
}

void main(void)
{TMOD=0x02;
IE=0x82;
TH0=0xA3;
servoport=0;
ms_tenth_countdown=200;
TR0=1;
for(;;);
}

 


This code is not getting compiled in Keil. The error shown is 'missing ";" before "_at" ', which is probably due to the difference in the syntax of Keil and SDCC.
Problems I am facing:
1) I searched for the right syntax for initializing the lookup in Keil but couldn't find it.
2)The above code is only for one motion( or rather, one position) of the four servos (i.e servo(23,10,14,21)). How do I modify this code for the sequential motion of all the servos?(in other words, for achieving this part of my previous code):
{servo(21,10,14,23);
servo(20,12,14,23);
servo(20,14,14,23);
servo(20,17,14,23);
servo(20,17,17,23);
servo(20,14,14,16);
servo(20,10,12,16);
servo(21,10,14,16);}

 


My guesses for achieving the above are:
i] Build different lookup tables for each position. Each of them with a different name and a different address.
ii]build a switch( ) statement in the ISR. For each position, a variable is given a particualar value(in the main())and that variable is used in the switch( ) function in the ISR.

3) Since "ms_tenth_countdown" is counting down , i.e from 200 to 0, should my lookup table be inverse of what it currently is?


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