PDA

View Full Version : PIC 18f2550 USB joystick TROUBLE (burnt PIC?)



jsags1
- 17th October 2014, 04:22
hello everyone, i finished my 2 axis and 7 button joystick, plugged it into my PC and checked the device manager and everything was working OK

then i unplugged the device and went on with my life....


later, idecided to check my device again and plugged it back into the PC, "unknown Device" showed up on the device manager, i uninstalled the controler for this "unknown Device" and unplugged and plugged back in and i still get unknown device from the device manager.

i was wondering if there is something that went wrong with my coding or with my circuit (maybe i burnt my PIC for some reason) i will attach my code and my schematic for reference.

maybe i did something wrong, please advice me. this would be greatly appreciated :D

Schemmatic;

ignore the LEDS on the diagram (i did not place those there) and C3 is 330nf instead of 470nf

on the outputs you see in the CODE i used an LED connected to a 4kohm resistor an then to GND

i also connected POTS of 2khoms to AN0 and AN1 (RA0 and RA1)

7476

CODE:

' ************************************************** **********
' * Auto generated EasyHID file. PBP 2.60 and above *
' ************************************************** **********


' include the HID descriptor
include "DESCEGGJOY.bas"


DEFINE OSC 48
DEFINE LOADER_USED 1


USBBufferSizeMax con 3 ' maximum buffer size
USBBufferSizeTX con 3 ' input


Define ADC_BITS 8 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 100 ' Set sampling time in uS


' the USB buffer...
USBBuffer Var Byte
USBBufferCount Var Byte
' Define ADCIN parameters




PORTB = 0 'clear ports
PORTA = 0
PORTC = 0
TRISC = 000000 'all are outputs
TRISA = 010011 'ra0/1/4 are inputs
TRISB = 111111 'rb0-5 are outputs


ADCON1 = 001101 'AN0 and AN1 are inputs (RA0 and RA1)


' ************************************************** **********
' * main program loop - remember, you must keep the USB *
' * connection alive with a call to USBService every couple *
' * of milliseconds or so... *
' ************************************************** **********
usbinit ' initialise USB...


ProgramStart:




ADCIN 0,USBBuffer[0]
ADCIN 1,USBBuffer[1]
USBBuffer.0(16) = porta.4
portc.0 = porta.4
USBBuffer.0(17) = porta.1
portc.1 = portb.1
USBBuffer.0(18) = portb.2
portc.2 = portb.2
USBBuffer.0(19) = portb.3
portc.6 = portb.3
USBBuffer.0(20) = portb.4
portc.7 = portb.4
USBBuffer.0(21) = portb.5
USBBuffer.0(22) = portb.6

gosub DoUSBOut
goto ProgramStart




' ************************************************** **********
' * wait for USB interface to attach *
' ************************************************** **********
DoUSBOut:
USBBufferCount = USBBufferSizeTX ' TX buffer size
USBService ' keep connection alive
USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data
return

[U]
DESCRIPTOR:

' USB descriptors for a HID device
'USBMEMORYADDRESS Con $400 ' USB RAM starts here (set in device header file)
USBMEMORYSIZE Con 256 ' USB RAM size in bytes
USBReservedMemory Var Byte[USBMEMORYSIZE] USBMEMORYADDRESS ' Reserve memory used by USB assembler code


goto hid_desc_end ' Skip over all of the USB assembler code
asm


#define USB_EP0_BUFF_SIZE 64 ; 8, 16, 32, or 64
#define USB_MAX_NUM_INT 1 ; For tracking Alternate Setting
#define USB_MAX_EP_NUMBER 1 ; UEP1
#define NUM_CONFIGURATIONS 1
#define NUM_INTERFACES 1


#define UCFG_VAL USB_PULLUP_ENABLE|USB_INTERNAL_TRANSCEIVER|USB_FUL L_SPEED|USB_PING_PONG__NO_PING_PONG
;#define UCFG_VAL USB_PULLUP_ENABLE|USB_INTERNAL_TRANSCEIVER|USB_LOW _SPEED|USB_PING_PONG__NO_PING_PONG


;#define USE_SELF_POWER_SENSE_IO
;#define USE_USB_BUS_SENSE_IO


#define USB_POLLING


; HID
; Endpoints Allocation
#define HID_INTF_ID 0x00
#define HID_EP 1
#define HID_INT_OUT_EP_SIZE 64
#define HID_INT_IN_EP_SIZE 64
#define HID_NUM_OF_DSC 1


include "usb_hid.asm" ; Include rest of USB files, starting with HID class code


