PDA

View Full Version : Help, I need use USB with internal oscillator INTOSCIO in 18F25K20



MTH
21st April 2017, 18:03
Hi, I need use the USB in 18F25K20 with internal oscillator (INTOSCIO), and not working, please help me.


The code I'm use is this:


;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings
Device 18F25K50
'Declare Xtal = 48
'Declare PLL_Req = OFF '
'Declare Watchdog =On
Declare All_Digital TRUE
Declare PortB_Pullups = On
'$define _usb_ram 1024 'sin esto da error al compilar!

Config_Start
PLLSEL = PLL3X ;3x clock multiplier
CFGPLLEN = OFF ;PLL Disabled (firmware controlled)
CPUDIV = NOCLKDIV ;CPU uses system clock /2
LS48MHZ = SYS48X8 ;System clock at 48 MHz, USB clock divider is set to 8
FOSC = INTOSCIO ;Internal oscillator
PCLKEN = On ;Primary oscillator enabled
FCMEN = On ;Fail-Safe Clock Monitor disabled
IESO = On ;Oscillator Switchover mode disabled
nPWRTEN = On ;Power up timer disabled
BOREN = SBORDIS ;BOR enabled in hardware (SBOREN is ignored)
BORV = 190 ;BOR set to 1.9V nominal
nLPBOR = On ;Low-Power Brown-out Reset disabled
WDTEN = OFF ;WDT enabled in hardware (SWDTEN ignored)
WDTPS = 32768 ;1:32768
CCP2MX = RC1 ;CCP2 input/output is multiplexed with RC1
PBADEN = On ;PORTB<5:0> pins are configured as analog input channels on Reset
T3CMX = RC0 ;T3CKI function is on RC0
SDOMX = RB3 ;SDO function is on RB3
MCLRE = On ;MCLR pin enabled; RE3 input disabled
STVREN = OFF ;Stack full/underflow will cause Reset
LVP = OFF ;Single-Supply ICSP enabled if MCLRE is also 1
ICPRT = OFF ;ICPORT disabled
XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled
Debug = OFF ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
Cp0 = OFF ;Block 0 is not code-protected
CP1 = OFF ;Block 1 is not code-protected
CP2 = OFF ;Block 2 is not code-protected
CP3 = OFF ;Block 3 is not code-protected
CPB = OFF ;Boot block is not code-protected
CPD = OFF ;Data EEPROM is not code-protected
WRT0 = OFF ;Block 0 (0800-1FFFh) is not write-protected
WRT1 = OFF ;Block 1 (2000-3FFFh) is not write-protected
WRT2 = OFF ;Block 2 (04000-5FFFh) is not write-protected
WRT3 = OFF ;Block 3 (06000-7FFFh) is not write-protected
WRTC = OFF ;Configuration registers (300000-3000FFh) are not write-protected
WRTB = OFF ;Boot block (0000-7FFh) is not write-protected
WRTD = OFF ;Data EEPROM is not write-protected
EBTR0 = OFF ;Block 0 is not protected from table reads executed in other blocks
EBTR1 = OFF ;Block 1 is not protected from table reads executed in other blocks
EBTR2 = OFF ;Block 2 is not protected from table reads executed in other blocks
EBTR3 = OFF ;Block 3 is not protected from table reads executed in other blocks
EBTRB = OFF ;Boot block is not protected from table reads executed in other blocks
Config_End
;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

Dim PP0 As Byte System ' USBPOLL status return
Dim i As Byte
Dim BUFFER[5] As Byte
Dim BUTTONS As Byte
Dim HAT As Byte
Dim Store As Byte
Dim LOOP_COUNT As Byte
Dim POSITION As Byte
Dim INDEX As Byte
Dim Botones As Byte
Dim POVControl As Byte
Symbol CARRY_FLAG = STATUS.0 ' High if microcontroller does not have control over the DP buffer
Symbol TRNIF = UIR.3 ' Low if USB Busy \
Symbol Bot1 = PORTB.0
Symbol Bot2 = PORTB.1
Symbol Bot3 = PORTB.2
Symbol Bot4 = PORTB.3
Symbol Bot5 = PORTB.4
Symbol Bot6 = PORTB.5
Symbol Bot7 = PORTB.6
Symbol Bot8 = PORTB.7
Symbol LedST = PORTC.2
Symbol Pov1 = PORTA.0
Symbol Pov2 = PORTA.1
Symbol Pov3 = PORTA.2
Symbol Pov4 = PORTA.3
Symbol SW1 = PORTC.7
' '// Enable USB interrupt
' PIR3bits_USBIF = 0;
' PIE3bits_USBIE = 1;
'// Disable USB interrupt
' PIE3bits_USBIE = 0;



'---- Ini sacado de (http://www.microchip.com/forums/m727996.aspx) de davekw7x para usar cristal interno de 18f25k50
OSCCON2bits_PLLEN = 0; // Changes in SPLLMULT are ignored unless pll is disabled
OSCTUNEbits_SPLLMULT = 1; // PLL: x3 multiplier Set this before enabling PLL

OSCCON = 0x70; OSCCON = 0x70
'//OSCCONbits.SCS = 0; //Primary clock determined by FOSC<3:0> in CONFIG1H
'//OSCCONbits.IRCF = 7; // Internal RC Oscillator HFINTOSC = 16 MHz
'//OSCCONbits.IDLEN = 0; // Device enters Sleep mode on SLEEP instruction
OSCCON2 = 0x10
'// 0b01110000 : 111 = HFINTOSC (16 MHz)
'// enable the 16 MHz internal clock
'// Primary clock source (HFINTOSC or HSPLL)
'// is defined by FOSC<2:0> (cf. config.h)

OSCCON2 = 0x10;
'//OSCCON2bits.INTSRC = 0; // Low power INTRC as 31.25 reference
'//OSCCON2bits.SOSCGO = 0; // No secondary oscillator unless otherewise requested
'//OSCCON2bits.PRISD = 0; // Enable primary oscillator
'//OSCCON2bits.PLLEN = 1; // Use PLL.
While OSCCON2bits_PLLRDY = 1 ' while (OSCCON2bits.PLLRDY != 1)
Wend

OSCCON2bits_PRISD = 1; '// Disable primary oscillator
'// The following is "probably" not necessary since not doing clock switching
DelayMS 3 '? Delay10KTCYx(3); '// 2.5 milliseconds for 12 MHz instruction clock


'// Enable HFINTOSC to be tuned by the USB clock
ACTCON = 0x90;
'//ACTCONbits.ACTEN = 1;
'//ACTCONbits.ACTSRC = 1;

'---- Fin sacado de (http://www.microchip.com/forums/m727996.aspx) de davekw7x para usar cristal interno de 18f25k50

High LedST
'Test speed with led
For i=0 To 10
Toggle LedST
DelayMS 1000
Next i
ANSELA = 0; // all I/O to Digital mode
ANSELB = 0; // all I/O to Digital mode
ANSELC = 0; // all I/O to Digital mode

' Include "KEY_DescMTH3.INC" ' test 8 hat
Include "USB18_Joystick_8b_Sega_25k50.inc"
' Include "USB18_Joystick_25k50.inc"
' Include "HID1_WIZ.inc"
'Include "CDC_Descriptor.inc"
Declare Reminders = Off
Declare Xtal = 12
Declare PLL_Req = On
'Declare Optimiser_Level = 1
DelayMS 10


Repeat ' \
USBPoll ' Wait for the USB interface to become attached
Until USB_tConnected = 1 Or USB_tConfigured = 1 ' Until PP0 = 000110 ' /


'Main loop
While 1 = 1
Toggle LedST
'Control de botones
'ini botones
Input Bot1
Input Bot2
Input Bot3
Input Bot4
Input Bot5
Input Bot6
Input Bot7
Input Bot8

'BT Star y Mode
Botones.6=Bot7+1
Botones.7=Bot8+1
If SW1=0 Then
Botones.0=Bot1+1
Botones.1=Bot2+1
Botones.2=Bot3+1
Botones.3=Bot4+1
Botones.4=Bot5+1
Botones.5=Bot6+1
Botones.6=Bot7+1
Botones.7=Bot8+1
Else
'
If Bot1=0 Then
Botones.0=Botones.0+1
Else
Botones.0=0
EndIf
'
If Bot2=0 Then
Botones.1=Botones.1+1
Else
Botones.1=0
EndIf
'
If Bot3=0 Then
Botones.2=Botones.2+1
Else
Botones.2=0
EndIf
'
If Bot4=0 Then
Botones.3=Botones.3+1
Else
Botones.3=0
EndIf
'
If Bot5=0 Then
Botones.4=Botones.4+1
Else
Botones.4=0
EndIf
'
If Bot6=0 Then
Botones.5=Botones.5+1
Else
Botones.5=0
EndIf
EndIf
BUFFER[1] = Botones

