Iki servo motor olunca sorun oluyor !

Başlatan Digimensch, 13 Ocak 2011, 16:40:03

Digimensch

Ben 1 Servo Motoru USB üzerinden istedigim acilarda dönderebiliyorum.
Deneme Kartinda deniyorum sonuc gayet güzel.
Ayni Kodlarima 2.Servo Motoru ekledim yine calisiyor Kodlar ama iki Servo Motor olunca su sorunlar ile karsilasiyorum.
1- Motorun biri dönmeye basllayinca öteki motorda hafif tetikleniyor.
2-Bir süre sonra motorlar Devrenin USB baglantisini kopariyor(saniyorum Fazla akim cekiyorlar bir an)

Simdi arkadaslar su Kodda bu olaylara sebep olan gözünüze carpan Faktörler nelerdir , bana fikirlerinizi yazarsaniz bu sorunu cözebilirim belki.
Fikirlerinizi bekliyorum, simdiden tesekkürler !!
#include <18F4550.h>
#device ADC=10
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL2,CPUDIV1,VREGEN,NOBROWNOUT // 8MHZ
#use delay(clock=48000000)


#use fast_io(b)
#use fast_io(d)
#define USB_HID_DEVICE     TRUE             
#define USB_EP1_TX_ENABLE  USB_ENABLE_INTERRUPT  //Ucnokta1'de Kesme transferi aktif
#define USB_EP1_RX_ENABLE  USB_ENABLE_INTERRUPT    
#define USB_EP1_TX_SIZE    64                    //Ucnokta1 icin maksimum alinacak ve gonderilecek
#define USB_EP1_RX_SIZE    64                    //veri boyutu (64 byte)

#include <flex_lcd.c>
#include <pic18_usb.h>     
#include <USB_Konfigurasyon.h>                //USB konfigurasyon bilgileri bu dosyadan aliniyor
#include <usb.c>   
//////////////

/////////////

#define UcNokta1       1 
#define servono        paket[0]
#define adim           paket[1]
#define port_durum     paket[2]
#define sure           paket[3]

//Gerekli Degiskenler
int paket[64];
int16 x,s1;
int8 servo1 = PIN_B0; 
int8 servo2 = PIN_B1;

void motor_don(int8 motor,int16 duty)
{
      for(x=0;x<25;x++)
      {
      output_high(motor);
      delay_us(duty);
      output_low(motor);
      delay_us(20000-duty);
      }
}
void main(void)
{     
   set_tris_b(0x00);
   output_b(0x00);
   set_tris_d(0x00);
   output_d(0x00);
   
   lcd_init();   //LCD hazirlaniyor
   usb_init();   //USB hazirlaniyor                    
   usb_task();     
   printf(lcd_putc,"USB BAGLANTISI"); //USB baglantisi kurulduysa LCD'de göster
   lcd_gotoxy(1,2);
   printf(lcd_putc,"KURULUYOR...");     //USB baglantisi kurulduysa LCD'de göster
   usb_wait_for_enumeration();         //Cihaz, hazir olana kadar bekle
   
///////LCD'de BAGLANTININ OLUSTUGUNU GÖSTERIYORUZ      
   if(usb_enumerated())    
   output_high(pin_d0);
   lcd_gotoxy(1,1);
   printf(lcd_putc,"\fUSB BAGLANTISI");//USB baglantisi kurulduysa LCD'de göster
   lcd_gotoxy(1,2);
   printf(lcd_putc,"KURULDU !");//USB baglantisi kurulduysa LCD'de göster
   for (;;)
   {
      while(usb_enumerated())
      {
  
         if (usb_kbhit(1))             //Eger pc'den yeni bir paket geldiyse
         {         
         usb_get_packet(UcNokta1, paket, 64); //paketi oku 
         ///////Veri alindiktan sonra Motorun Dönmesi icin gerekli Formul
      s1=adim*2;
      printf(lcd_putc,"\fGel: %ld",s1);
      s1*=10;
      s1=s1+600;
      lcd_gotoxy(1,2);
      printf(lcd_putc,"\Gon: %ld",s1);
      
//////SERVO MOTORU GELEN VERIYE GÖRE HAKARET ETTIRIYORUZ
switch(servono)    // Paketin ilk elemanýndaki komutu oku ve ilgili göreve git
{
case 'i': //SERVO 1
       motor_don(servo1,s1);
      break;
case 'j': //SERVO 2
      motor_don(servo2,s1);
      break;

   }
            }
         }
      }
   }

