HID USB on 18F87J50


Closed Thread
Results 1 to 40 of 57

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default Re: HID USB on 18F87J50

    Well, I am not having any luck over here either. Here is my try at using DT_HID260. I have been successful in getting it running on another J chip, the PIC18F47J53, and looking at the two data sheets, the USB doesnt seem to differ much between these two chips. Except on one the USB data memory is below the buffer descriptors, and the other the USB data memory is above the buffer descriptors. The DEV files seem to point to the USB buffer descriptors (67J50 here): USBMEMORYADDRESS Con $400 ' USB RAM starts here

    Here is my code (that does not work)
    Code:
    '***************************************************************************
    '*  Name    : BasicUSB.pbp                                                 *
    '*  Author  : Darrel Taylor                                                *
    '*  Notice  : Copyright (c) 2009                                           *
    '*  Date    : 7/23/2009                                                    *
    '*  Version : 1.x ' Modified by scalerobotics                              *
    '*  Notes   : I tried to edit it to work on a PIC18F67J50 and I failed     *
    '*          : Worked great on other chips, but I can't seem to figure out  *
    '*          : the problem for PIC18F67J50. Board is PIC_LCD3310, which does*
    '*          : work with the USB bootloader,so probably not a hardware issue*
    '***************************************************************************
    'DEFINE LOADER_USED 1
    'DEFINE RESET_ORG 1000h ' For Microchip USB Bootloader
    
    ;--- if you un-comment these, you must comment the ones in the .inc file ---
    ASM  ; 18F2550/4550, 20mhz crystal
    ;   __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    ;   __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
    ;   __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
    ;   __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
    ;   __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    
    ;ASM  ; 18F13K50/14K50  Only 12mhz crystal can be used for USB
    ;    CONFIG CPUDIV=NOCLKDIV ; CPU runing at full speed
    ;    CONFIG USBDIV=OFF ; Low speed USB clock diviser disabled, not used here
    ;    CONFIG FOSC=HS ; Use of High Speed crystal oscillator
    ;    CONFIG PLLEN=ON ; Enable PLL multiplier, 12Mhz oscilator x 4
    ;    CONFIG PCLKEN=ON ; Primary clock source is enabled
    ;    CONFIG FCMEN=OFF ; Failsafe clock off
    ;    CONFIG IESO=OFF ; Oscillator switchover mode disabled
    ;    CONFIG WDTEN=ON ; Watchdog timer on
    ;    CONFIG WDTPS=512 ; Watchdog divider is 512
    ;    CONFIG MCLRE=OFF ; Disable MCLR pin, enable RC3
    ;    CONFIG STVREN=ON ; Stack full/underflow will cause reset
    ;    CONFIG LVP=OFF ; Low voltage programming disabled
    ;    CONFIG BBSIZ=OFF ; 512kW block boot size
    ;    CONFIG XINST=OFF ; Extended instruction mode disabled
    ;ENDASM
    #config         ;pic18F67J50 on Olimex PIC_LCD3310 usb board
        CONFIG PLLDIV = 5    ;for 20 mhz crystal
        CONFIG XINST = OFF
        CONFIG STVREN = off    ;stack overflow reset
        CONFIG WDTEN = OFF    ;added
        CONFIG CP0 = OFF    ;added
        CONFIG IESO = OFF    ;added
        CONFIG FCMEN = OFF    ;added
        CONFIG CCP2MX = DEFAULT    ;added
        CONFIG WDTPS = 32768 
        CONFIG CPUDIV = OSC1  ;DIVIDE BY 1 MODE
        CONFIG FOSC = HSPLL
        CONFIG MSSPMSK = MSK5   ;add
    #endconfig
    
    DEFINE OSC 48
    clear
    OSCTUNE.6 = 1  ' Enable PLL for 18F87J50 family
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
    
    ASM
    INT_LIST  macro    ; IntSource,          Label,  Type, ResetFlag?
            INT_Handler   USB_Handler
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
    
    ;--- Setup USB -------------------------------------------------------------
    INCLUDE "DT_HID260.pbp"
    
    DEFINE USB_VENDORID    6017
    DEFINE USB_PRODUCTID   2000
    DEFINE USB_VERSION     1
    DEFINE USB_VENDORNAME  "Darrel Taylor"
    DEFINE USB_PRODUCTNAME "DT_HID"
    DEFINE USB_SERIAL      "001"
    DEFINE USB_INSIZE      32   ;  IN report is PIC to PC (8,16,32,64)
    DEFINE USB_OUTSIZE     16   ; OUT report is PC to PIC
    DEFINE USB_POLLIN      10   ; Polling times in mS, MIN=1 MAX=10
    DEFINE USB_POLLOUT     10
    
    ; --- Each USB LED is optional, comment them if not used ----
    ;DEFINE USB_LEDPOLARITY 1       ; LED ON State [0 or 1]  (default = 1)
    ;DEFINE USB_PLUGGEDLED  PORTB,0 ; LED indicates if USB is connected
    ;DEFINE USB_TXLED       PORTC,2 ;  "      "     data being sent to PC
    ;DEFINE USB_RXLED       PORTC,1 ;  "      "     data being received from PC
    
    OutCount    VAR  WORD : OutCount = 0
    Value       VAR  WORD
    X           VAR  WORD
    
    ;--- Setup ADC -------------------------------------------------------------
    DEFINE ADC_BITS 10 ; Number of bits in ADCIN result
    '       Configure ADC 
    '       =============
    '   See thread http://www.picbasic.co.uk/forum/showthread.php?t=11128&highlight=18f67j50
    '   for more information about setting analog, and the WDTCON.4 on this chip
    WDTCON.4 = 1   ' Switch to Alternate SFR
    ANCON0_ALT = %10011110
               '  -xx------ Not Implemented
               '  1--1111-- AN7, & AN<4:1> = Digital
               '  -------0- AN0 = Analog
    
    ANCON1_ALT = %11111111
               '  11111111- AN<15:10> = Digital
    
    WDTCON.4 = 0    ' Back to Default SFR
     
    ADCON0 = %00000001
           '  0-------- VCFG1, Vref- 0 = AVss (1=AN2)
           '  -0------- VCFG2, Vref+ 0 = AVdd (1=AN3) 
           '  --0000--- CHS<3:0>, Channel select -- 0
           '  ------0-- Go/Done, don't care for now
           '  -------1- ADON, Enable ADC
                      
    ADCON1 = %10000111
           '  1-------- ADFM, Right justified result
           '  -0------- ADCAL, Normal A/D converter operation
           '  --000---- ACQT<2:0>, A/D Aquisition time = 0 Tad
           '  -----111- ADCS<2:0>, A/D conversion clock = FRC
    ;--- The Main Loop ---------------------------------------------------------
    TRISD = 0
    PORTD.0 = 1   'turn on g sensor
    PORTD.1 = 0   'select scale for g sensor
    PORTD.2 = 0   'select scale for g sensor
    
    
    TRISA = %00000111   'set porta.0, 1, and 2 as inputs
    TRISB = 0
    CM1CON1 = 7   'CM1CON in PBP3 as CM1CON1
    CM2CON1 = 7   'CM2CON in PBP3 as CM2CON1
    TRISC = 0
    TRISE = 0
    pause 100
    ;--- The Main Loop ---------------------------------------------------------
    Main:
        FOR X = 0 to 1000           ; Check for incomming USB data while pausing
    @     ON_USBRX_GOSUB  _HandleRX
          PAUSE 1
        NEXT X
        
        ADCIN 10, Value
        OutCount = OutCount + 1
        ARRAYWRITE USBTXBuffer,["AN0=",DEC Value," -",DEC OutCount,"  "]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
    GOTO Main
    
    ;---- This just sends the received packet back to the PC -------------------
    HandleRX:
        ARRAYWRITE USBTXBuffer,[STR USBRXBuffer\USBBufferSizeRX]
    return

  2. #2
    Join Date
    Sep 2009
    Posts
    755

    Default Re: HID USB on 18F87J50

    I try similar thing, but same result.
    So is it possible there are some bug in PBP for this PIC family?

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: HID USB on 18F87J50

    I'm looking into it too.
    Trying to build a board.

    But first I have to ask ...
    Do you have VDD (3.3V) tied to VUSB?
    There's no internal regulator on those chips.
    DT

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default Re: HID USB on 18F87J50

    I can't speak for Pedja's board, But I am pretty sure Walter is using the PIC_LCD3310. If so that DOES show Vusb tied to 3.3V on the schamatic.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default Re: HID USB on 18F87J50

    Thanks Darrel. I had some weird behavior in my computer. PBP3 kept defaulting to MPASMX, no mater how I set it, I'd check back, and it was set to MPASMX. So after removing the Microchip directory, and re-installing MPLAB 8.76, I was able to get PBP to settle on C:\Program Files\Microchip\MPASM Suite . Now CDC and HID work for the 18F67J50 with PBP3.0! Thanks for routing that out for us!
    Last edited by ScaleRobotics; - 24th August 2011 at 04:46.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default Re: HID USB on 18F87J50

    I have to say I'm glad for Melabs it's not another Microchip twist who had to implement another .HWLIB thing.

    Finger crossed for the next USB pic though... BTW, it's about time Microchip release USB3 AND/OR Thunderbolt.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Sep 2009
    Posts
    755

    Default Re: HID USB on 18F87J50

    Darrel,
    I try your DT_HID260, and it work on first attempt. It's very simple to use.
    But I have question.
    If I want to use 64 byte, #define USB_EP0_BUFF_SIZE should be 64, is that correct?
    Thanks

  8. #8
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default Re: HID USB on 18F87J50

    I have installed MPLAB8,76. Now I get CDC to work on 2.60C, but I don't get the same file to work with PBP3.

    But I am wondering where PBP3 is looking for MPLAB or MPASM? 2.60 allowed you to select the location for PBP, and it also allowed you to show it where the assembler was located. In PBP3 I get this option:

    Name:  pbp3.PNG
Views: 1465
Size:  28.8 KB

    How am I supposed to enter them both? Or are they really supposed to be in the same place??

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: HID USB on 18F87J50

    In the Start menu, go to All Programs > PBP3 from melabs > MPASM-MPLAB setup.
    It allows you to set the path to MPASM.
    DT

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts