USBDemo, something to learn USB a little bit


Closed Thread
Results 1 to 40 of 279

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default One statement causes compile error

    Quote Originally Posted by Darrel Taylor View Post
    . If you haven't already ... download and extract the USBDemo from the beginning of this thread.

    . Then create a new folder (USBDemo260) and copy the USBDemo.pbp file from Steve's archive into the new folder.
    That is the only file that is valid with 2.60, so don't copy any of the others.

    . Download the USBDEMOdesc.bas.txt (descriptor) file attached to this post and place it in the same folder. Remove the .txt extension.

    . In the USB18 folder, inside your PBP folder ...
    Copy the following files to the project ...

    usb_dev.asm
    usb_dev.inc
    usb_hid.asm
    usb_hid.inc
    usb_mem.asm


    . Add this line to the USBDemo.PBP program ... and compile.
    Code:
      INCLUDE "USBDEMOdesc.bas"
    Darrel, I followed steps you listed explicitly and then tried to compile with PBP 2.6. Got the following error:
    " ERROR line 81: Redefinition of VAR. USBDemo.pbp]"
    which I don't understand since the UCFG variable is not declared anywhere else in the code...just this line where the code occurs.
    The error applies to the statement
    "UCFG VAR BYTE EXT ' include UCFG register... Yeah Melabs didn't ("

    I went to manual on 2.6 compiler to check syntax of this statement. I guess I don't understand the use of EXT at the end of the statement....manual doesn't explain that.

    Can you tell me what might be wrong and why this won't compile?? I would really like to get this USBDemo going for my 18F4550.

    Also don't understand why Steve's schematic that you posted varies from the hardware description in the USBDemo260 code:
    Here is the Hardware description from the code:
    Hardware:
    ' ---------
    ' 4 Push Buttons on PORTA<5:2> with pull-down resistors
    ' 2 Trim pot on PORTA<1:0>
    ' 8 LEDs attach between PORTB and GND
    ' 2 LEDs attach to CCP<2:1> pins
    ' 4 MHZ crystal & all the usual USB stuff
    Yet the schematic shows no pushbuttons on PORTA <5:2>, no trim pota on PORTA <1:0>, no LEDS on PORTB or CCP, and a 20 MHz crystal rather than 4 MHz. Can you advise me of the correct hardware hookups for the USBDemo260 code...the schematic or the code description??

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jellis00 View Post
    Darrel, I followed steps you listed explicitly...The error applies to the statement "UCFG VAR BYTE EXT
    Quote Originally Posted by Darrel Taylor View Post
    ... And comment out the UCFG EXT variable since it's not needed anymore. ...
    Steve wrote that program when 2.46 was the latest and greatest.
    At that time UCFG VAR EXT was missing from the PIC18EXT.bas file.
    But with 2.60, the oversight has been corrected, so you don't need that line anymore.
    Well actually, you didn't need it then either, it's handled by the USB routines.
    So not sure why he put it there to begin with.

    The schematic is the one you requested.
    It was originally from Mecanique, and I'm sure he was showing how to hook up the USB stuff.
    And probably assumed the user would know how to connect LED's and switches on their own.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default Compiles OK now!

    Quote Originally Posted by Darrel Taylor View Post
    At that time UCFG VAR EXT was missing from the PIC18EXT.bas file.
    But with 2.60, the oversight has been corrected, so you don't need that line anymore.<br>
    Thanks, Darrel. That fixed it and it now compiles. Sorry I didn't read your comment more closely about commenting out this statement.
    My next step, now that it will compile, is to configure my hardware on an EasyPic6 and then program the 18F4550 and run the program.

    One question: Do I need to run the VB6 program on my PC with the USB cable connected before I turn on power to the 18F4550 and run its code??

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jellis00 View Post
    Thanks, Darrel. That fixed it and it now compiles.
    Sweet!

    One question: Do I need to run the VB6 program on my PC with the USB cable connected before I turn on power to the 18F4550 and run its code??
    Doesn't matter, the VB program will pick up when it connects, and sometimes when it disconnects.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default Now working except for RA4 pushbutton??

    Quote Originally Posted by Darrel Taylor View Post
    Sweet!
    Doesn't matter, the VB program will pick up when it connects, and sometimes when it disconnects.
    <br>
    Darrell, thanks to your help I now have the USBDemo running on my EasyPic6 and everything appears to work except an annomaly with the RA4 pushbutton. When I initially power up, the VB6 window shows all four pushbutton lights on (GREEN). When I push each of the RA2-RA5 pushbuttons on the EasyPic6, the lights go temporarily out while the pushbutton is depressed, which is expected. However, when RA4 is released it stays unlit, unlike the other pushbuttons. Then if I power down and power backup or if I reset, it is lit again along with the others, and the sequence described above happens again if I depress the buttons.
    I don't understand why the RA4 pushbutton doesn't operate like the others as a momentary switch. I checked the code and it appears it should. Is there some reason for this? I thought it might even be a problem with my EasyPic6, but the RA4pushbutton is operating normally in other codes I have that use it on the EASYPIC6. I didn't do anything about changing the capacitors on the EasyPic6 that

    I also notice that the RX window continuously shows 10 line entries of "USBDemo" and when you click the Clear RX button, it immediately repopulates the RX window with the same 10 entries. I am trying to understand this and presume that these entries are due to the TMR0 interrupt executing every 100 usec to run the goto at DoUSBService, which reloads the TMR0. I presume each time this reload takes place and the TMR0 overflows, a USBDemo line appears in the RX window. Am I understanding what is happening???

    I am TOTALLY impressed with this code and the functionality Steve created in this demo! He is to be highly commended for sharing this since it helps people (like me) to finally understand at a basic level how to incorporate a USB interface into our applications.
    Now I have to figure out how to modify it for a specific application that operates this way...am explaining in hopes you or someone else on this thread will have some ideas:
    1) the Main code wakes up from SLEEP mode every night at midnight and executes 6-12 ultrasonic range finder measurements which are averaged and the average result is logged into EEPROM, and then it goes back to SLEEP till next midnight.
    2) This data logging occurs every night at midnight. If at any time a USB cable is plugged into the USB connector (which will only happen once every 30 days to download the 30 averaged range measurements from EEPROM), it must recognize this as an interrupt to the normal data logging application and permit the User on the other end of the USB interface (a laptop) to recover the 30 averaged range measurements from EEPROM to the laptop and export them into a spreadsheet.
    Now that I have the USB interface working, I am struggling with how best to support this scenario with an interrupt that recognizes when the USB cable is connected. I thought I might use an RBIE: RB Port Change Interrupt in the MCU code that would be created by the laptop User when one of the RBx boxes in the VB6 User Interface is clicked. Do you have any better suggestions as to how to do this??

    Would also appreciate any pointers you might have to the best approach for a midnight to midnight interrupt without having to add a RTC to my application. I thought a TMR1 approach with 24 hr delays might work for this, but have doubts that it would keep time accuracy well enough to always happen exactly at midnight. Any ideas are appreciated??

  6. #6
    Join Date
    Nov 2009
    Location
    Australia
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Problems with ASM

    G'day
    Have 2.60 PBP and did the latest setup etc as per the last few posts.
    I now get the following errors when compiling.

    ERROR: Unable to execute mpasmwin.Error[118] C:\PBP\USBDEMO260\USBDEMO.ASM 413 : Overwriting previous address contents (0000)

    Error[118] C:\PBP\USBDEMO260\USBDEMO.ASM 413 : Overwriting previous address contents (0001)
    etc.

    Any ideas,
    Tks

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by OzGrant View Post
    I now get the following errors when compiling.
    ERROR: Unable to execute mpasmwin.
    Error[118] C:\PBP\USBDEMO260\USBDEMO.ASM 413 : Overwriting previous address contents (0000)
    Error[118] C:\PBP\USBDEMO260\USBDEMO.ASM 413 : Overwriting previous address contents (0001)
    etc.
    OzGrant,
    See this thread about how to fix the configs ...
    http://www.picbasic.co.uk/forum/show...=6775#post6775

    jellis00,
    Uno momento ...
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default Try this

    Quote Originally Posted by OzGrant View Post
    Error[118] C:\PBP\USBDEMO260\USBDEMO.ASM 413 : Overwriting previous address contents (0001)
    Make sure you commented out the _config statements in the 18F4550.inc file and resaved it. If you don't the _config statements in the USBDemo code will give this type of error. I don't have any ideas as to the other error...sorry!

    What is your development environment?....editor (MicroCode Studio, MPALAB or what?)...assembler (MPASM or PM?).....programmer (PicKit2, EasyPic or what?)

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


    Did you find this post helpful? Yes | No

    Default Solved problem! Would still like answer to other questions.

    Quote Originally Posted by jellis00 View Post
    I don't understand why the RA4 pushbutton doesn't operate like the others as a momentary switch. I checked the code and it appears it should. Is there some reason for this?
    I also notice that the RX window continuously shows 10 line entries of "USBDemo" and when you click the Clear RX button, it immediately repopulates the RX window with the same 10 entries. I am trying to understand this...
    The problem resolved itself and I don't know exactly why. The only changes I made were to make sure the pull-down resistors were enabled properly and to connect the RA0 pin to the potentiometer for the Analog A/D input. Either as a result of these changes or some other unknown reason, the annomaly of the RA4 pushbutton and the "USBDemo" messages in the RX window went away. I see now that the "USBDemo messages are not a result of the TMR0 reloads but only appear when the pushbuttons are pressed and the RX window clears normally now and stays clear until the next pushbutton.
    Even though these problems are solved, I would still appreciate any inputs/ideas regarding my other questions. It begins to look like I can achieve my intentions for detecting USB connection by implementing the "self-power only" circuit as shown in Figure 17-11 of the 18F4550 data sheet. Will try it and report in later post.

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


    Did you find this post helpful? Yes | No

    Default

    This is a update to Mister E's VB6 demo program, and firmware that uses Darrel's DT_HID260.pbp include file. It brings back some of the functions that went away with the HID update, and it adds a few more. It now transfers 10 bit A/D conversions to the PC, and it has a really low bandwidth mschart function. It also transfers the port info up to the computer in a single byte, and it's read by VB in bits. (It is hard to read bits with VB!) Ports are changed to match the Olimex PIC-USB-STK ( http://www.olimex.com/dev/pic-usb-stk.html ) . On the chart, it's a little over a second from left to right. By the way, if anyone knows how to keep the mschart from flickering as it is being redrawn, please let me know.

    Name:  scope.PNG