; ************************************************** ****************
; This table is polled by the host immediately after USB Reset has been released.
; This table defines the maximum packet size EP0 can take.
; See section 9.6.1 of the Rev 1.0 USB specification.
; These fields are application DEPENDENT. Modify these to meet
; your specifications.
; ************************************************** ****************
DeviceDescriptor
retlw (EndDeviceDescriptor-DeviceDescriptor)/2 ; bLength Length of this descriptor
retlw USB_DESCRIPTOR_DEVICE ; bDescType This is a DEVICE descriptor
retlw 0x10 ; bcdUSBUSB Revision 1.10 (low byte)
retlw 0x01 ; high byte
retlw 0x00 ; bDeviceClass zero means each interface operates independently
retlw 0x00 ; bDeviceSubClass
retlw 0x00 ; bDeviceProtocol
retlw USB_EP0_BUFF_SIZE ; bMaxPacketSize for EP0


; idVendor (low byte, high byte)
retlw 0x81
retlw 0x17


; idProduct (low byte, high byte)
retlw 0xD8
retlw 0x07


retlw 0x00 ; bcdDevice (low byte)
retlw 0x00 ; (high byte)
retlw 0x01 ; iManufacturer (string index)
retlw 0x02 ; iProduct (string index)


; iSerialNumber (string index)
retlw 0x03
retlw NUM_CONFIGURATIONS ; bNumConfigurations
EndDeviceDescriptor


; ************************************************** ****************
; This table is retrieved by the host after the address has been set.
; This table defines the configurations available for the device.
; See section 9.6.2 of the Rev 1.0 USB specification (page 184).
; These fields are application DEPENDENT.
; Modify these to meet your specifications.
; ************************************************** ****************
; Configuration pointer table
USB_CD_Ptr
Configs
db low Config1, high Config1
db upper Config1, 0


; Configuration Descriptor
Config1
retlw (Interface1-Config1)/2 ; bLength Length of this descriptor
retlw USB_DESCRIPTOR_CONFIGURATION ; bDescType 2=CONFIGURATION
Config1Len
retlw low ((EndConfig1 - Config1)/2) ; Length of this configuration
retlw high ((EndConfig1 - Config1)/2)
retlw 0x01 ; bNumInterfaces Number of interfaces
retlw 0x01 ; bConfigValue Configuration Value
retlw 0x00 ; iConfig (string index)
retlw _DEFAULT|_SELF ; bmAttributes attributes - bus powered


; Max power consumption (2X mA)
retlw 0x32
Interface1
retlw (HIDDescriptor1-Interface1)/2 ; length of descriptor
retlw USB_DESCRIPTOR_INTERFACE
retlw 0x00 ; number of interface, 0 based array
retlw 0x00 ; alternate setting
retlw 0x02 ; number of endpoints used in this interface
retlw 0x03 ; interface class - assigned by the USB
retlw 0x00 ; boot device
retlw 0x00 ; interface protocol
retlw 0x00 ; index to string descriptor that describes this interface
HIDDescriptor1
retlw (Endpoint1In-HIDDescriptor1)/2 ; descriptor size (9 bytes)
retlw DSC_HID ; descriptor type (HID)
retlw 0x11 ; HID class release number (1.11)
retlw 0x01
retlw 0x00 ; Localized country code (none)
retlw 0x01 ; # of HID class descriptor to follow (1)
retlw 0x22 ; Report descriptor type (HID)
ReportDescriptor1Len
retlw low ((EndReportDescriptor1-ReportDescriptor1)/2)
retlw high ((EndReportDescriptor1-ReportDescriptor1)/2)
Endpoint1In
retlw (EndPoint1Out-Endpoint1In)/2 ; length of descriptor
retlw USB_DESCRIPTOR_ENDPOINT
retlw HID_EP|_EP_IN ; EP1, In
retlw _INT ; Interrupt
retlw low (HID_INT_IN_EP_SIZE) ; This should be the size of the endpoint buffer
retlw high (HID_INT_IN_EP_SIZE)
retlw 0x0A ; Polling interval
EndPoint1Out
retlw (EndConfig1-EndPoint1Out)/2 ; Length of this Endpoint Descriptor
retlw USB_DESCRIPTOR_ENDPOINT ; bDescriptorType = 5 for Endpoint Descriptor
retlw HID_EP|_EP_OUT ; Endpoint number & direction
retlw _INT ; Transfer type supported by this Endpoint
retlw low (HID_INT_OUT_EP_SIZE) ; This should be the size of the endpoint buffer
retlw high (HID_INT_OUT_EP_SIZE)
retlw 0x0A ; Polling interval
EndConfig1


ReportDescriptor1


