Ry, Rz and Back Throttle axis are not working

Discussion in 'General Electronics Chat' started by Omais Ahmed, Oct 4, 2015.

  1. Omais Ahmed

    Thread Starter New Member

    Oct 4, 2015
    7
    0
    Hi,
    I'm using PIC18F2550 the Ry(AN8), Rz(AN9) and back throttle axis are not working, Is the programming right for axis or do I have to configure channel 8 and 9 as a analog? I have one more question I'm making the joystick for flight simulator...need to add back throttle there is no such option in usb descriptor generator how can I add back throttle?

    here is my code and screenshot.

    Code (C):
    1.  
    2. USB.C
    3.  
    4. unsigned char readbuff[64] absolute 0x500;
    5. unsigned char writebuff[64] absolute 0x540;
    6. unsigned char buttons;
    7. unsigned char pov, pov_hat, dig_pov;
    8. char x_axis, y_axis, throttle=0, rudder=0, Rx, Ry, Rz;   // signed char
    9.  
    10. void interrupt()
    11. {
    12.      USB_Interrupt_Proc();        // USB servicing is done inside the interrupt
    13. }
    14.  
    15. void main()
    16. {
    17.  
    18.  
    19.  
    20.  
    21.         HID_Enable(readbuff,writebuff);
    22.  
    23.         while(1)
    24.         {
    25.  
    26.                 //Joystick Axes
    27.                 x_axis=(ADC_Read(0)>>2)-128;      //Read only the upper 8 bits of the ADC
    28.                 y_axis=(ADC_Read(1)>>2)-128;
    29.                 rudder=(ADC_Read(2)>>2)-128;
    30.                 throttle=(ADC_Read(3)>>2)-128;
    31.                 Rx=(ADC_Read(4)>>2)-128;
    32.                 Ry=(ADC_Read(8)>>2)-128;
    33.                 Rz=(ADC_Read(9)>>2)-128;
    34.  
    35.                 //USB
    36.                 writebuff[0]=throttle;
    37.                 writebuff[1]=x_axis;
    38.                 writebuff[2]=y_axis;
    39.                 writebuff[3]=rudder;
    40.                 writebuff[4]=Rx;
    41.                 writebuff[8]=Ry;
    42.                 writebuff[9]=Rz;
    43.  
    44.  
    45.                 while(!HID_Write(writebuff,7));
    46.         }
    47. }
    48.  
    49. USB_DESC.C
    50.  
    51. const unsigned int USB_VENDOR_ID = 0x1234;
    52. const unsigned int USB_PRODUCT_ID = 0x0001;
    53. const char USB_SELF_POWER = 0x80;            // Self powered 0xC0,  0x80 bus powered
    54. const char USB_MAX_POWER = 50;               // Bus power required in units of 2 mA
    55. const char HID_INPUT_REPORT_BYTES = 64;
    56. const char HID_OUTPUT_REPORT_BYTES = 64;
    57. const char USB_TRANSFER_TYPE = 0x03;         //0x03 Interrupt
    58. const char EP_IN_INTERVAL = 1;
    59. const char EP_OUT_INTERVAL = 1;
    60.  
    61. const char USB_INTERRUPT = 1;
    62. const char USB_HID_EP = 1;
    63. const char USB_HID_RPT_SIZE = 46;
    64.  
    65. /* Device Descriptor */
    66. const struct {
    67.     char bLength;               // bLength         - Descriptor size in bytes (12h)
    68.     char bDescriptorType;       // bDescriptorType - The constant DEVICE (01h)
    69.     unsigned int bcdUSB;        // bcdUSB          - USB specification release number (BCD)
    70.     char bDeviceClass;          // bDeviceClass    - Class Code
    71.     char bDeviceSubClass;       // bDeviceSubClass - Subclass code
    72.     char bDeviceProtocol;       // bDeviceProtocol - Protocol code
    73.     char bMaxPacketSize0;       // bMaxPacketSize0 - Maximum packet size for endpoint 0
    74.     unsigned int idVendor;      // idVendor        - Vendor ID
    75.     unsigned int idProduct;     // idProduct       - Product ID
    76.     unsigned int bcdDevice;     // bcdDevice       - Device release number (BCD)
    77.     char iManufacturer;         // iManufacturer   - Index of string descriptor for the manufacturer
    78.     char iProduct;              // iProduct        - Index of string descriptor for the product.
    79.     char iSerialNumber;         // iSerialNumber   - Index of string descriptor for the serial number.
    80.     char bNumConfigurations;    // bNumConfigurations - Number of possible configurations
    81. } device_dsc = {
    82.       0x12,                   // bLength
    83.       0x01,                   // bDescriptorType
    84.       0x0200,                 // bcdUSB
    85.       0x00,                   // bDeviceClass
    86.       0x00,                   // bDeviceSubClass
    87.       0x00,                   // bDeviceProtocol
    88.       8,                      // bMaxPacketSize0
    89.       USB_VENDOR_ID,          // idVendor
    90.       USB_PRODUCT_ID,         // idProduct
    91.       0x0001,                 // bcdDevice
    92.       0x01,                   // iManufacturer
    93.       0x02,                   // iProduct
    94.       0x00,                   // iSerialNumber
    95.       0x01                    // bNumConfigurations
    96.   };
    97.  
    98. /* Configuration 1 Descriptor */
    99. const char configDescriptor1[]= {
    100.     // Configuration Descriptor
    101.     0x09,                   // bLength             - Descriptor size in bytes
    102.     0x02,                   // bDescriptorType     - The constant CONFIGURATION (02h)
    103.     0x29,0x00,              // wTotalLength        - The number of bytes in the configuration descriptor and all of its subordinate descriptors
    104.     1,                      // bNumInterfaces      - Number of interfaces in the configuration
    105.     1,                      // bConfigurationValue - Identifier for Set Configuration and Get Configuration requests
    106.     0,                      // iConfiguration      - Index of string descriptor for the configuration
    107.     USB_SELF_POWER,         // bmAttributes        - Self/bus power and remote wakeup settings
    108.     USB_MAX_POWER,          // bMaxPower           - Bus power required in units of 2 mA
    109.  
    110.     // Interface Descriptor
    111.     0x09,                   // bLength - Descriptor size in bytes (09h)
    112.     0x04,                   // bDescriptorType - The constant Interface (04h)
    113.     0,                      // bInterfaceNumber - Number identifying this interface
    114.     0,                      // bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber.
    115.     2,                      // bNumEndpoint - Number of endpoints supported not counting endpoint zero
    116.     0x03,                   // bInterfaceClass - Class code
    117.     0,                      // bInterfaceSubclass - Subclass code
    118.     0,                      // bInterfaceProtocol - Protocol code
    119.     0,                      // iInterface - Interface string index
    120.  
    121.     // HID Class-Specific Descriptor
    122.     0x09,                   // bLength - Descriptor size in bytes.
    123.     0x21,                   // bDescriptorType - This descriptor's type: 21h to indicate the HID class.
    124.     0x01,0x01,              // bcdHID - HID specification release number (BCD).
    125.     0x00,                   // bCountryCode - Numeric expression identifying the country for localized hardware (BCD) or 00h.
    126.     1,                      // bNumDescriptors - Number of subordinate report and physical descriptors.
    127.     0x22,                   // bDescriptorType - The type of a class-specific descriptor that follows
    128.     USB_HID_RPT_SIZE,0x00,  // wDescriptorLength - Total length of the descriptor identified above.
    129.  
    130.     // Endpoint Descriptor
    131.     0x07,                   // bLength - Descriptor size in bytes (07h)
    132.     0x05,                   // bDescriptorType - The constant Endpoint (05h)
    133.     USB_HID_EP | 0x80,      // bEndpointAddress - Endpoint number and direction
    134.     USB_TRANSFER_TYPE,      // bmAttributes - Transfer type and supplementary information  
    135.     0x40,0x00,              // wMaxPacketSize - Maximum packet size supported
    136.     EP_IN_INTERVAL,         // bInterval - Service interval or NAK rate
    137.  
    138.     // Endpoint Descriptor
    139.     0x07,                   // bLength - DesÍª        tor size in bytes (07h)
    140.     0x05,                   // bDescriptorType - The constant Endpoint (05h)
    141.     USB_HID_EP,             // bEndpointAddress - Endpoint number and direction
    142.     USB_TRANSFER_TYPE,      // bmAttributes - Transfer type and supplementary information
    143.     0x40,0x00,              // wMaxPacketSize - Maximum packet size supported  
    144.     EP_OUT_INTERVAL         // bInterval - Service interval or NAK rate
    145. };
    146.  
    147. const struct {
    148.   char report[];
    149. }hid_rpt_desc =
    150.   {
    151.      0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    152.     0x15, 0x00,                    // LOGICAL_MINIMUM (0)
    153.     0x09, 0x04,                    // USAGE (Joystick)
    154.     0xa1, 0x01,                    // COLLECTION (Application)
    155.     0x05, 0x02,                    //   USAGE_PAGE (Simulation Controls)
    156.     0x09, 0xbb,                    //   USAGE (Throttle)
    157.     0x15, 0x81,                    //   LOGICAL_MINIMUM (-127)
    158.     0x25, 0x7f,                    //   LOGICAL_MAXIMUM (127)
    159.     0x75, 0x08,                    //   REPORT_SIZE (8)
    160.     0x95, 0x01,                    //   REPORT_COUNT (1)
    161.     0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    162.     0x05, 0x01,                    //   USAGE_PAGE (Generic Desktop)
    163.     0x09, 0x01,                    //   USAGE (Pointer)
    164.     0xa1, 0x00,                    //   COLLECTION (Physical)
    165.     0x09, 0x30,                    //     USAGE (X)
    166.     0x09, 0x31,                    //     USAGE (Y)
    167.     0x09, 0x32,                    //     USAGE (Z)
    168.     0x09, 0x33,                    //     USAGE (Rx)
    169.     0x09, 0x34,                    //     USAGE (Ry)
    170.     0x09, 0x35,                    //     USAGE (Rz)
    171.     0x95, 0x06,                    //     REPORT_COUNT (6)
    172.     0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    173.     0xc0,                          //   END_COLLECTION
    174.     0xc0                           // END_COLLECTION
    175.   };
    176.  
    177. //Language code string descriptor
    178. const struct {
    179.   char bLength;
    180.   char bDscType;
    181.   unsigned int string[1];
    182.   } strd1 = {
    183.       4,
    184.       0x03,
    185.       {0x0409}
    186.     };
    187.  
    188.  
    189. //Manufacturer string descriptor
    190. const struct{
    191.   char bLength;
    192.   char bDscType;
    193.   unsigned int string[11];
    194.   }strd2={
    195.     22,           //sizeof this descriptor string
    196.     0x03,
    197.     {'E','m','i','l',' ','E','n','c','h','e','v'}
    198.   };
    199.  
    200. //Product string descriptor
    201. const struct{
    202.   char bLength;
    203.   char bDscType;
    204.   unsigned int string[15];
    205. }strd3={
    206.     32,          //sizeof this descriptor string
    207.     0x03,
    208.     {'U','S','B',' ','M','a','n','i','p','u','l','a','t','o','r'}
    209. };
    210.  
    211. //Array of configuration descriptors
    212. const char* USB_config_dsc_ptr[1];
    213.  
    214. //Array of string descriptors
    215. const char* USB_string_dsc_ptr[3];
    216.  
    217. void USB_Init_Desc(){
    218.   USB_config_dsc_ptr[0] = &configDescriptor1;
    219.   USB_string_dsc_ptr[0] = (const char*)&strd1;
    220.   USB_string_dsc_ptr[1] = (const char*)&strd2;
    221.   USB_string_dsc_ptr[2] = (const char*)&strd3;
    222. }
    223.  
    Moderators note: used code=c codetags, bold can not be used inside code tags
     
    Last edited by a moderator: Oct 4, 2015
Loading...