Digimensch

#1
Bir göz atin su Koda Arkadaslar, neler acaba iki servonun saglikli calismadina engel oluyor olabilir.
Tek servo'da sorun olmuyor , ama iki servo oldumu birbirinden etkileniyorlar.
USB üzerinden 1 karekter ve birde servonun dönmesini belirleyecek süre gönderiyorum.
Kod karektere göre hangi servo calisacak onu belirleyip gönderdigim süreyide o servoya aktariyor ve ilgili servo harekete basliyor.
Ama yukarda belirttigim sorunlar meydana geliyor !!!
Yani...
1- Motorun biri dönmeye basllayinca öteki motorda hafif tetikleniyor.
2-Bir süre sonra motorlar Devrenin USB baglantisini kopariyor(saniyorum Fazla akim cekiyorlar bir an)
(Bu ikinci sorun Motorlari Deneme Kartinda denedigim icin olabilirmi?
Motorlari disardan beslesem dahami iyi olur?)


Amacim 4 veya 5 Servoyu saglikli calistirmak...
Haydu Ustalar !

volkii

sen bu motorları usb üzerinde mi besliyorsun yoksa?

Digimensch

hayir Deneme Kartinin extra 7-23 volt extern besleme özelligi var ordan besliyorum.
sorunu anlatan birde video koyuyuorum umarim yardimci olan arkadaslar olur. !!!
http://rapidshare.com/files/442426483/ServoHata.wmv

Tagli

Servoları normal bekleme döngüsü kullanmadan, kesme ile sürmeyi dene bence. Zaten doğrusu, servo motor hareket etmeyecekse bile sinyal göndermeye devam etmektir. Kesme kullanarak, programa yük bindirmeden çok sayıda servo motora sürekli olarak PWM uygulayabilirsin.

Ben şu yöntemi kullanıyorum: Timer2'yi (başka timer da olur) 100 us'de bir kesme oluşturacak şekilde kuruyorum. Her kesmede bir değişkeni (mesela i diyelim) 1 arttırıyorum. Bu değişkeni bir x değeri ile karşılaştırıyorum, x 10 ile 20 arasında olacak bir değer. Yani kesme kodu şöyle oluyor:
i'yi 1 arttır
i < x ise çıkışa 1 ver
değilse (yani i > x ise) çıkışa 0 ver
i == 400 ise i = 0 yap (periyodun 40 ms olduğunu varsayarsak. Motora göre değişebilir)

Burada servolar yaklaşık 10 kademeli çalışıyor (hesap hatası yapmış olabilirim, pek üzerinde durmadım). Kesme sıklığını arttırıp x değerleriyle oynarsan çözünürlüğü arttırabilirsin ama çok sık kesmeye gitmek sorun çıkarabilir.
Gökçe Tağlıoğlu

Digimensch

#5
yani timer2 ile kesme olsturup
belirli bir süre
(if kesme< 50)
PIN_B0 high
belirli bir süre 5 kesme boyunca PIN_B0 high yap

if(kesme>50)
PIN_B0 low
50 kesmeden 200 kesmeye kadar yani 150 kesme boyunca  PIN_B0 low yapip

if(kesme =200)
kesme=0
200 kesme olusunca kesmeyi sifirlayip basa dön