Views: 19656
Size:  41.6 KB


    VB6 doesn't make it very easy to be sure you have include all the necessary files, so if you have issues, let me know. The code was made for a PIC18F4550 with a 20 mhz crystal. You will also need Darrel's DT_HID260 file from here: http://www.picbasic.co.uk/forum/show...0434#post80434

    (Thanks Steve and Darrel for giving me the USB bug!)

    Code:
    '****************************************************************************
    '*  Name    : USB_Demo_4_HID.pbp                                            *
    '*  Author  : Walter Dunckel ScaleRobotics using Darrels example as template*
    '*  Notice  : Copyright (c) 2011                                            *
    '*  Date    : 1/13/2011                                                     *
    '*  Version : 1.1                                                           *
    '*  Notes   : Added Darrel's text example                                   *
    '*          :                                                               *
    '****************************************************************************
    ;--- 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
    'add if using Microchip's HID Bootloader
    'DEFINE LOADER_USED 1
    'DEFINE RESET_ORG 1000h ' For Microchip USB Bootloader
     
    ;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
    ;    
    ;    ;added
    ;    __CONFIG    _CONFIG2H, _WDTEN_ON_2H & _WDTPS_512_2H
    ;    __CONFIG    _CONFIG3H, _MCLRE_ON_3H 
    ;    __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_OFF_4L & _XINST_OFF_4L
    ;ENDASM
     
    DEFINE OSC 48
    clear
     
    PortA = %00000000
    TrisA = %00000001
    PortB = %00000000
    TrisB = %11110100        'make pushbuttons inputs for PIC-USB-STK
    'TrisB = %00010000 'for 18k50
    PortC = %00000000
    TrisC = %00000000
    TrisD = %00000000
    CMCON = 7
    'CM1CON0 = 7  'for 18f14k50
    'CM2CON0 = 7
     
            '   CCP/PWM
            '   -------
    CCP1CON =   %00001100       ' CCP1, PWM mode
    CCP2CON =   %00001100       ' CCP2, PWM mode
    PR2     =   249             ' 12khz PWM Freq
    T2CON   =   %00000101       ' TMR2 on, prescaler 1:4
    ;--- 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  "ScaleRobotics"
    DEFINE USB_PRODUCTNAME "Cheap-Scope"
    DEFINE USB_SERIAL      "001"
    DEFINE USB_INSIZE      8   ;was 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  PORTD,0 ; LED indicates if USB is connected
    'DEFINE USB_TXLED       PORTD,2 ;  "      "     data being sent to PC
    'DEFINE USB_RXLED       PORTD,1 ;  "      "     data being received from PC
     
    OutCount    VAR  WORD : OutCount = 0
    Value       VAR  word   'analog result from AN0
    Value2      var  word   'analog result from AN11
    X           VAR  WORD
    counter     var  byte
    Duty1       var  word EXT ' make them available 
    Duty2       var  byte EXT
    smallvalue  var  byte
     
    ;--- Setup ADC -------------------------------------------------------------
    DEFINE ADC_BITS 10 ; Number of bits in ADCIN result
    ADCON2.7 = 1       ; right justify    (Change this if ADFM in diff register)
    'ANSEL = %00000000  'for 18f14k50
    'ANSELH = %00000100  'for 18f14k50
    ADCON0 = %00000001 ' turn on a/d   AN0
     
    ;--- The Main Loop ---------------------------------------------------------
    pause 2000                               'wait for connection
    ARRAYWRITE USBTXBuffer, ["USB Demo"]    'show text example
    GOSUB WaitToSend  
     
    Main:
        FOR X = 0 to 2           ; Check for incomming USB data while pausing
    @     ON_USBRX_GOSUB  _HandleRX
          PAUSE 1
        NEXT X
        ADCin 8, value2
    @Duty1=_USBRXBuffer+1 
    @Duty2=_USBRXBuffer+3 
        counter = counter +1 
        ADCIN 0, Value
        ARRAYWRITE USBTXBuffer,[portb,counter,value.highbyte,value.lowbyte,Value2.highbyte,Value2.lowbyte,0,0]
        CCP1CON.5=DUTY1.1       ' load CCP1 duty value            
        CCP1CON.4=DUTY1.0       '      with Duty1 
        CCPR1L=DUTY1>>2 
        CCP2CON.5=DUTY2.1       ' load CCP2 duty value            
        CCP2CON.4=DUTY2.0       '      with Duty1 
        CCPR2L=DUTY2>>2 
        portd = usbrxbuffer[0]
        'IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        gosub SendIfReady
    GOTO Main
     
    ;---- This just sends the received packet back to the PC -------------------
    HandleRX:
        ARRAYWRITE USBTXBuffer,[STR USBRXBuffer\USBBufferSizeRX]
    return
     
    SendIfReady:
        IF Plugged AND TX_READY THEN DoUSBOut
    RETURN
     
    WaitToSend:
        WHILE Plugged and !TX_READY : WEND
        IF TX_READY THEN GOSUB DoUSBOut
    RETURN
    Edit:
    Ok, now looking at Darrel's post 221 http://www.picbasic.co.uk/forum/show...0611#post80611 , he already made the program compatible with most of the original functions for the 18F4550. So I (also) lifted his code to transfer text to the PC. However, I only do this at power up, so I don't slow the analog transfers down.
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by ScaleRobotics; - 2nd May 2011 at 01:30. Reason: Added code in code tags
    http://www.scalerobotics.com

  11. #11
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default

    FormMain.frm is missing...

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by pedja089 View Post
    FormMain.frm is missing...
    Thanks pedja089, I just added it.
    http://www.scalerobotics.com

  13. #13
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default

    Excellent project!
    Not too complicated, but there are interesting examples of communication and usage of DT's include files.
    Perhaps you should add the LCD.
    Here is my example how to sendtext from winamp to lcd:
    http://www.elektronika.ba/506/lcd-winamp-plugin-on-usb/
    I hope that you will manage the translation...

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