CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How autocalibrate a Joystick (PIC 18f2550)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Alain



Joined: 18 Apr 2006
Posts: 3
Location: France

View user's profile Send private message

How autocalibrate a Joystick (PIC 18f2550)
PostPosted: Tue Apr 18, 2006 10:18 pm     Reply with quote

Hi,

I design a basic controler USB for a Joystick with a PIC 18f2550.

It works fine Smile , but i hope that the joystick was autocalibrate when the controler is plugged.

I think that i need to know Vcenter , Vmax et Vmin but i haven't any idea for use this.


if anyone might offer some assistance?

Thinks

here my HID Descriptor

Code:


const char USB_CLASS_SPECIFIC_DESC[] = {
      0x05, 0x01,       // Usage Page = Generic Desktop
      0x09, 0x04,       // Usage = Joystick
      0xa1, 0x01,       // Collection = Application
      0x05, 0x02,       // Usage Page (Simulation Controls)
      0x09, 0xBB,       // Usage (Throttle)
      0x15, 0x00,       // Logical  Minimum (0)
      0x26, 0xFF,0x00   // Logical  Maximum (255)
      0x35, 0x00,       // Physical Minimum (0)
      0x46, 0xFF,0x00,  // Physical Maximum (255)
      0x75, 0x08,       // Report Size (8)
      0x95, 0x01,       // Report Count (1)
      0x81, 0x02,       // Input (Data,Var,Abs)

      0x05, 0x01,       // Usage Page = Generic Desktop
      0x09, 0x01,       // Usage (Pointer)
      0xA1, 0x00,       // Collection (Physical)
      0x09, 0x30,       // Usage (X)
      0x09, 0x31,       // Usage (Y)
      0x15, 0x81,       // Logical  Minimum (-127)
      0x25, 0x7F,       // Logical  Maximum (+127)
      0x95, 0x02,       // Report Count (2)
      0x81, 0x02,       // Input (Data,Var,Abs)
      0xC0,             // End_Collection

      0x05, 0x09,       // Usage Page (Button)
      0x19, 0x01,       // Usage Minimum (Button1)
      0x29, 0x08,       // Usage Maximum (Button8)
      0x15, 0x00,       // Logical Minimum (0)
      0x25, 0x01,       // Logical Maximum (1)
      0x35, 0x00,       // Physical Minimum (0)
      0x45, 0x01,       // Physical Maximum (1)
      0x95, 0x08,       // Report Count (8)
      0x75, 0x01,       // Report Size (1)
      0x65, 0x00,       // Unit (None)
      0x81, 0x02,       // Input (Data,Var,Abs)
      0xC0              // End Collection

   };



Here the main code

Code:
 

#define Throttle     TxUSB[0]
#define X            TxUSB[1]
#define Y            TxUSB[2]
#define Boutons      TxUSB[3]

   int8 Trim[2];
   int8 TxUSB[5];
   int8 Buffer;

while (TRUE)
   {
      if(usb_enumerated())             //si le PicUSB a �t� configur�
      {

         // Lecture des entr�es analogiques

               set_adc_channel( 0 );   // Selection Voie 0
               delay_us(40);
               Buffer = Read_ADC();    // Lecture du Canal 0 : X
               X = Buffer -128 ;           // Centrage de l'axe � 2.5V
               set_adc_channel( 1 );   // Selection Voie 1
               delay_us(40);
               Buffer = Read_ADC();    // Lecture du Canal 1 : Y
               Y = Buffer -128 ;
               set_adc_channel( 2 );   // Selection Voie 2
               delay_us(40);
               Throttle = Read_ADC();  // Lecture du Canal 2 : Throttle
               set_adc_channel( 3 );   // Selection Voie 3
               delay_us(40);
               Buffer = Read_ADC();    // Lecture du Canal 3 : Rudder
               Rudder = Buffer - 128 ;
               set_adc_channel( 4 );   // Selection Voie 4
               delay_us(40);
               Buffer = Read_ADC();    // Lecture du Canal 4 : Axe ?
               Trim[1] = Buffer - 128 ;
               delay_us(40);

        // Lecture des entr�es num�riques

               Boutons = input_b();

       // Envoie des entr�es sur le port USB

               usb_put_packet(1, TxUSB, 4, USB_DTS_TOGGLE); //envoie d'un paquet de 4 octets sur EP1 vers le PC

               delay_ms(10);

            }

     }
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Wed Apr 19, 2006 12:52 am     Reply with quote

Hm... This might be an interesting problem.

Why do you need to calibrate your joystick every time you plug it into the USB port? You could calibrate it once and store the calibration constants in the PIC's EEPROM.

Could you post the description of your hardware (electrical and mechanical)?

Do you want the calibration to be completely automatic? If not, you could ask the user to do certain manipulations with joystick such as "move the stick all the way to the top-right and press a button" then "move the stick all the way to the bottom-left and press a button".
Guest








PostPosted: Sat Jul 05, 2008 9:47 pm     Reply with quote

does anyone have the full working code for a simple joystick? I'm not sure how I would set the descriptor up.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group