Peki bu timer2 kesmesini nasil tetikleyecegim?
Cünü main fonksiyonu icindeki while döngüsüyle devamli usb yi dinlemem gerek.

birde usb den nasil veri göndereyim?
su an 1 char  , birde Byte tipinde sayi gönderiyorum.
char ile , hangi motor dönecek onu belirliyorum
byte ile gelenlede motorun dömesinde gereken duty zamani belirliyorum.. !

Tagli

#6
Verdiğin koddaki "belirli bir süre" ifadesini kaldır. Süre zaten kesme ile belirleniyor, yani kesmenin içinde bekleme olmuyor. Örneğin x == 15 ise, yani motoru 1.5 ms ile ortaya konumlamak istiyorsan, 15 kesme boyunca bacak 1 oluyor, sonraki 200 - 15 = 185 kesme boyunca (yani 18.5 ms) 0 oluyor.

Timer2'nin kurulumu işlemci hızına göre (yani clock frekansına göre) değişecektir. Bu değerleri ve PIC modelini yazarsan bir örnek verebilirim. Yani kullandığın kristal ve osilatör ayarlarına göre hesap değişir. Bir kez kurduktan sonra timer ana programdan bağımsız olarak çalışır. Yapman gereken tek şey ilgili motor için ana programda x değerini güncellemek.

Malesef USB ile hiç uğraşmadım, bu yüzden o konuda yardımcı olmam mümkün değil.

Ekleme: Şimdi farkettim iletini değiştirmişsin. Şu durumda yazdığın şey yukarıdaki açıklamama uymuş gibi gözüküyor.
Gökçe Tağlıoğlu

Digimensch

belirli bir süre ile kastim if();  fonksiyonu.
kullandigim pic 18F4550
Deneme kartinda 8 MHZ'li kristal
ve clock=48000000

Tagli

Hesabı yanlış yapmadıysam şu şekilde yazarsan 100 us'de bir taşacak şekilde ayarlamış olursun.

PR2 = 74;
T2CON = 0b00000110; //Prescaler 16 oluyor ve timer çalışmaya başlıyor

Kesme ayarlarını sana bırakıyorum. Yapman gereken TMR2 kesmesini açmak. Kesme önceliği belirlemek de isteyebilirsin, ama başka kesmen yoksa bu ayar gerekmez zaten.
Gökçe Tağlıoğlu

iyildirim

@Tagli

Arkadaşım biliyorsan 18F serisi ile TIMER kullanılarak 50hz elde edilebilirmi. Sanki daha önceki diğer başlıklarıdan bu konuda sıkıntı var, bu kadar düşük frekansa düşülemiyor gibi birşeyler hatırlar gibiyim ancak emin de değilim.

Digimensch

#10
Alıntı yapılan: Tagli - 14 Ocak 2011, 00:23:31
Hesabı yanlış yapmadıysam şu şekilde yazarsan 100 us'de bir taşacak şekilde ayarlamış olursun.

PR2 = 74;
T2CON = 0b00000110; //Prescaler 16 oluyor ve timer çalışmaya başlıyor

Kesme ayarlarını sana bırakıyorum. Yapman gereken TMR2 kesmesini açmak. Kesme önceliği belirlemek de isteyebilirsin, ama başka kesmen yoksa bu ayar gerekmez zaten.

   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_110); 
   set_timer0(74);

Yani her 100 us'de  bir kesme mi olusturacak?

seklindemi?

Tagli

CCS C bilmiyorum. Ben kodu C18'de yazmıştım. Ama yukarıda geçenler register isimleri. O şekliyle CCS C'de de çalışyor olmaları gerekir.

Senin yazdığın gibi değil ama sanırım. TMR2'nin kendisiyle oynamıyorsun, PR2'yi ayarlaman lazım.