'Control POV

'ini POV
Input Pov1
Input Pov2
Input Pov3
Input Pov4

'centro
If Pov1=1 And Pov2=1 And Pov3=1 And Pov4=1 Then POVControl=8 'palanca en centro

'normales
If Pov1=0 Then POVControl=0 'UP
If Pov2=0 Then POVControl=4 'DW
If Pov3=0 Then POVControl=2 'RI
If Pov4=0 Then POVControl=6 'LE

'diagonales
If Pov1=0 And Pov3=0 Then POVControl=1
If Pov3=0 And Pov2=0 Then POVControl=3
If Pov2=0 And Pov4=0 Then POVControl=5
If Pov4=0 And Pov1=0 Then POVControl=7

BUFFER[0] = POVControl

Repeat
USBOut 1, BUFFER,2 ' Send the buffer to endpoint 1
Until CARRY_FLAG = 0 ' Keep trying if the microcontroller does not have control over the buffer
'Repeat : Until TRNIF = 1 ' Wait for completion before continuing
Wend

End


This code worked, compiled in old version of the PROTON, but now not working, When I connect board to PC, unknown device error message.

Thanks a lot.

towlerg
21st April 2017, 21:04
Can you post the desciptor USB18_Joystick_8b_Sega_25k50.Inc

MTH
21st April 2017, 23:58
Hi George, thanks for reply. Yes it is this:



$ifndef _HID_DESC_INC_
$define _HID_DESC_INC_
'
' Generated by PDS USB HID Wizard, version 0.2.1.1
'
$define cVID 0x04D8 ' Vendor ID (Keep to 0x format for Hex value)
$define cPID 0x001A ' Product ID (Keep to 0x format for Hex value)
$define cUSB_EP0_BUFF_SIZE 8 ' 8, 16, 32, or 64
$define cUSB_MAX_NUM_INT 1
$define cUSB_MAX_EP_NUMBER 1
$define cUSB_NUM_CONFIGS 1
$define cUSB_NUM_INTERFACES 1
$define cUSB_MAX_POWER 40 ' Maximum power consumption (in MilliAmps)
$define cUSB_POLLING_INTERVAL 1 ' Polling interval (in MilliSeconds)
'$define cUSE_SELF_POWER
'$define cUSE_USB_BUS_SENSE_IO
$ifdef cUSE_USB_BUS_SENSE_IO
Symbol USB_BUS_SENSE_PIN = PORTA.0
$endif
$define cUSB_POLLING
' HID
' Endpoints Allocation
$define cHID_INTF_ID 0
$define cHID_EP 1
$define cHID_INT_OUT_EP_SIZE 8
$define cHID_INT_IN_EP_SIZE 8
$define cHID_NUM_OF_DSC 1
Symbol cUSB_BUFFER_OUT_SIZE = cHID_INT_OUT_EP_SIZE
Symbol cUSB_BUFFER_IN_SIZE = cHID_INT_IN_EP_SIZE
GoTo _DescriptorMain_ ' Jump over the USB code
Include "USB_HID.inc" ' Include the 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.
'
Desc_DeviceDescriptor:
Dt (Desc_EndDeviceDescriptor - Desc_DeviceDescriptor) / 2 ' Size of this descriptor (in bytes)
Dt cUSB_DESCRIPTOR_DEVICE ' Device descriptor type
Dt 0x10, 0x01 ' USB Spec Release Number in BCD format - 1.10 (low byte, high byte)
Dt 0x00 ' Class Code
Dt 0x00 ' Subclass code
Dt 0x00 ' Protocol code
Dt cUSB_EP0_BUFF_SIZE ' Max packet size for EP0
Dt Low(cVID), High(cVID) ' Vendor ID
Dt Low(cPID), High(cPID) ' Product ID
Dt 0x01 ' Device release number in BCD format (low byte)
Dt 0x00 ' (high byte)
Dt 0x01 ' Manufacturer string index
Dt 0x02 ' Product string index
Dt 0x00 ' Device serial number string index
Dt cUSB_NUM_CONFIGS ' Number of possible configurations
Desc_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 Descriptor
'
Desc_Config1:
Dt (Desc_Interface1 - Desc_Config1) / 2 ' Size of this descriptor (in bytes)
Dt cUSB_DESCRIPTOR_CONFIGURATION ' Configuration descriptor type
Desc_Config1Len:
Dt Low((Desc_EndConfig1 - Desc_Config1) / 2),High((Desc_EndConfig1 - Desc_Config1) / 2) ' Total length of data for this cfg
Dt cUSB_NUM_INTERFACES ' Number of interfaces in this cfg
Dt 0x01 ' Index value of this configuration
Dt 0x00 ' Configuration string index
Dt _cDEFAULT | _cSELF ' Attributes
Dt (cUSB_MAX_POWER / 2) ' Max power consumption (in mA)
'
' Interface descriptor
'
Desc_Interface1:
Dt (Desc_HIDDescriptor1 - Desc_Interface1) / 2 ' Size of this descriptor (in bytes)
Dt cUSB_DESCRIPTOR_INTERFACE ' Interface descriptor type
Dt 0x00 ' Interface Number
Dt 0x00 ' Alternate Setting Number
Dt 0x02 ' Number of endpoints in this intf
Dt cHID_INTF ' Class code
Dt 0x00 ' Subclass code
Dt 0x00 ' Protocol code
Dt 0x00 ' Interface string index
'
' HID class-specific descriptor
'
Desc_HIDDescriptor1:
Dt (Desc_Endpoint1Out - Desc_HIDDescriptor1) / 2' Size of this descriptor (in bytes)
Dt cDSC_HID ' HID descriptor type
Dt 0x11, 0x01 ' HID Spec Release Number in BCD format - 1.11 (low byte,high byte)
Dt 0x00 ' Country Code (0x00 for Not supported)
Dt cHID_NUM_OF_DSC ' Number of class descriptors
Dt cDSC_RPT ' Report descriptor type (HID)
Desc_ReportDescriptor1Len:
Dt Low((Desc_EndReportDescriptor1 - Desc_ReportDescriptor1) / 2),High((Desc_EndReportDescriptor1 - Desc_ReportDescriptor1) / 2)
'
' Enpoint descriptor (OUT)
'
Desc_Endpoint1Out:
Dt (Desc_Endpoint1In - Desc_Endpoint1Out) / 2 ' Size of this descriptor (in bytes)
Dt cUSB_DESCRIPTOR_ENDPOINT ' EndPoint descriptor type
Dt cHID_EP | _cEP_OUT ' EndPoint Address
Dt _cINT ' Attributes
Dt Low(cHID_INT_OUT_EP_SIZE),0x00 ' Size of the EndPoint buffer (in bytes) (low byte, high byte)
Dt cUSB_POLLING_INTERVAL ' Polling interval (in ms)
'
' Endpoint descriptor (IN)
'
Desc_Endpoint1In:
Dt (Desc_EndConfig1 - Desc_Endpoint1In) / 2 ' Size of this descriptor (in bytes)
Dt cUSB_DESCRIPTOR_ENDPOINT ' EndPoint descriptor type
Dt cHID_EP | _cEP_IN ' EndPoint Address
Dt _cINT ' Attributes
Dt Low(cHID_INT_IN_EP_SIZE),0x00 ' Size of the EndPoint buffer (in bytes) (low byte,high byte)
Dt cUSB_POLLING_INTERVAL ' Polling interval (in ms)
Desc_EndConfig1:
Desc_ReportDescriptor1:
'Descripcion del dispositivo:
dt 0X05, 0X01 'USAGE_PAGE (Generic Desktop)
dt 0X09, 0X04 'USAGE (Joystick)
dt 0XA1, 0X01 'COLLECTION (Application)
dt 0X09, 0X04 'USAGE (Joystick)
dt 0XA1, 0X00 'COLLECTION (Physical)