retlw 0x05
retlw 0x01 ; USAGE_PAGE (Generic Desktop)
retlw 0x09
retlw 0x04 ; USAGE (Joystick)
retlw 0xa1
retlw 0x01 ; COLLECTION (Application)
retlw 0x09
retlw 0x04 ; USAGE (Joystick)
retlw 0xa1
retlw 0x00 ; COLLECTION (Physical)
retlw 0x09
retlw 0x30 ; USAGE (X)
retlw 0x09
retlw 0x31 ; USAGE (Y)
retlw 0x75
retlw 0x08 ; REPORT_SIZE (8)
retlw 0x95
retlw 0x02 ; REPORT_COUNT (2)
retlw 0x35
retlw 0x00 ; PHYSICAL_MINIMUM (0)
retlw 0x46
retlw 0xff
retlw 0x00 ; PHYSICAL_MAXIMUM (255)
retlw 0x81
retlw 0x03 ; INPUT (Cnst Var Abs)
retlw 0x05
retlw 0x09 ; USAGE_PAGE (Button)
retlw 0x19
retlw 0x01 ; USAGE_MINIMUM (Button 1)
retlw 0x29
retlw 0x07 ; USAGE_MAXIMUM (Button 7)
retlw 0x15
retlw 0x00 ; LOGICAL_MINIMUM (0)
retlw 0x25
retlw 0x01 ; LOGICAL_MAXIMUM (1)
retlw 0x75
retlw 0x01 ; REPORT_SIZE (1)
retlw 0x95
retlw 0x08 ; REPORT_COUNT (8)
retlw 0x81
retlw 0x03 ; INPUT (Cnst Var Abs)
retlw 0xc0 ; END_COLLECTION
retlw 0xc0 ; END_COLLECTION




EndReportDescriptor1


; String pointer table
USB_SD_Ptr
Strings
db low String0, high String0
db upper String0, 0
db low String1, high String1
db upper String1, 0
db low String2, high String2
db upper String2, 0
db low String3, high String3
db upper String3, 0


String0
retlw (String1-String0)/2 ; Length of string
retlw USB_DESCRIPTOR_STRING ; Descriptor type 3
retlw 0x09 ; Language ID (as defined by MS 0x0409)
retlw 0x04


; company name
String1
retlw (String2-String1)/2
retlw USB_DESCRIPTOR_STRING

retlw 'e'
retlw 0x00
retlw 'g'
retlw 0x00
retlw 'g'
retlw 0x00
retlw 'j'
retlw 0x00
retlw 'o'
retlw 0x00
retlw 'y'
retlw 0x00



; product name
String2
retlw (String3-String2)/2
retlw USB_DESCRIPTOR_STRING

retlw 'e'
retlw 0x00
retlw 'g'
retlw 0x00
retlw 'g'
retlw 0x00
retlw 'j'
retlw 0x00
retlw 'o'
retlw 0x00
retlw 'y'
retlw 0x00




; serial number
String3
retlw (String4-String3)/2
retlw USB_DESCRIPTOR_STRING

retlw '0'
retlw 0x00
retlw '0'
retlw 0x00
retlw '0'
retlw 0x00
retlw '1'
retlw 0x00


String4




endasm
hid_desc_end

DaveC3
- 17th October 2014, 13:34
I have made several joy stick projects over the years. A couple of observations.

1. In your ReportDescriptor1, you have only allocated 7 bits (buttons 1 to 7) You either need to change to


retlw 0x01 ; usage minimum (button 1)
retlw 0x29
retlw 0x08 ; usage maximum (button 8)
retlw 0x15
retlw 0x00 ; logical min (0)
retlw 0x25
retlw 0x01 ; logical max (1)
retlw 0x75
retlw 0x01 ; report size (1)
retlw 0x95
retlw 0x08 ; report count (8)


or add a one bit filler.

I have always used 10K pot for analog inputs.

Make sure you loop is less than 10ms or USB will time out.

Hope this helps

Dave

Demon
- 17th October 2014, 14:29
What happens if you reboot and try again?

Robert

jsags1
- 17th October 2014, 16:16
DAVE: i will try all of your solutions to my problem, but how do you explain that the device worked before and all of a sudden it doesnt?

DEMON: i did that and still get "Unknown Device" even o other computers

i will run to the store and buy a new PIC and see if thats what died on me (and maybe some new CAPS and POTS)

Thanks for the help so far guys (lets keep it coming XD )

jsags1
- 17th October 2014, 19:06
SOLVED:

Changed C3 from 330nf (ceramic capacitor) to 470nf (polyester capacitor) and worked like a charm, thanks for the input guys.

i also changed my pots to 10k as you suggested, but i think ill revert to 2Kohm ones since there is less "noise" (jumping between values)