iyildirim, düşük frekans sınırlaması donanımsal PWM modülü kullanıldığında ortaya çıkıyor. Ayrıca kesme saniyede 10 bin kez gelecek, bu 50 Hz yapmaz, 10 kHz yapar.
Yakın zamanda açılan bir başlıkta ise yüksek frekans elde edilememesi gibi bir durum vardı.
Gökçe Tağlıoğlu

Digimensch

#12
@tagli tesekkür ederim Hocam.
Ama kafam karisti inan...

CCS den anlayan arkadaslarin yardimlarini bekliyorum.
Acaba yukarda yazdigim Kodlarda nelere dikkat etmeliyim?
Neleri degistirirsem yukarda yazmis oldugum sorunlari ortadan kaldirabailirim??

necati

//PicUSB.h
/////////////////////////////////////////////////////////////////////////
////                            PicUSB.h                             ////
////                                                                 ////
//// Este ejemplo muestra como configurar el dispositivo USB y sus   ////
//// descriptores. Los únicos cambios con respecto a su verión       ////
//// original (usb_desc_scope.h) han sido realizados en el apartado  ////
//// start device descriptors, concretamente el vendor y product id  ////
//// y en apartado de start string descriptors, para definir el      ////
//// nombre del dispositivo y la compañía.                           ////
////                                                                 ////
//// Realizado con el compilador CCS PCWH 3.227                      ////
////                                                                 ////
//// Por: Jaime Fernández-Caro Belmonte        hobbypic@hotmail.com  ////
////                                                                 ////
//// http://www.hobbypic.com                                         ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
////   Editado posteriormente por: Guillermo N.              ////
////                   (Solamente el PID y VID)            ////
////                                                                 ////
////   Utilizando la versión 4.023 del mismo compilador              ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////


#IFNDEF __USB_DESCRIPTORS__
#DEFINE __USB_DESCRIPTORS__

#include <usb.h>

//////////////////////////////////////////////////////////////////
///
///   start config descriptor
///   right now we only support one configuration descriptor.
///   the config, interface, class, and endpoint goes into this array.
///
//////////////////////////////////////////////////////////////////

   #DEFINE USB_TOTAL_CONFIG_LEN      32 //config+interface+class+endpoint

   //configuration descriptor
   char const USB_CONFIG_DESC[] = {
   //config_descriptor for config index 1
         USB_DESC_CONFIG_LEN,     //length of descriptor size
         USB_DESC_CONFIG_TYPE,         //constant CONFIGURATION (0x02)
         USB_TOTAL_CONFIG_LEN,0,  //size of all data returned for this config
         1,      //number of interfaces this device supports
         0x01,                //identifier for this configuration.  (IF we had more than one configurations)
         0x00,                //index of string descriptor for this configuration
         0xC0,                //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 reserved and bit7=1
         0x32,                //maximum bus power required (maximum milliamperes/2)  (0x32 = 100mA)

   //interface descriptor 0 alt 0
         USB_DESC_INTERFACE_LEN,  //length of descriptor
         USB_DESC_INTERFACE_TYPE,      //constant INTERFACE (0x04)
         0x00,                //number defining this interface (IF we had more than one interface)
         0x00,                //alternate setting
         2,       //number of endpoints, not counting endpoint 0.
         0xFF,                //class code, FF = vendor defined
         0xFF,                //subclass code, FF = vendor
         0xFF,                //protocol code, FF = vendor
         0x00,                //index of string descriptor for interface

   //endpoint descriptor
         USB_DESC_ENDPOINT_LEN, //length of descriptor
         USB_DESC_ENDPOINT_TYPE,     //constant ENDPOINT (0x05)
         0x81,              //endpoint number and direction (0x81 = EP1 IN)
         0x02,              //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
         USB_EP1_TX_SIZE,0x00,         //maximum packet size supported
         0x01,              //polling interval in ms. (for interrupt transfers ONLY)

   //endpoint descriptor
         USB_DESC_ENDPOINT_LEN, //length of descriptor
         USB_DESC_ENDPOINT_TYPE,     //constant ENDPOINT (0x05)
         0x01,              //endpoint number and direction (0x01 = EP1 OUT)
         0x02,              //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
         USB_EP1_RX_SIZE,0x00,         //maximum packet size supported
         0x01,              //polling interval in ms. (for interrupt transfers ONLY)

  };

   //****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ********
   //since we can't make pointers to constants in certain pic16s, this is an offset table to find
   //  a specific descriptor in the above table.

   //NOTE: DO TO A LIMITATION OF THE CCS CODE, ALL HID INTERFACES MUST START AT 0 AND BE SEQUENTIAL
   //      FOR EXAMPLE, IF YOU HAVE 2 HID INTERFACES THEY MUST BE INTERFACE 0 AND INTERFACE 1
   #define USB_NUM_HID_INTERFACES   0

   //the maximum number of interfaces seen on any config
   //for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2
   #define USB_MAX_NUM_INTERFACES   1

   //define how many interfaces there are per config. 
  • is the first config, etc.
       const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={1};

       #if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN)
          #error USB_TOTAL_CONFIG_LEN not defined correctly
       #endif


    //////////////////////////////////////////////////////////////////
    ///
    ///   start device descriptors
    ///
    //////////////////////////////////////////////////////////////////

       //device descriptor
       char const USB_DEVICE_DESC[] ={
             USB_DESC_DEVICE_LEN,          //the length of this report
             0x01,                //constant DEVICE (0x01)
             0x10,0x01,           //usb version in bcd
             0x00,                //class code (if 0, interface defines class.  FF is vendor defined)
             0x00,                //subclass code
             0x00,                //protocol code
             USB_MAX_EP0_PACKET_LENGTH,   //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8)
             0x25,0x09,           //vendor id (0x0925)
             0x31,0x12,           //product id, (0x1231)
             0x01,0x00,           //device release number
             0x01,                //index of string description of manufacturer. therefore we point to string_1 array (see below)
             0x02,                //index of string descriptor of the product
             0x00,                //index of string descriptor of serial number
             USB_NUM_CONFIGURATIONS   //number of possible configurations
       };


    //////////////////////////////////////////////////////////////////
    ///
    ///   start string descriptors
    ///   String 0 is a special language string, and must be defined.  People in U.S.A. can leave this alone.
    ///
    ///   You must define the length else get_next_string_character() will not see the string
    ///   Current code only supports 10 strings (0 thru 9)
    ///
    //////////////////////////////////////////////////////////////////

    //the offset of the starting location of each string.
    //offset[0] is the start of string 0, offset[1] is the start of string 1, etc.
    const char USB_STRING_DESC_OFFSET[]={0,4,12};

    #define USB_STRING_DESC_COUNT sizeof(USB_STRING_DESC_OFFSET)

    char const USB_STRING_DESC[]={
       //string 0
             4, //length of string index
             USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
             0x09,0x04,   //Microsoft Defined for US-English
       //string 1 --> la compañia del producto ???
             8, //length of string index
             USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
             'J',0,
             '1',0,
             'M',0,
       //string 2 --> nombre del dispositivo
             22, //length of string index
             USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
             'J',0,
             '1',0,
             'M',0,
             ' ',0,
             'P',0,
             'i',0,
             'c',0,
             'U',0,
             'S',0,
             'B',0
    };

    #ENDIF
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //pic18_servo16.c
    #include <18F4550.h>
    #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN,NOBROWNOUT
    #use delay(clock=48000000)//48MHz

    #USE RS232 (baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7)

    //#build(reset=0x000800,interrupt=0x000808:0x000818)
    // Necesario para indicarle al compilador a partir de donde alojar mi programa
    // Si se quiere usar bootloader se pueden habilitar estás dos líneas
    //#ORG 0x000, 0x07FF {} // Espacio reservado para alojar el bootloader

    #byte PORTA = 0xF80// Son las direcciones de memoria de los puertos en este PIC
    #byte PORTB = 0xF81
    #byte PORTC = 0xF82
    #byte PORTD = 0xF83
    #byte PORTE = 0xF84

    /////////////////////////////////////////////////////////////////////////////
    //
    // CCS Library dynamic defines.  For dynamic configuration of the CCS Library
    // for your application several defines need to be made.  See the comments
    // at usb.h for more information
    //
    /////////////////////////////////////////////////////////////////////////////
    #define USB_HID_DEVICE     FALSE             //deshabilitamos el uso de las directivas HID
    #define USB_EP1_TX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
    #define USB_EP1_RX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
    #define USB_EP1_TX_SIZE    2                 //size to allocate for the tx endpoint 1 buffer
    #define USB_EP1_RX_SIZE    2                 //size to allocate for the rx endpoint 1 buffer

    /////////////////////////////////////////////////////////////////////////////
    //
    // If you are using a USB connection sense pin, define it here.  If you are
    // not using connection sense, comment out this line.  Without connection
    // sense you will not know if the device gets disconnected.
    //       (connection sense should look like this:
    //                             100k
    //            VBUS-----+----/\/\/\/\/\----- (I/O PIN ON PIC)
    //                     |
    //                     +----/\/\/\/\/\-----GND
    //                             100k
    //        (where VBUS is pin1 of the USB connector)
    //
    /////////////////////////////////////////////////////////////////////////////
    //#define USB_CON_SENSE_PIN PIN_B2  //CCS 18F4550 development kit has optional conection sense pin

    /////////////////////////////////////////////////////////////////////////////
    //
    // Include the CCS USB Libraries.  See the comments at the top of these
    // files for more information
    //
    /////////////////////////////////////////////////////////////////////////////
    #include <pic18_usb.h>     //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
    #include <PicUSB.h>        //Configuración del USB y los descriptores para este dispositivo
    #include <usb.c>           //handles usb setup tokens and get descriptor reports

    #use fast_io(A)
    #use fast_io(B)
    #use fast_io(C)
    #use fast_io(D)
    #use fast_io(E)

    #bit servo_00     = PORTB.0
    #bit servo_01     = PORTB.1
    #bit servo_02     = PORTB.2
    #bit servo_03     = PORTB.3
    #bit servo_04     = PORTB.4
    #bit servo_05     = PORTB.5
    #bit servo_06     = PORTB.6
    #bit servo_07     = PORTB.7

    #bit servo_08     = PORTD.0
    #bit servo_09     = PORTD.1
    #bit servo_10     = PORTD.2
    #bit servo_11     = PORTD.3
    #bit servo_12     = PORTD.4
    #bit servo_13     = PORTD.5
    #bit servo_14     = PORTD.6
    #bit servo_15     = PORTD.7

    #define i_usb     recibe[0]// es el índice que se recibe vía usb
    #define pos_usb   recibe[1]// es la posición que se recibe vía usb

    #define n 16// número de servos
                //para otro número de servos hay que hacer mediciones de tiempo

    #define max_theCount 200// 200*100us=20ms
    #define derecha  25// 25*100us=2,5ms
    #define centro   15// 15*100us=1,5ms
    #define izquierda 5// 5*100us =0,5ms

    #define val_timer0 127

    int8    theCount=1;
    int8    duty[n];

    #INT_TIMER0
    void isr_timer0(){
       delay_cycles(5);
       if (duty[0] >= theCount)// Cada 100us llega aqui de forma cíclica
          {
             servo_00=1;
          }
          else
          {
             servo_00=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[1] >= theCount)
          {
             servo_01=1;
          }
          else
          {
             servo_01=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[2] >= theCount)
          {
             servo_02=1;
          }
          else
          {
             servo_02=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[3] >= theCount)
          {
             servo_03=1;
          }
          else
          {
             servo_03=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[4] >= theCount)
          {
             servo_04=1;
          }
          else
          {
             servo_04=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[5] >= theCount)
          {
             servo_05=1;
          }
          else
          {
             servo_05=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[6] >= theCount)
          {
             servo_06=1;
          }
          else
          {
             servo_06=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[7] >= theCount)
          {
             servo_07=1;
          }
          else
          {
             servo_07=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[8] >= theCount)
          {
             servo_08=1;
          }
          else
          {
             servo_08=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[9] >= theCount)
          {
             servo_09=1;
          }
          else
          {
             servo_09=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[10] >= theCount)
          {
             servo_10=1;
          }
          else
          {
             servo_10=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[11] >= theCount)
          {
             servo_11=1;
          }
          else
          {
             servo_11=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[12] >= theCount)
          {
             servo_12=1;
          }
          else
          {
             servo_12=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[13] >= theCount)
          {
             servo_13=1;
          }
          else
          {
             servo_13=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[14] >= theCount)
          {
             servo_14=1;
          }
          else
          {
             servo_14=0;
             #asm
                nop
             #endasm
          }
         
          if (duty[15] >= theCount)
          {
             servo_15=1;
          }
          else
          {
             servo_15=0;
             #asm
                nop
             #endasm
          }
         
          theCount=theCount+1;
          if (theCount>max_theCount)
          {
             theCount=1;
          }
          else
          {
             delay_us(1);
             #asm
                nop
             #endasm
          }
          set_timer0(val_timer0);
    }

    /////////////////////////////////////// PRINCIPAL /////////////////////////////////////

    void main()
    {
        int     k;
        int8    i=0;// es el índice exclusivo de duty[] en la recepción serial
        int1    band=0;
        int8    recibe[2];// Buffer de recepción vía usb                 
      //int8    envia[2];// Habilitar en caso de necesitar
       
        set_tris_b(0x00);
        set_tris_c(0b10000000);
        set_tris_d(0x00);
       
        PORTB=0x00;
        PORTD=0x00;
       
        port_b_pullups(FALSE);
       
        for(k=0;k<=(n-1);k++)
          duty[k]=centro;//

        setup_adc_ports(NO_ANALOGS);
        setup_adc(ADC_OFF);

        setup_timer_0(RTCC_DIV_8 | RTCC_8_BIT);

        set_timer0(val_timer0);
       
        enable_interrupts(INT_TIMER0);
        enable_interrupts(GLOBAL);
       
        usb_init();//inicializamos el USB

        usb_task();//habilita periférico usb e interrupciones
        usb_wait_for_enumeration();//esperamos hasta que el PicUSB sea configurado por el host

       while (TRUE)
       {
          if(usb_enumerated())//si el PicUSB está configurado
             //if (TRUE)
          {
    // Recepción de datos via rs232
             if (kbhit()){
                if (band==0){
                   i=getc();
                   band=1;
                }
                else{
                   duty=getc();
                   band=0;   
                }
             }
    // Recepción vía USB         
             if (usb_kbhit(1))//El endpoint de salida contiene datos del host (EP1)?
             {
                usb_get_packet(1, recibe, 2);// Recibimos los 2 bytes: (servo,pos)
                duty[i_usb]=pos_usb;
             }
          }
       }
    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
[email]entegreterbiyecisi@yahoo.com[/email]

Digimensch

@Necati
süpeeeeeer Dostum cok saol.
Kod calisyor hemde 15 servo kontrol edebilecek sekilde.
Kodu calistirdim USB'den iki byte lik veri gönderiliyor ben koddan anladigim kadari ile
1. Veri 0-15 arasi
2.Veriyi tam cikartamadim ama rast gele sayilar göderdim servo calisiyor.
Ama birde tam gönderecegim veriyi yazarsan veya anlayan arkadaslar yazarsalrsa tam süper olacak !!!

tekrardan tesekkürler...