' 'Mando analogico
' dt 0X09, 0X30 'USAGE (X)
' dt 0X09, 0X31 'USAGE (Y)
' dt 0X75, 0X08 'REPORT_SIZE (8)
' dt 0X95, 0X02 'REPORT_COUNT (1)
' dt 0X81, 0X02 'INPUT (Data,Var,Abs)
' dt 0X35, 0X00 'PHYSICAL_MINIMUM (0)
' dt 0X46, 0XFF, 0X00 'PHYSICAL_MAXIMUM (255)
' dt 0X81, 0X03 'INPUT (Cnst,Var,Abs)
' dt 0XC0 'END_COLLECTION
' 'Acelerador (THROTTLE) analogico
' dt 0X05, 0X02 'USAGE_PAGE (Simulation Controls) 02 09
' dt 0X09, 0XBB 'USAGE (Throttle) BB 15
' dt 0X15, 0X81 'LOGICAL_MINIMUM (-127) 15 81
' dt 0X25, 0X7F 'LOGICAL_MAXIMUM (127) 25 7F
' dt 0X75, 0X08 'REPORT_SIZE (8) 75 08
' dt 0X95, 0X01 'REPORT_COUNT (1) 95 01
' dt 0X81, 0X02 'INPUT (Data,Var,Abs) 81 02

'Hat mando digital
dt 0X09, 0X39 'USAGE (Hat switch) 09 39
dt 0X15, 0X00 'LOGICAL_MINIMUM (0) 15 00
dt 0X25, 0X07 'LOGICAL_MAXIMUM (7) 25 08
dt 0X35, 0X00 'PHYSICAL_MINIMUM (0) 35 00
dt 0X46, 0X3B, 0X01 'PHYSICAL_MAXIMUM (315) 46 3B 01
dt 0X65, 0X14 'UNIT (Eng Rot:Angular Pos) 65 14
dt 0X55, 0X00 ' Unit_Exponent (0)
dt 0X75, 0X08 'REPORT_SIZE (8) 75 08
dt 0X95, 0X01 'REPORT_COUNT (1) 95 01
dt 0X81, 0X42 'INPUT (Data,Var,Abs,NULL) 81 42

'Configuracion 8 botones
dt 0X05, 0X09 'USAGE_PAGE (Botones)
dt 0X19, 0X01 'USAGE_MINIMUN
dt 0X29, 0X08 'USAGE_MAXIMUN
dt 0X15, 0X00 'LOGICAL_MINIMUN (0)
dt 0X25, 0X01 'LOGICAL_MINIMUN (1)
dt 0X75, 0X01 'REPORT_SIZE (1)
dt 0X95, 0X08 'REPORT_COUNT (8)
dt 0X81, 0X03 'INPUT (Cnst,Var,Abs)
dt 0XC0 'END_COLLECTION
dt 0XC0 'END_COLLECTION




' dt 0X05, 0x01 'USAGE_PAGE (Generic Desktop) 05 01
' dt 0x09, 0x04 'USAGE (Joystick) 09 04
' dt 0xA1, 0x01 'COLLECTION (Application) A1 01
' dt 0X05, 0X02 'USAGE_PAGE (Simulation Controls) 02 09
' dt 0X09, 0XBB 'USAGE (Throttle) BB 15
' dt 0X15, 0X81 'LOGICAL_MINIMUM (-127) 15 81
' dt 0X25, 0X7F 'LOGICAL_MAXIMUM (127) 25 7F
' dt 0X75, 0X08 'REPORT_SIZE (8) 75 08
' dt 0X95, 0X01 'REPORT_COUNT (1) 95 01
' dt 0X81, 0X02 'INPUT (Data,Var,Abs) 81 02
' dt 0X05, 0X01 'USAGE_PAGE (Generic Desktop) 05 01
' dt 0X09, 0X01 'USAGE (Pointer) 09 01
' dt 0XA1, 0X00 'COLLECTION (Physical) A1 00
' dt 0X09, 0X30 'USAGE (X) 09 30
' dt 0X09, 0X31 'USAGE (Y) 09 31
' dt 0X15, 0X81 'LOGICAL_MINIMUM (-127) 15 81
' dt 0X25, 0X7F 'LOGICAL_MAXIMUM (127) 25 7F
' dt 0X95, 0X02 'REPORT_COUNT (2) 95 02
' dt 0X81, 0X02 'INPUT (Data,Var,Abs) 81 02
' dt 0XC0 'END_COLLECTION C0
' dt 0X09, 0X39 'USAGE (Hat switch) 09 39
' dt 0X15, 0X00 'LOGICAL_MINIMUM (0) 15 00
' dt 0X25, 0X07 'LOGICAL_MAXIMUM (7) 25 08
' dt 0X35, 0X00 'PHYSICAL_MINIMUM (0) 35 00
' dt 0X46, 0X3B, 0X01 'PHYSICAL_MAXIMUM (315) 46 3B 01
' dt 0X65, 0X14 'UNIT (Eng Rot:Angular Pos) 65 14
' dt 0X55, 0X00 ' Unit_Exponent (0)
' dt 0X75, 0X08 'REPORT_SIZE (8) 75 08
' dt 0X95, 0X01 'REPORT_COUNT (1) 95 01
' dt 0X81, 0X42 'INPUT (Data,Var,Abs,NULL) 81 42
' 'configuracion 8 botones
' dt 0x05, 0x09 'USAGE_PAGE (Button) 05 09
' dt 0x19, 0x01 'USAGE_MINIMUM (Button 1) 19 01
' dt 0x29, 0x08 'USAGE_MAXIMUM (Button 8) 29 08 Cantidad maxima de botones
' dt 0x15, 0x00 'LOGICAL_MINIMUM (0) 15 00
' dt 0x25, 0x01 'LOGICAL_MAXIMUM (1) 25 01
' dt 0X35, 0X00 'PHYSICAL_MINIMUM (0) 35 00
' dt 0X45, 0X01 'PHYSICAL_MAXIMUM (1) 45 01
' dt 0x75, 0x01 'REPORT_SIZE (1)
' dt 0x95, 0x08 'REPORT_COUNT (8) 95 08 Modificar junto a cantidad maxima de botones
' dt 0X65, 0X00 'UNIT (none)
' dt 0x81, 0x02 'INPUT (Data,Var,Abs)
' 'dt 0X81, 0X03 'Input const var absolute ! padding
' dt 0XC0 'END_COLLECTION C0
' 'Configuracion 32 botones
' dt 0X05, 0X09 'USAGE_PAGE (Button) 05 09
' dt 0X19, 0X01 'USAGE_MINIMUM (Button 1) 19 01
' dt 0X29, 0X20 'USAGE_MAXIMUM (Button 32) 29 20
' dt 0X15, 0X00 'LOGICAL_MINIMUM (0) 15 00
' dt 0X25, 0X01 'LOGICAL_MAXIMUM (1) 25 01
' dt 0X75, 0X01 'REPORT_SIZE (1) 75 01
' dt 0X95, 0X20 'REPORT_COUNT (32) 95 32
' dt 0X55, 0X00 'UNIT_EXPONENT (0) 55 00
' dt 0X65, 0X00 'UNIT (None) 65 00
' dt 0X81, 0X02 'INPUT (Data,Var,Abs) 81 02
' dt 0XC0 'END_COLLECTION C0



Desc_EndReportDescriptor1:
'
' Configuration pointer table
Desc_USB_CD_Ptr:
Desc_Configs:
CData As Dword Desc_Config1
'
' String pointer table
Desc_USB_SD_Ptr:
Desc_Strings:
CData As Dword Desc_String0, Desc_String1, Desc_String2, Desc_String3
'
' Language code string descriptor
'
Desc_String0:-
dt (Desc_String1 - Desc_String0) / 2 ' Size of this descriptor (in bytes)
dt cUSB_DESCRIPTOR_STRING ' String descriptor type
dt 0x09, 0x04 ' Language ID as defined by MS - 0x0409
'
' Manufacturer string descriptor
'
Desc_String1:-
dt (Desc_String2 - Desc_String1) / 2
dt cUSB_DESCRIPTOR_STRING ; Descriptor string type
CData As Dword "MTH"
'
' Product string descriptor
'
Desc_String2:-
dt (Desc_String3 - Desc_String2) / 2
dt cUSB_DESCRIPTOR_STRING ; Descriptor string type
CData As Dword "MTH-Joystick"
'
' Serial number string descriptor
'
Desc_String3:-
dt (_DescriptorMain_ - Desc_String3) / 2
dt cUSB_DESCRIPTOR_STRING ; Descriptor string type
CData As Dword "03"
_DescriptorMain_:
$endif ' _HID_DESC_INC_



I really do not know, if I inadvertently I modified my program and this causes it to not work.
But, I have one PCB armed and working perfectly, with a PIC18F25K50 added with copper wires (attached photo, do not laugh ...) in a very precarious way to an old Sega Joystick.
Since this was to play, practice and learn a little, but now I really need it for a project that I must finish (attached photo with PIC18F25K50 in QFN) I really do not know, if I inadvertently modify my program and that causes it to not work.
I thank you for any help you can give me.
Thank you very much.




PIC18F25K50 in QFN:
3262

PIC18F25K50 in SOIC28:
3261

barak
22nd April 2017, 01:18
What version are you using? For me version 3.5.9.3 fixed this problem

MTH
22nd April 2017, 04:31
Hi again, still not working, I attached an updated proton image.

3263

Does exactly the same :(

Hi Barak, thanks for you reply.
My current version is 3.5.8.6
Now update to the version you say, I will comment the results in a moment.
Thanks.

Tim
22nd April 2017, 16:27
From memory USB needs greater accuracy than in the INTSOC can provide.

That is why there are never products using a PIC that run with out an external clock.

towlerg
22nd April 2017, 17:22
Tim, Mth posted that it had worked with an earlier version of Proton. I have to say I was surprised that it was possible to use an internal oscillator. I seem to remember a while ago MicroChip made a big splash announcement that they were going to release a USB capible device which had an internal crystal.

MTH
22nd April 2017, 20:09
Hi, I have read a lot about it, and it is true that it seems that very few manage to operate the USB with internal glass. But I really have it working, I can make a video of the disassembled Joystick (I can remove the glue I put on the 18F25K50 so that the crystal pins can be seen without connection) so you can believe me.

towlerg
22nd April 2017, 23:05
I don't know that device but perhaps you could trim the internal oscillator. I guess though the obvious question is why you dont want to use a crystal, SMD one are tiny.

towlerg
23rd April 2017, 03:08
For the record the following is the clock accuracy requirement for different USB speeds


Speed Tolerance
Low 1.5%
Full 0.25%
High 0.05%

Source: USB Complete

towlerg
23rd April 2017, 03:19
For the record the following is the clock accuracy requirement for different USB speeds


Speed Tolerance
Low 1.5%
Full 0.25%
High 0.05%

Source: USB Complete

MTH
23rd April 2017, 19:49
George, I not using a crystal is because in a previous design with glass I had problems with an 18F2550, this when there was some electomagnetic noise was hanging and did not come out of the drape even with the WDT. Finished placing a 12F629 that controlled the activity of the 18F2550 and reset it by hardware when this happened. I always had better results with internal glass, that is why I desid not to place glass in this development and as I had previously managed to operate the 18F25k50 without glass I did not see the difficulty of not placing it. Now I have about 200 pcb finished and I can not walk. I'm in trouble. I usually do not go to the forum because I could always solve everything on my own, but now I really do not know how to solve it.

towlerg
23rd April 2017, 22:12
The title of this tread is ........... 18F25K20 but code has 18F25K50

If it's 18F25K20 then all is solved as 25K20 is not USB capable.

If it's 18F25K50 then you are just unlucky. The datasheet states

Crystal-less Full Speed (12 MB/s) and Low-Speed Operation (1.5 Mb/s
try another 18F25K50. Also maybe try Low Speed if possible.

MTH
24th April 2017, 12:33
Hi George, you're right, 18F25K20 does not have USB, I know, I got confused when I wrote the title, sorry. The problem I have with the 18F25K50, and tested several, in fact the tests I am doing on a test board with a 18F25K50 in SOIC28 format, the plates armed I have in QFN format.
How can I correct the title of the post?
Thank you.

towlerg
24th April 2017, 14:53
How can I correct the title of the post
I suspect that you can't. Maybe raise another thread and reference this one.

Did you try Low speed, the tolerance is much greater? (although if the devices are in spec, then that should not be an issue)

Just a few ideas, most of which I'm sure you've already considered and rejected.

Have you tried a USB analyser (I think you can get a trial of USBLyser and USB Trace)? What does the attempt to attach look like?

Have you considered that it might be something other that the oscillator?

If you have a scope, write a simple program to measure the clock.

Does your board implement the requirements in Section 2 of the data sheet, specifically C7?

Can you post a circuit diagram?

Have you tried reverting to the version of Proton that worked?

Have you made ANY changes to the descriptor?

If you have a spare board with the 25k50 already soldered (I can't do SMD) I'll take a look. It would be interesting what a logic analyser makes of what's going on.

tumbleweed
24th April 2017, 16:20
The 25K50 works fine with the internal osc and usb FS... I've used it before just not with Proton.

If I understand correctly you say you have a version that works with the SOIC package ok, but not the QFN package. Is that right?
What's the difference circuit-wise between the two?

It looks like you have inductors/ferrite beads on the USB D+/D- lines. I'd remove them to start with. You can leave the ones on USB VBUS and GND... they should be ok.

MTH
25th April 2017, 10:57
Hi, thank you very much for the answers.
Here I answer the last two comments.

George:
I suspect that you can not. Maybe raise another thread and reference this one.
Ok.
Did you try Low speed, the tolerance is much greater? (Although the devices are in spec, then that should not be an issue)
No, I'll try.
Just a few ideas, most of which I'm sure you've already considered and rejected.
Have you tried a USB Analyzer (I think you can get a trial of USBLyser and USB Trace)? What does the attempt to attach look like?
No, I have not tries a USB analyzer, I are not have.

Have you considered that it might be something else that the oscillator?
Realy I not sure that is the oscilator.
If you have a scope, write a simple program to measure the clock.
Ok, I post the result.
Does your board implement the requirements in Section 2 of the data sheet, specifically C7?
Yes, the circuit are working, only no work with this code of the proton.
Can you post a circuit diagram?
Yes.
Have you tried reverting to the version of Proton that worked?
No, realy I not sure that version proton was.
Have you made ANY changes to the descriptor?
Yes, but I are not sure if ok.
If you have a spare board with the 25k50 already soldered (I can not do SMD) I'll take a look. It would be interesting what a logic analyzer makes of what's going on.
I made one test with logical analizer, the device sends frames for about 10 seconds until the system gives the error.


tumbleweed:

The 25K50 works fine with the internal osc and usb FS ... I've used it before just with Proton.
Can you send me some .HEX that works to prove?
If I understand correctly you say that you have a version that works with the SOIC package ok, but not the QFN package. Is that right?
What's the difference circuit-wise between the two?
No, it does not work with any of the 2 encapsulates.
It looks like you have inductors / ferrite beads on the USB D + / D- lines. I'd remove them to start with. You can leave the ones on USB VBUS and GND ... they should be ok.
Already tested everything, even change the position and value of C7 (according datasheet) but always get the same error.


The Circuit:
3271


The boards:
3267

The CPUs:
32683269

The osc speed test:
3270

With this code:


While 1=1
Toggle LedST
DelayMS 10
Wend


Is 10.8 Ms

Thanks much, If you need me to try something else, let me know.

Federico MTH.

hadv215
25th April 2017, 12:06
It's hard to distinguish, but it looks like you are using a 2u2 polarized cap on Vusb.
I'm not sure this is the right choice, please consider the resommendations in the chapter "Voltage Regulator Pins (VUSB3V3)".
I always use 470n ceramic caps and have found no problems with them.

towlerg
26th April 2017, 02:26
Can you post a larger image of the curcuit diagram, can't see any detail on posted image.


I always use 470n ceramic caps and have found no problems with them.
Maybe I've just been lucky but I always use 0.1 decoupling ceramic, always seems to work.


Is 10.8 Ms
Are you sure, thats nearly a 10% error. What Xtal was declared?

Kudos on the board, very nice.

hadv215
26th April 2017, 11:59
from the datasheet:
F devices permanently enable the voltage
regulator.
These devices require an external capacitor on
the VUSB3V3 pin. It is recommended that the
capacitor be a ceramic cap between 0.22 to
0.47 μF.

towlerg
26th April 2017, 12:55
These devices require an external capacitor on
the VUSB3V3 pin. It is recommended that the
capacitor be a ceramic cap between 0.22 to
0.47 μF.

I know 0.1 is out of spec but it seems to work.

MTH, another thing you could try, to confirm the harware is OK, try running one of the USB demos.

MTH
27th April 2017, 00:57
Hi, sorry for delay in my answer.
I do not know why, I can not open the proton page from my office from any pc. It is as if my IP would be drooling.
The hardware is it ok, the cap in VUSB3V3 pin is 470nF ceramic.
The code is the posted by my, the config for the xtal is it, I not have the demo of the code with internal oscillator for test the hardware, only test for my code of the sega joystick. tomorrow I test the adjust of the xtal to 10ms and post the result. thanks much

towlerg
27th April 2017, 01:37
I test the adjust of the xtal to 10ms and post the result.

I'm not sure what you mean, I had the the impression that the internal clock was meant to be factory trimmed to 1% and able to automatically adjust itself to plus or minus 0.2%. Bear in mind the automatic adjustment, "Automatic Clock Tuning" will only occur when connected to a active USB host. OSCTUNE seems to be a temperature compensation not a mechanism to synchronise USB comms

See_Mos
27th April 2017, 11:17
This is my working test code. There are a few differences in the config. Also in your code Declare XTAL = 48 is commented out, as far as I remember without the declare the compiler defaults to 4MHz


'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2017 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 27/02/2017 *
'* Version : 2.0 *
'* Notes : *
'* : *
'************************************************* ***************
' This file works with Delphi programme USB 2009. Tested 02.03.2017

Device = 18F25K50
Declare Xtal = 48
Include "Trevor HID.inc" ' Vendor 1240 = $04D8, product 1 = $0001 to match
' Delphi USB2009.DPR
'Include "Trevor 18F25K50.inc"
Declare LCD_Type 0
Declare LCD_Interface 4
Declare LCD_Lines 2
Declare LCD_DTPin PORTB.4
Declare LCD_RSPin PORTB.3
Declare LCD_ENPin PORTB.2
Declare LCD_CommandUs = 250 ' 205us time for commands to be sent to the LCD
Declare LCD_DataUs = 100 ' 100us time for data to be sent to the LCD

OSCCON = 110000 ' settings for 16MHz INTOSC

TRISA.6 = 0 ' clock output
TRISB.1 = 0 ' LED
All_Digital = True

Symbol TRNIF = UIR.3

Dim Loop_Count As Word
Dim tempw1 As Word
Dim tempb1 As Byte
Dim tempb2 As Byte
Dim I As Byte
Dim True As 1
Dim False As 0

' USB buffer...
Symbol USBBufferSizeTX = 64
Symbol USBBufferSizeRX = 64

Dim USBInBuffer[USBBufferSizeRX] As Byte ;At __USBIn_Buffer
Dim USBOutBuffer[USBBufferSizeTX] As Byte ;At __USBOut_buffer

Dim USBCommand As Byte At USBInBuffer#0

Dim Result As Word At USBOutBuffer#0

Symbol Command1 = 01 ' LED 1
Symbol Command2 = 02 ' LED 2
Symbol Command3 = 03
Symbol Command4 = 04 ' get 64Kb
Symbol Command5 = 05 ' clear LCD

Symbol Command7 = 07 ' Test

Symbol Led1 = LATB.0
Symbol Led2 = LATB.1

Clear
Low Led1 : High Led2 ' Led1 is off until USB is connected
DelayMS 250
Cls
Print "Ready"
DelayMS 500

Print Cls
Print "Waiting for USB"
USBInit
Repeat ' \
USBPoll ' Wait for the USB interface to become attached
Until USB_tConnected = 1 Or USB_tConfigured = 1

Print Cls,"Ready"
High Led1

Main_Loop:
While 1 = 1
Clear USBOutBuffer
GoSub DoUSBIn
Select USBCommand
' Select USBInBuffer[0]
Case Command1
Toggle Led1

Case Command2
Toggle Led2

Case Command3
Result = USBInBuffer#1 + USBInBuffer#2
GoSub DoUSBOut
Cls
Print "#1 = ",Dec Usbinbuffer#1," #2 = ",Dec usbinbuffer#2
Print At 2,1,"Result = ",Dec Result
Case Command4
tempw1 = 0
tempb2 = 0
Print Cls,"Send 64KB to PC"
Repeat
tempb1 = 0
Repeat
USBOutBuffer[tempb1] = tempb2
Inc tempb1
Inc tempb2
Inc tempw1
Until tempb1 = 64
GoSub DoUSBOut
Until tempw1 = 64000
Print Cls, "Next"
Case Command5
Cls
Case Command7
Print Cls
For I = 0 To 3
Print Dec USBInBuffer[I]," "
Next
Print At 2,1
For I = 4 To 7
Print Dec USBInBuffer[I]," "
Next
GoSub DoUSBOut ' send same data back to PC
DelayMS 3000 ' need to see the info
Print Cls,"Next ?"
Case Else
GoTo Endd
End Select
Print At 1,10,Dec USBInBuffer#0
Endd:

Wend

' ************************************************** **********
' * receive data from the USB bus *
' ************************************************** **********
DoUSBIn:
Clear USBInBuffer
Clear USBOutBuffer
USBIn 1,USBInBuffer,64,InLoop
InLoop:
Return

' ************************************************** **********
' * transmit Data *
' ************************************************** **********

DoUSBOut:
USBOut 1,USBOutBuffer,64,DoUSBOut
Return
;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings
Config_Start
PLLSEL = PLL3X ;3x clock multiplier 3 x 16 = 48
CFGPLLEN = On ;PLL Disabled (firmware controlled)
CPUDIV = NOCLKDIV ;CPU uses system clock (no divide)
LS48MHZ = SYS48X8 ;System clock at 48 MHz, USB clock divider is set to 8
FOSC = INTOSCIO ; internal oscillator, no clock out on RA6
' FOSC = INTOSCCLKO ;Internal oscillator, clock output on RA6 OSC2
PCLKEN = On ;Primary oscillator enabled
FCMEN = OFF ;Fail-Safe Clock Monitor disabled
IESO = OFF ;Oscillator Switchover mode disabled
nPWRTEN = OFF ;Power up timer disabled
BOREN = SBORDIS ;BOR enabled in hardware (SBOREN is ignored)
BORV = 190 ;BOR set to 1.9V nominal
nLPBOR = OFF ;Low-Power Brown-out Reset disabled
WDTEN = On ;WDT enabled in hardware (SWDTEN ignored)
WDTPS = 32768 ;1:32768
CCP2MX = RC1 ;CCP2 input/output is multiplexed with RC1
PBADEN = On ;PORTB<5:0> pins are configured as analog input channels on Reset
T3CMX = RC0 ;T3CKI function is on RC0
SDOMX = RB3 ;SDO function is on RB3
MCLRE = On ;MCLR pin enabled; RE3 input disabled
STVREN = On ;Stack full/underflow will cause Reset
LVP = OFF ;Single-Supply ICSP disabled
ICPRT = OFF ;ICPORT disabled
XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled
Debug = OFF ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
Cp0 = OFF ;Block 0 is not code-protected
CP1 = OFF ;Block 1 is not code-protected
CP2 = OFF ;Block 2 is not code-protected
CP3 = OFF ;Block 3 is not code-protected
CPB = OFF ;Boot block is not code-protected
CPD = OFF ;Data EEPROM is not code-protected
WRT0 = OFF ;Block 0 (0800-1FFFh) is not write-protected
WRT1 = OFF ;Block 1 (2000-3FFFh) is not write-protected
WRT2 = OFF ;Block 2 (04000-5FFFh) is not write-protected
WRT3 = OFF ;Block 3 (06000-7FFFh) is not write-protected
WRTC = OFF ;Configuration registers (300000-3000FFh) are not write-protected
WRTB = OFF ;Boot block (0000-7FFh) is not write-protected
WRTD = OFF ;Data EEPROM is not write-protected
EBTR0 = OFF ;Block 0 is not protected from table reads executed in other blocks
EBTR1 = OFF ;Block 1 is not protected from table reads executed in other blocks
EBTR2 = OFF ;Block 2 is not protected from table reads executed in other blocks
EBTR3 = OFF ;Block 3 is not protected from table reads executed in other blocks
EBTRB = OFF ;Boot block is not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

towlerg
27th April 2017, 16:06
A working example is worth a hundred posts. Thank you. Just one tiny thing, what version of Proton? I see it was tested recently, either 2nd. March or 3rd. of Feb depending on which side of the pond.

Mht, I didn't realise before I saw See_Mos's config, you can echo the clock on RA6.

MTH
27th April 2017, 18:35
Hello everyone, make it work !!!
The problem was the descriptor, add the program descriptor echo initially in the 18F2550 and it works !!
Many thanks to all for the help and support given, I am eternally grateful.

I post the code in clean, the descriptor used and photos of the tests.

Many thanks!!!


This Code working the 27/04/2017 by MTH:


'************************************************* ***************
'* Name : SegaUSB.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2017 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 27/04/2017 *
'* Version : 1.0 *
'* Notes : nop *
'* : *
'************************************************* ***************
;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings
Device 18F25K50
Declare Xtal = 48
'Declare PLL_Req = OFF '
'Declare Watchdog =On
Declare All_Digital TRUE
Declare PortB_Pullups = On
Declare Reminders = Off
$define _usb_ram 1024 'sin esto da error al compilar!
Include "USB18_Joystick_8b_Sega.inc" 'el resto de los descriptors no funciona

Config_Start
PLLSEL = PLL3X ;3x clock multiplier
CFGPLLEN = OFF ;PLL Disabled (firmware controlled)
CPUDIV = NOCLKDIV ;CPU uses system clock /2
LS48MHZ = SYS48X8 ;System clock at 48 MHz, USB clock divider is set to 8
FOSC = INTOSCIO ;Internal oscillator
PCLKEN = On ;Primary oscillator enabled
FCMEN = On ;Fail-Safe Clock Monitor disabled
IESO = On ;Oscillator Switchover mode disabled
nPWRTEN = On ;Power up timer disabled
BOREN = SBORDIS ;BOR enabled in hardware (SBOREN is ignored)
BORV = 190 ;BOR set to 1.9V nominal
nLPBOR = On ;Low-Power Brown-out Reset disabled
WDTEN = OFF ;WDT enabled in hardware (SWDTEN ignored)
WDTPS = 32768 ;1:32768
CCP2MX = RC1 ;CCP2 input/output is multiplexed with RC1
PBADEN = On ;PORTB<5:0> pins are configured as analog input channels on Reset
T3CMX = RC0 ;T3CKI function is on RC0
SDOMX = RB3 ;SDO function is on RB3
MCLRE = On ;MCLR pin enabled; RE3 input disabled
STVREN = OFF ;Stack full/underflow will cause Reset
LVP = OFF ;Single-Supply ICSP enabled if MCLRE is also 1
ICPRT = OFF ;ICPORT disabled
XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled
Debug = OFF ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
Cp0 = OFF ;Block 0 is not code-protected
CP1 = OFF ;Block 1 is not code-protected
CP2 = OFF ;Block 2 is not code-protected
CP3 = OFF ;Block 3 is not code-protected
CPB = OFF ;Boot block is not code-protected
CPD = OFF ;Data EEPROM is not code-protected
WRT0 = OFF ;Block 0 (0800-1FFFh) is not write-protected
WRT1 = OFF ;Block 1 (2000-3FFFh) is not write-protected
WRT2 = OFF ;Block 2 (04000-5FFFh) is not write-protected
WRT3 = OFF ;Block 3 (06000-7FFFh) is not write-protected
WRTC = OFF ;Configuration registers (300000-3000FFh) are not write-protected
WRTB = OFF ;Boot block (0000-7FFh) is not write-protected
WRTD = OFF ;Data EEPROM is not write-protected
EBTR0 = OFF ;Block 0 is not protected from table reads executed in other blocks
EBTR1 = OFF ;Block 1 is not protected from table reads executed in other blocks
EBTR2 = OFF ;Block 2 is not protected from table reads executed in other blocks
EBTR3 = OFF ;Block 3 is not protected from table reads executed in other blocks
EBTRB = OFF ;Boot block is not protected from table reads executed in other blocks
Config_End
;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

Dim PP0 As Byte System ' USBPOLL status return
Dim i As Byte
Dim BUFFER[5] As Byte
Dim Botones As Byte
Dim POVControl As Byte
Symbol CARRY_FLAG = STATUS.0 ' High if microcontroller does not have control over the DP buffer
Symbol TRNIF = UIR.3 ' Low if USB Busy \
'Ports in use:
Symbol Bot1 = PORTB.0
Symbol Bot2 = PORTB.1
Symbol Bot3 = PORTB.2
Symbol Bot4 = PORTB.3
Symbol Bot5 = PORTB.4
Symbol Bot6 = PORTB.5
Symbol Bot7 = PORTB.6
Symbol Bot8 = PORTB.7
Symbol LedST = PORTC.2
Symbol Pov1 = PORTA.0
Symbol Pov2 = PORTA.1
Symbol Pov3 = PORTA.2
Symbol Pov4 = PORTA.3
Symbol SW1 = PORTC.7


'---- Ini sacado de (http://www.microchip.com/forums/m727996.aspx) de davekw7x para usar cristal interno de 18f25k50
OSCCON2bits_PLLEN = 0; // Changes in SPLLMULT are ignored unless pll is disabled
OSCTUNEbits_SPLLMULT = 1; // PLL: x3 multiplier Set this before enabling PLL

OSCCON = 0x70; OSCCON = 0x70 110000
'//OSCCONbits.SCS = 0; //Primary clock determined by FOSC<3:0> in CONFIG1H
'//OSCCONbits.IRCF = 7; // Internal RC Oscillator HFINTOSC = 16 MHz
'//OSCCONbits.IDLEN = 0; // Device enters Sleep mode on SLEEP instruction
OSCCON2 = 0x10
'// 0b01110000 : 111 = HFINTOSC (16 MHz)
'// enable the 16 MHz internal clock
'// Primary clock source (HFINTOSC or HSPLL)
'// is defined by FOSC<2:0> (cf. config.h)

OSCCON2 = 0x10;
'//OSCCON2bits.INTSRC = 0; // Low power INTRC as 31.25 reference
'//OSCCON2bits.SOSCGO = 0; // No secondary oscillator unless otherewise requested
'//OSCCON2bits.PRISD = 0; // Enable primary oscillator
'//OSCCON2bits.PLLEN = 1; // Use PLL.
While OSCCON2bits_PLLRDY = 1 ' while (OSCCON2bits.PLLRDY != 1)
Wend

OSCCON2bits_PRISD = 1; '// Disable primary oscillator
'// The following is "probably" not necessary since not doing clock switching
DelayMS 3 '? Delay10KTCYx(3); '// 2.5 milliseconds for 12 MHz instruction clock


'// Enable HFINTOSC to be tuned by the USB clock
ACTCON = 0x90;
'//ACTCONbits.ACTEN = 1;
'//ACTCONbits.ACTSRC = 1;

'---- Fin sacado de (http://www.microchip.com/forums/m727996.aspx) de davekw7x para usar cristal interno de 18f25k50

High LedST

ANSELA = 0; // all I/O to Digital mode
ANSELB = 0; // all I/O to Digital mode
ANSELC = 0; // all I/O to Digital mode

DelayMS 10

USBInit
Repeat ' \
USBPoll ' Wait for the USB interface to become attached
Until USB_tConnected = 1 Or USB_tConfigured = 1 ' Until PP0 = 000110 ' /
Low LedST

'Main loop
While 1 = 1
Toggle LedST
'Control de botones
'ini botones
Input Bot1
Input Bot2
Input Bot3
Input Bot4
Input Bot5
Input Bot6
Input Bot7
Input Bot8

'BT Star y Mode
Botones.6=Bot7+1
Botones.7=Bot8+1
If SW1=0 Then
Botones.0=Bot1+1
Botones.1=Bot2+1
Botones.2=Bot3+1
Botones.3=Bot4+1
Botones.4=Bot5+1
Botones.5=Bot6+1
Botones.6=Bot7+1
Botones.7=Bot8+1
Else
'
If Bot1=0 Then
Botones.0=Botones.0+1
Else
Botones.0=0
EndIf
'
If Bot2=0 Then
Botones.1=Botones.1+1
Else
Botones.1=0
EndIf
'
If Bot3=0 Then
Botones.2=Botones.2+1
Else
Botones.2=0
EndIf
'
If Bot4=0 Then
Botones.3=Botones.3+1
Else
Botones.3=0
EndIf
'
If Bot5=0 Then
Botones.4=Botones.4+1
Else
Botones.4=0
EndIf
'
If Bot6=0 Then
Botones.5=Botones.5+1
Else
Botones.5=0
EndIf
EndIf
BUFFER[1] = Botones

'Control POV

'ini POV
Input Pov1
Input Pov2
Input Pov3
Input Pov4

'centro
If Pov1=1 And Pov2=1 And Pov3=1 And Pov4=1 Then POVControl=8 'palanca en centro

'normales
If Pov1=0 Then POVControl=0 'UP
If Pov2=0 Then POVControl=4 'DW
If Pov3=0 Then POVControl=2 'RI
If Pov4=0 Then POVControl=6 'LE

'diagonales
If Pov1=0 And Pov3=0 Then POVControl=1
If Pov3=0 And Pov2=0 Then POVControl=3
If Pov2=0 And Pov4=0 Then POVControl=5
If Pov4=0 And Pov1=0 Then POVControl=7

BUFFER[0] = POVControl

Repeat
USBOut 1, BUFFER,2 ' Send the buffer to endpoint 1
Until CARRY_FLAG = 0 ' Keep trying if the microcontroller does not have control over the buffer
'Repeat : Until TRNIF = 1 ' Wait for completion before continuing
Wend
End



This is the descriptor file "USB18_Joystick_8b_Sega.inc":

$ifndef _HID_DESC_INC_
$define _HID_DESC_INC_
'
' Generated by PDS USB HID Wizard, version 0.2.1.1
'
$define cVID 0x04D8 ' Vendor ID (Keep to 0x format for Hex value)
$define cPID 0x001A ' Product ID (Keep to 0x format for Hex value)
$define cUSB_EP0_BUFF_SIZE 8 ' 8, 16, 32, or 64
$define cUSB_MAX_NUM_INT 1
$define cUSB_MAX_EP_NUMBER 1
$define cUSB_NUM_CONFIGS 1
$define cUSB_NUM_INTERFACES 1
$define cUSB_MAX_POWER 40 ' Maximum power consumption (in MilliAmps)
$define cUSB_POLLING_INTERVAL 1 ' Polling interval (in MilliSeconds)
'$define cUSE_SELF_POWER
'$define cUSE_USB_BUS_SENSE_IO
$ifdef cUSE_USB_BUS_SENSE_IO
Symbol USB_BUS_SENSE_PIN = PORTA.0
$endif
$define cUSB_POLLING
' HID
' Endpoints Allocation
$define cHID_INTF_ID 0
$define cHID_EP 1
$define cHID_INT_OUT_EP_SIZE 8
$define cHID_INT_IN_EP_SIZE 8
$define cHID_NUM_OF_DSC 1
Symbol cUSB_BUFFER_OUT_SIZE = cHID_INT_OUT_EP_SIZE
Symbol cUSB_BUFFER_IN_SIZE = cHID_INT_IN_EP_SIZE
GoTo _DescriptorMain_ ' Jump over the USB code
Include "USB_HID.inc" ' Include the 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.
'
Desc_DeviceDescriptor:
Dt (Desc_EndDeviceDescriptor - Desc_DeviceDescriptor) / 2 ' Size of this descriptor (in bytes)
Dt cUSB_DESCRIPTOR_DEVICE ' Device descriptor type
Dt 0x10, 0x01 ' USB Spec Release Number in BCD format - 1.10 (low byte, high byte)
Dt 0x00 ' Class Code
Dt 0x00 ' Subclass code
Dt 0x00 ' Protocol code
Dt cUSB_EP0_BUFF_SIZE ' Max packet size for EP0
Dt Low(cVID), High(cVID) ' Vendor ID
Dt Low(cPID), High(cPID) ' Product ID
Dt 0x01 ' Device release number in BCD format (low byte)
Dt 0x00 ' (high byte)
Dt 0x01 ' Manufacturer string index
Dt 0x02 ' Product string index
Dt 0x00 ' Device serial number string index
Dt cUSB_NUM_CONFIGS ' Number of possible configurations
Desc_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 Descriptor
'
Desc_Config1:
Dt (Desc_Interface1 - Desc_Config1) / 2 ' Size of this descriptor (in bytes)
Dt cUSB_DESCRIPTOR_CONFIGURATION ' Configuration descriptor type
Desc_Config1Len:
Dt Low((Desc_EndConfig1 - Desc_Config1) / 2),High((Desc_EndConfig1 - Desc_Config1) / 2) ' Total length of data for this cfg
Dt cUSB_NUM_INTERFACES ' Number of interfaces in this cfg
Dt 0x01 ' Index value of this configuration
Dt 0x00 ' Configuration string index
Dt _cDEFAULT | _cSELF ' Attributes
Dt (cUSB_MAX_POWER / 2) ' Max power consumption (in mA)
'
' Interface descriptor
'
Desc_Interface1:
Dt (Desc_HIDDescriptor1 - Desc_Interface1) / 2 ' Size of this descriptor (in bytes)
Dt cUSB_DESCRIPTOR_INTERFACE ' Interface descriptor type
Dt 0x00 ' Interface Number
Dt 0x00 ' Alternate Setting Number
Dt 0x02 ' Number of endpoints in this intf
Dt cHID_INTF ' Class code
Dt 0x00 ' Subclass code
Dt 0x00 ' Protocol code
Dt 0x00 ' Interface string index
'
' HID class-specific descriptor
'
Desc_HIDDescriptor1:
Dt (Desc_Endpoint1Out - Desc_HIDDescriptor1) / 2' Size of this descriptor (in bytes)
Dt cDSC_HID ' HID descriptor type
Dt 0x11, 0x01 ' HID Spec Release Number in BCD format - 1.11 (low byte,high byte)
Dt 0x00 ' Country Code (0x00 for Not supported)
Dt cHID_NUM_OF_DSC ' Number of class descriptors
Dt cDSC_RPT ' Report descriptor type (HID)
Desc_ReportDescriptor1Len:
Dt Low((Desc_EndReportDescriptor1 - Desc_ReportDescriptor1) / 2),High((Desc_EndReportDescriptor1 - Desc_ReportDescriptor1) / 2)
'
' Enpoint descriptor (OUT)
'
Desc_Endpoint1Out:
Dt (Desc_Endpoint1In - Desc_Endpoint1Out) / 2 ' Size of this descriptor (in bytes)
Dt cUSB_DESCRIPTOR_ENDPOINT ' EndPoint descriptor type
Dt cHID_EP | _cEP_OUT ' EndPoint Address
Dt _cINT ' Attributes
Dt Low(cHID_INT_OUT_EP_SIZE),0x00 ' Size of the EndPoint buffer (in bytes) (low byte, high byte)
Dt cUSB_POLLING_INTERVAL ' Polling interval (in ms)
'
' Endpoint descriptor (IN)
'
Desc_Endpoint1In:
Dt (Desc_EndConfig1 - Desc_Endpoint1In) / 2 ' Size of this descriptor (in bytes)
Dt cUSB_DESCRIPTOR_ENDPOINT ' EndPoint descriptor type
Dt cHID_EP | _cEP_IN ' EndPoint Address
Dt _cINT ' Attributes
Dt Low(cHID_INT_IN_EP_SIZE),0x00 ' Size of the EndPoint buffer (in bytes) (low byte,high byte)
Dt cUSB_POLLING_INTERVAL ' Polling interval (in ms)
Desc_EndConfig1:
Desc_ReportDescriptor1:
'Descripcion del dispositivo:
dt 0X05, 0X01 'USAGE_PAGE (Generic Desktop)
dt 0X09, 0X04 'USAGE (Joystick)
dt 0XA1, 0X01 'COLLECTION (Application)
dt 0X09, 0X04 'USAGE (Joystick)
dt 0XA1, 0X00 'COLLECTION (Physical)

' 'Mando analogico
' dt 0X09, 0X30 'USAGE (X)
' dt 0X09, 0X31 'USAGE (Y)
' dt 0X75, 0X08 'REPORT_SIZE (8)
' dt 0X95, 0X02 'REPORT_COUNT (1)
' dt 0X81, 0X02 'INPUT (Data,Var,Abs)
' dt 0X35, 0X00 'PHYSICAL_MINIMUM (0)
' dt 0X46, 0XFF, 0X00 'PHYSICAL_MAXIMUM (255)
' dt 0X81, 0X03 'INPUT (Cnst,Var,Abs)
' dt 0XC0 'END_COLLECTION
' 'Acelerador (THROTTLE) analogico
' dt 0X05, 0X02 'USAGE_PAGE (Simulation Controls) 02 09
' dt 0X09, 0XBB 'USAGE (Throttle) BB 15
' dt 0X15, 0X81 'LOGICAL_MINIMUM (-127) 15 81
' dt 0X25, 0X7F 'LOGICAL_MAXIMUM (127) 25 7F
' dt 0X75, 0X08 'REPORT_SIZE (8) 75 08
' dt 0X95, 0X01 'REPORT_COUNT (1) 95 01
' dt 0X81, 0X02 'INPUT (Data,Var,Abs) 81 02

'Hat mando digital
dt 0X09, 0X39 'USAGE (Hat switch) 09 39
dt 0X15, 0X00 'LOGICAL_MINIMUM (0) 15 00
dt 0X25, 0X07 'LOGICAL_MAXIMUM (7) 25 08
dt 0X35, 0X00 'PHYSICAL_MINIMUM (0) 35 00
dt 0X46, 0X3B, 0X01 'PHYSICAL_MAXIMUM (315) 46 3B 01
dt 0X65, 0X14 'UNIT (Eng Rot:Angular Pos) 65 14
dt 0X55, 0X00 ' Unit_Exponent (0)
dt 0X75, 0X08 'REPORT_SIZE (8) 75 08
dt 0X95, 0X01 'REPORT_COUNT (1) 95 01
dt 0X81, 0X42 'INPUT (Data,Var,Abs,NULL) 81 42

'Configuracion 8 botones
dt 0X05, 0X09 'USAGE_PAGE (Botones)
dt 0X19, 0X01 'USAGE_MINIMUN
dt 0X29, 0X08 'USAGE_MAXIMUN
dt 0X15, 0X00 'LOGICAL_MINIMUN (0)
dt 0X25, 0X01 'LOGICAL_MINIMUN (1)
dt 0X75, 0X01 'REPORT_SIZE (1)
dt 0X95, 0X08 'REPORT_COUNT (8)
dt 0X81, 0X03 'INPUT (Cnst,Var,Abs)
dt 0XC0 'END_COLLECTION
dt 0XC0 'END_COLLECTION




' dt 0X05, 0x01 'USAGE_PAGE (Generic Desktop) 05 01
' dt 0x09, 0x04 'USAGE (Joystick) 09 04
' dt 0xA1, 0x01 'COLLECTION (Application) A1 01
' dt 0X05, 0X02 'USAGE_PAGE (Simulation Controls) 02 09
' dt 0X09, 0XBB 'USAGE (Throttle) BB 15
' dt 0X15, 0X81 'LOGICAL_MINIMUM (-127) 15 81
' dt 0X25, 0X7F 'LOGICAL_MAXIMUM (127) 25 7F
' dt 0X75, 0X08 'REPORT_SIZE (8) 75 08
' dt 0X95, 0X01 'REPORT_COUNT (1) 95 01
' dt 0X81, 0X02 'INPUT (Data,Var,Abs) 81 02
' dt 0X05, 0X01 'USAGE_PAGE (Generic Desktop) 05 01
' dt 0X09, 0X01 'USAGE (Pointer) 09 01
' dt 0XA1, 0X00 'COLLECTION (Physical) A1 00
' dt 0X09, 0X30 'USAGE (X) 09 30
' dt 0X09, 0X31 'USAGE (Y) 09 31
' dt 0X15, 0X81 'LOGICAL_MINIMUM (-127) 15 81
' dt 0X25, 0X7F 'LOGICAL_MAXIMUM (127) 25 7F
' dt 0X95, 0X02 'REPORT_COUNT (2) 95 02
' dt 0X81, 0X02 'INPUT (Data,Var,Abs) 81 02
' dt 0XC0 'END_COLLECTION C0
' dt 0X09, 0X39 'USAGE (Hat switch) 09 39
' dt 0X15, 0X00 'LOGICAL_MINIMUM (0) 15 00
' dt 0X25, 0X07 'LOGICAL_MAXIMUM (7) 25 08
' dt 0X35, 0X00 'PHYSICAL_MINIMUM (0) 35 00
' dt 0X46, 0X3B, 0X01 'PHYSICAL_MAXIMUM (315) 46 3B 01
' dt 0X65, 0X14 'UNIT (Eng Rot:Angular Pos) 65 14
' dt 0X55, 0X00 ' Unit_Exponent (0)
' dt 0X75, 0X08 'REPORT_SIZE (8) 75 08
' dt 0X95, 0X01 'REPORT_COUNT (1) 95 01
' dt 0X81, 0X42 'INPUT (Data,Var,Abs,NULL) 81 42
' 'configuracion 8 botones
' dt 0x05, 0x09 'USAGE_PAGE (Button) 05 09
' dt 0x19, 0x01 'USAGE_MINIMUM (Button 1) 19 01
' dt 0x29, 0x08 'USAGE_MAXIMUM (Button 8) 29 08 Cantidad maxima de botones
' dt 0x15, 0x00 'LOGICAL_MINIMUM (0) 15 00
' dt 0x25, 0x01 'LOGICAL_MAXIMUM (1) 25 01
' dt 0X35, 0X00 'PHYSICAL_MINIMUM (0) 35 00
' dt 0X45, 0X01 'PHYSICAL_MAXIMUM (1) 45 01
' dt 0x75, 0x01 'REPORT_SIZE (1)
' dt 0x95, 0x08 'REPORT_COUNT (8) 95 08 Modificar junto a cantidad maxima de botones
' dt 0X65, 0X00 'UNIT (none)
' dt 0x81, 0x02 'INPUT (Data,Var,Abs)
' 'dt 0X81, 0X03 'Input const var absolute ! padding
' dt 0XC0 'END_COLLECTION C0
' 'Configuracion 32 botones
' dt 0X05, 0X09 'USAGE_PAGE (Button) 05 09
' dt 0X19, 0X01 'USAGE_MINIMUM (Button 1) 19 01
' dt 0X29, 0X20 'USAGE_MAXIMUM (Button 32) 29 20
' dt 0X15, 0X00 'LOGICAL_MINIMUM (0) 15 00
' dt 0X25, 0X01 'LOGICAL_MAXIMUM (1) 25 01
' dt 0X75, 0X01 'REPORT_SIZE (1) 75 01
' dt 0X95, 0X20 'REPORT_COUNT (32) 95 32
' dt 0X55, 0X00 'UNIT_EXPONENT (0) 55 00
' dt 0X65, 0X00 'UNIT (None) 65 00
' dt 0X81, 0X02 'INPUT (Data,Var,Abs) 81 02
' dt 0XC0 'END_COLLECTION C0



Desc_EndReportDescriptor1:
'
' Configuration pointer table
Desc_USB_CD_Ptr:
Desc_Configs:
CData As Dword Desc_Config1
'
' String pointer table
Desc_USB_SD_Ptr:
Desc_Strings:
CData As Dword Desc_String0, Desc_String1, Desc_String2, Desc_String3
'
' Language code string descriptor
'
Desc_String0:-
dt (Desc_String1 - Desc_String0) / 2 ' Size of this descriptor (in bytes)
dt cUSB_DESCRIPTOR_STRING ' String descriptor type
dt 0x09, 0x04 ' Language ID as defined by MS - 0x0409
'
' Manufacturer string descriptor
'
Desc_String1:-
dt (Desc_String2 - Desc_String1) / 2
dt cUSB_DESCRIPTOR_STRING ; Descriptor string type
CData As Dword "MTH"
'
' Product string descriptor
'
Desc_String2:-
dt (Desc_String3 - Desc_String2) / 2
dt cUSB_DESCRIPTOR_STRING ; Descriptor string type
CData As Dword "MTH-Joystick"
'
' Serial number string descriptor
'3273
Desc_String3:-
dt (_DescriptorMain_ - Desc_String3) / 2
dt cUSB_DESCRIPTOR_STRING ; Descriptor string type
CData As Dword "03"
_DescriptorMain_:
$endif ' _HID_DESC_INC_




Some pictures of the tests. Is running on a 2.2uF capacitor tantaliun on VUSB3V3 pin. Just to try, and works perfect.

32723273


And... a tiny video working:

<span id="result_box" lang="en"><b><i><u><sub><sup><strike>
https://youtu.be/jyBXYyBCm8I

towlerg
27th April 2017, 18:56
Glad to hear you got it working, you must be relieved. Kindda odd though because the only difference between the descriptor you originally posted and the one above is the unintentionally (I assume) embedded picture?

MTH
28th April 2017, 11:24
SORRY, SORRY and SORRY.
I found the error, Thanks to the sample code posted by See_Mos, I found the problem at all.
I in all the tests I did, in a moment, I add USBInit to my program.
Between tests I evidently uncoment the line ($define _usb_ram 1024) and at the same time add the line of the old descriptor.
After the comment towlerg (George), I compare both descriptors with NOTEPAD ++ and I started to test the initial program posted that did not work, until I found the difference, USBInit ...
I apologize for my bad information.
Sorry and thank you very much.



Hi, I think the problem has been something in Proton, I remember that when I get it to work 25K50, apart from modifying the descriptor tube I add this line of code:

$define _usb_ram 1024
Without that line I remembered that I threw some error when compiling, now if I remove that line compiles the same without throwing errors, but it does not work.
I'm really not sure what happened, normally I usually make base codes and, through a copy of them, I start the final program.
This time I did not even start the initial base program.
I usually update the Proton almost constantly and this program had it stopped waiting for the arrival of the plates, as I had a lot of work ahead literally set it aside for a while.

MTH
28th April 2017, 12:25
Strangely with the 18F2550 it works without problems as well without the USBInit

towlerg
28th April 2017, 17:02
Strangely with the 18F2550 it works without problems as well without the USBInit
Apparently USBInit is optional.


Define _usb_ram 1024
From memory, there was a problem with the config file for that device which was corrected several version ago.

MTH
28th April 2017, 19:26
Hi George, yes USBInit is optional, but with 18F25K50 generates a problem, the descriptor does not charge correctly and ends up giving an error.
If you wish, I can make a video of the problem with USBInit in the 18F25K50 and in the 18F2550.

Thanks.

See_Mos
1st May 2017, 12:07
Sorry for the late reply, MTH good to read you got it working.
My code was modified from an earlier version and tested with V3.5.9.2

MTH
1st May 2017, 22:56
Hi See_mos, no problem! Thanks much for you help. Please, for whatever you need I am at your entire disposal.