USBDemo, something to learn USB a little bit


Closed Thread
Results 1 to 40 of 279

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    USBDemo was a good starting point for me, Thanks Steve.
    But there are several problems that don't coincide with what you want.

    1) When you disconnect the cable, it will still try to send data, causing the PIC to enter a Locked Loop, waiting to send to an inactive bus.

    2) You really have no indication that anything was received.
    If there's no incoming data, it just goes ahead and sets the dutycycles again, using the old data left over in the buffer.

    3) There's no indication of when it's connected, when something was received or when it's ok to send.

    4) With the 1mS servicing from Timer0, it's a bit sluggish when enumerating, overall data rates suffer and it uses TMR0 when it doesn't need to.

    5) EasyHID no longer works with 2.60, so it's difficult to make changes to the descriptors.

    6) I don't use Visual Basic, so I can't update the PC program.
    My main language is Delphi, and I stopped using mchid.dll a long time ago.

    I would have worked with Steve to build a better demo, but alas, he's not here.
    <hr>
    I'm thinking it's time to unveil DT_HID.
    It's the PIC side of USB, made ... yes, I'll say it ... EASY!

    The PC side is still up to you, but it even works with Steve's original VB prog, so that, or any other VB/Delphi program from EasyHID can be used as a "template".

    I'm not even going to tell you how it works.
    I defy you to not understand what it does.
    Up until you ask a question.

    Warning, the example is setup for 13K50/14K50.
    Comment the configs, and uncomment the other configs (if needed).
    Change ANSELs to ADCON1 (if needed).

    Also note: This is for PBP 2.60 only.
    BasicUSB.pbp is the test program.

    Don't shoot me, I can't even play a piano ...
    Attached Files Attached Files
    DT

  2. #2
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Question Compiles and programs but USB doesn't connect

    Quote Originally Posted by Darrel Taylor View Post
    USBDemo Warning, the example is setup for 13K50/14K50.
    Comment the configs, and uncomment the other configs (if needed).
    Change ANSELs to ADCON1 (if needed).
    I made these changes to the BasicUSB.pbp code for use with 18F4550 as you can see in my listed code below. It compiles OK into a .hex file which I then programmed into the 18F4550 using the PicFlash programmer in my EasyPic6. By all appearances everything was OK until I turned on power to the MCU with Steve's VB6 program running....at that point the USB connection was not recognized and nothing else happened. Can you look at this code and tell me what is wrong. I made shure both the include files were in the PBP folder and since it compiled I interpreted that to mean the INCLUDES were OK. Since I was able to get Steve's code to run in my EasyPic6 I believe that eliminates the VB6 code as the problem, so need to figure out how to debug yours and when it doesn't connect or do anything visible, I don't know how to debug it.

    I'm not even going to tell you how it works.
    I defy you to not understand what it does.
    Up until you ask a question.
    I studied the code in both the test program and in DT__HID.bas and unfortunately I guess I don't understand what it does since I can't get it to work. I need your HELP.
    Code:
    '**********************************
            '*  Name    : BasicUSB.pbp        *
            '*  Author  : Darrel Taylor       *
            '*  Notice  : Copyright (c) 2009  *
            '*  Date    : 7/23/2009           *
            '*  Version : 1.0                 *
            '*  Notes   :                     *
            '*          :                     *
            '**********************************
    ;--- if you un-comment these, you must comment the ones in the .inc file ---
    ASM  ; 18F2550/4550, 8mhz crystal as used in EasyPic6
       __CONFIG    _CONFIG1L, _PLLDIV_2_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    _CONFIG1L, _CPUDIV_NOCLKDIV_1L & _USBDIV_OFF_1L
    ;    __CONFIG    _CONFIG1H, _FOSC_HS_1H & _PLLEN_ON_1H & _PCLKEN_ON_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    ENDASM
    
    DEFINE OSC 48
    clear
    
    ;--- 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
    ADCON2.7 = 1        ; right justify    (Change this if ADFM in diff register)
    ADCON1 = %00010000  ; AN4/RC0 Analog
    'ANSELH = 0
    
    ;--- 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 4, 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

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


    Did you find this post helpful? Yes | No

    Default

    Apparently, I missed the CONFIG2L.
    I always miss that one, weird ...
    Code:
       __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
    And try the HIDmonitor program from the .zip

    When I said it works with Steve's original program, well it will, but it's not set up to send/receive the same analog values and switches/LED's. With HIDmonitor you should see when it connects and what data it's sending.

    hth,
    DT

  4. #4
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Made config change..compiles, nothing happening

    [QUOTE=Darrel Taylor;80452]Apparently, I missed the CONFIG2L.
    I always miss that one, weird ...
    Code:
       __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
    I made this _CONFIG change in the code. Compiles/assembles OK and appears to program the 18F4550 OK.

    And try the HIDmonitor program from the .zip

    When I said it works with Steve's original program, well it will, but it's not set up to send/receive the same analog values and switches/LED's. With HIDmonitor you should see when it connects and what data it's sending.
    Tried both your HIDmonitor and Steve's VB6 routine after programming and power/resetting the 18F4550 . Although I hear a low "click" and see the USB icon appear in my WINDOWS tray when the USB cable is connected from the PC, I don't see any indication of the connection on the HIDmonitor or on Steve's VB6. And the USB icon disappears out of the tray about 10 secs after the next keyboard key or mouse button is pressed with no audible "click". Nor do I hear another "click" or see any visual indication of disconnect when USB cable is disconnected. Nor is there any indication of any communications on either the HIDmonitor or the VB6 window.

    Do you have any suggestions how I might monitor what is happening in the code while running so I can debug? I don't have a usable ICD.
    Last edited by jellis00; - 5th November 2009 at 18:22. Reason: Add sentence

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


    Did you find this post helpful? Yes | No

    Default

    Before I posted last time, I copied your program to MCS, added the config2L and changed my crystal to 8mhz.

    It fired right up, and is still connected now.
    It shows up as DT_HID (001) in HIDmonitor.

    Do you have anything on RB0, RC1 or RC2.
    I've got some Status outputs to LED's on those pins, that shows when it's connected and when it sends/receives data.

    You did have the hardware working before right?
    <br>
    DT

  6. #6
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Working!..a couple of more questions.

    Quote Originally Posted by Darrel Taylor View Post
    Do you have anything on RB0, RC1 or RC2.
    I've got some Status outputs to LED's on those pins, that shows when it's connected and when it sends/receives data.<br>
    Thanks, Darrel...this led me to the problem. The EasyPic6 has dip-slide switches that let you connect LEDs to the A/E, B, C, and D ports for troubleshooting. I had the switch selected for Ports B and C. When I finally realized I needed to shut them off everything started working properly.

    However, one question. I notice while running MisterE's VB6 monitor side-by-side with your DT_HID monitor I see the Rx data showing some variances. I have attached a screen-snapshot of this so you can see.

    Notice in the screen snapshot that when when AN=123, AN0= 1023; when AN=51, AN0=510, and when AN=-4, AN0=0. Since both are receiving the same data as transmitted by the PIC, shouldn't the displayed values be equal in both monitors??? Don't understand this. Can you explain for me??

    My next step is to figure out how to capture what appears in the DT_HID Rx data window into a text file or better yet into a spreadsheet. Any suggestions as to how to do this in the DT_HID code?,
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default

    Great, I thought I lost you.

    The program is sending different data than mister-e's PC program is expecting.
    I guess my example was off thread, and I should make an example that does work with his GUI.

    My next step is to figure out how to capture what appears in the DT_HID Rx data window into a text file or better yet into a spreadsheet. Any suggestions as to how to do this in the DT_HID code?,
    In Delphi sure ... can't help with Visual Basic though.

    It may even be easier with CDC and Hyperterminal.
    Outputting the data in CSV format from the PIC, and capturing it with the terminal, makes it real easy to import into excel. But it does require user intervention.
    If it's has to be automatic, HID's the way, whether it's DDE exchanges, or saving the file and importing to excel.

    Anyhow, I'll go make a more appropriate demo for Steve's GUI.

    BBL,
    DT

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Quote Originally Posted by Darrel Taylor View Post
    ...
    Also note: This is for PBP 2.60 only ...
    Someone found a workaround for PBP 3:

    http://www.picbasic.co.uk/forum/show...599#post126599

    Robert

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 10:38
  3. Replies: 9
    Last Post: - 31st July 2008, 08:56
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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