USBDemo, something to learn USB a little bit - Page 6


Closed Thread
Page 6 of 7 FirstFirst ... 234567 LastLast
Results 201 to 240 of 279
  1. #201
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,620


    Did you find this post helpful? Yes | No

    Cool

    Hi,

    Last news for me are stamped August, the 14 th ....

    Steve was telling he still need some " quiet " time.

    But do not hope to read from him before " a certain time " ...


    Much Higher priorities thans solving "problems" ( seen quotes ??? ) when solutions just are "in the Manuals".
    May be he "simply" has to take care of himself, ... for once.

    No Forum for that ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #202
    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??

  3. #203
    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

  4. #204
    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??

  5. #205
    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

  6. #206
    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??

  7. #207
    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

  8. #208
    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.

  9. #209
    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

  10. #210
    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?)

  11. #211
    Join Date
    Nov 2009
    Location
    Australia
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Asm ok

    Darrel,
    Tks it of course fixed the error. I should spend more time searching the forum, that trying to solve the problem, and then by default put up a newbee sort of question. Will now wait for my Picstart Plus upgrade kit so I can burn the 18F4550 and have even more fun. Will now search the forum before I ask my next question "does the mcHID.dll work with VB5"
    Tks again.
    Grant

  12. #212
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Here are the 18F4550 _CONFIG settings

    [QUOTE=Darrel Taylor;80423]OzGrant,
    See this thread about how to fix the configs ...
    http://www.picbasic.co.uk/forum/show...=6775#post6775

    Attached .txt document is a list of the _CONFIG settings for the 18F4550 from its corresponding P18F4550.INC file in MPLAB folder. It is always a good idea to have this list handy when setting up code for a new program.

  13. #213
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default This time with the list

    [QUOTE=jellis00;80428
    Attached .txt document is a list of the _CONFIG settings for the 18F4550 from its corresponding P18F4550.INC file in MPLAB folder.QUOTE]
    Forgot to attach with previous post.
    Attached Files Attached Files

  14. #214
    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

  15. #215
    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

  16. #216
    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

  17. #217
    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 19:22. Reason: Add sentence

  18. #218
    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

  19. #219
    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  

  20. #220
    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

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


    Did you find this post helpful? Yes | No

    Default

    OK, this program should work with Steve's original USBDemo GUI.

    18F2550/4550, 8Mhz, DT_INTS-18, DT_HID260.

    Cheers,
    Attached Files Attached Files
    DT

  22. #222
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Data from PIC works...data to PIC doesn't

    Quote Originally Posted by Darrel Taylor View Post
    OK, this program should work with Steve's original USBDemo GUI.
    Darrel,
    Everything compiles/assembles/programs in my EasyPic6 configuration with 18F4550 (8 MHz crystal), and it does run with Steve's VB6 GUI, but only for data from the PIC....data to PIC side of the GUI doesn't work. I double checked that I didn't have anytheng on the EasyPic6 connected to the pins you are using. See attached screen snapshot of the VB6 GUI that shows what is working and what isn't.

    I also notice that when I remove the comments on the DEFINE statements for the status LEDs that they do not light during the PLUGGED, TX or RX actions are supposedly taking place that they are suppose to indicate.

    I looked at your code and I couldn't see where the problem is. Any ideas??
    Attached Images Attached Images  
    Last edited by jellis00; - 10th November 2009 at 20:24. Reason: Added comments re: status LEDs

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


    Did you find this post helpful? Yes | No

    Default

    The ones on the left require 8-LEDs on PORTB, and 2 other LEDs on the CCP outputs, RC1/RC2.

    Previously you said you disconnected the LED's to get things working with the EasyPIC.

    The USB D-/D+ are on RC4/RC5, so I don't think you can just enable the whole bank of LED's on PORTC. You'll need to attach LEDs to only the 2 CCP Pins to get the faders working. But you should be ok with LEDs on PORTB.

    HTH,
    DT

  24. #224
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Talking Working as advertised! Another question.

    Quote Originally Posted by Darrel Taylor View Post
    The ones on the left require 8-LEDs on PORTB, and 2 other LEDs on the CCP outputs, RC1/RC2.
    The USB D-/D+ are on RC4/RC5, so I don't think you can just enable the whole bank of LED's on PORTC. You'll need to attach LEDs to only the 2 CCP Pins to get the faders working.
    Turns out you can enable all the whole bank of LED's on PORTC and it keeps working. You can then see the LEDs on RC1 and RC2 vary in brightness as you change the sliders.

    But you should be ok with LEDs on PORTB.
    Except for the LEDs on RB0, RB5, Rb6 & RB7 (which are used in your code) you can now click the check boxes on B1 thru B4 on the VB6 Gui and they work to light the corresponding LEDs.

    I now have Steve's VB6 GUI and the DT_HID monitor running side by side and everything works as advertised except for the exceptions I listed above for the B0 thru B7 check boxes. Your support to me in getting to this has been outstanding, Darrel. Thanks so much!

    Now I only have to figure out how to capture the data coming across the USB interface from the PIC into a spreadsheet. Your suggestion to use CDC and HYPERTERM would be an easier option except that my application requires a USB interface that is also used to connect to a cell phone, and I don't have physical room for both an RS232 and a USB interface within the physical board size contstraint or panel connector space. Looks like I have to figure out how to do the capture in Steve's USB VB6 GUI. I will modify the PIC side to send comman delimited data per your suggestion, but don't know how to approach capturing the comma delimited data from the VB6 USB Gui that is showing into a spreadsheet. Can you refer me to any forum ideas or reference tutorials in this area??

    Thanks again, Darrell. Your contributions & presence on this forum is what makes it worthwhile.
    Last edited by jellis00; - 11th November 2009 at 01:19.

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


    Did you find this post helpful? Yes | No

    Default

    PORTB.0 is not used anywhere in the program (other than output from the Demo).
    PORTB.5-7 are only used if the USB Status LED lines are uncommented (I left them commented). And they can be assigned to any pin, they don't have to be PORTB.5-7

    CDC is USB, there's no RS232 connector.

    In excel, use the Data | Import External Data | Import Data menu item to just plop your CSV file right into your spreadsheet. Then when the data changes, use Data | Refresh Data to update everything automatically.
    <br>
    DT

  26. #226
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Question One more time

    Sorry to be such a pest, Darrell, but am now trying to adapt your USBdemo_DTID so that it will go into USB connection mode as an interrupt when the USB cable is connected, permitting me in the Interrupt Service Routine to execute some code that is only intended to be executed when the USB cable is connected.
    I thought I could make the simple changes to your code as shown in my attachment below, where I just used a USB_INT with the DT_INTS-18 include file to perform the interrupt to my label "USBhandler".
    This compiles and assembles OK and starts on power up, but when the USB cable is connected I get a WINDOWS error saying "USB Device Not Recognized". Am I missing something here on how to make this work as a USB connection interrupt??
    Code:
    '**************************************************************************
    '*  Name    : USBdemo_DTHID2.pbp                                          *
    '*  Author  : Modification of Steve Monfette/Darrel Taylor                *
    '*  Date    : 11/9/2009                                                   *
    '*  Version : 2.0                                                         *
    '*  Notes   : This is a re-creation of mister-e's USBdemo for DT_HID      *
    '*          : Meant to work with mister-e's GUI but with a USB interrupt  *
    '*          : service routine where some specific code will be executed   *
    '*          : only during USB connection.                                 *
    '**************************************************************************
    ;-- if you un-comment these, you must comment the ones in the .inc file --
    ASM  ; 18F2550/4550, 8mhz crystal
       __CONFIG    _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
       __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
       __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
       __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
       __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
       __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    
    DEFINE OSC 48
    CLEAR
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP high priority interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,          Label,  Type, ResetFlag?
        INT_Handler        USB_INT,    _USBhandler,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
    @    INT_ENABLE   USB_INT    ; enable external (INT) interrupts
    
    ;--- Setup USB -------------------------------------------------------------
    INCLUDE "DT_HID260.pbp"
    
    DEFINE USB_VENDORID    6017
    DEFINE USB_PRODUCTID   2000
    DEFINE USB_VERSION     1
    DEFINE USB_VENDORNAME  "Mister E/DT"
    DEFINE USB_PRODUCTNAME "USBDemo"
    DEFINE USB_SERIAL      "001"
    DEFINE USB_INSIZE      8    ;  IN report is PIC to PC (8,16,32,64)
    DEFINE USB_OUTSIZE     8    ; OUT report is PC to PIC
    DEFINE USB_POLLIN      10   ; Polling times in mS, MIN=1 MAX=10
    DEFINE USB_POLLOUT     10
    
    ; --- Each USB status LED is optional, comment them if not used ------------
    ; --- They can be assigned to any pin, and no further action is required --- 
    DEFINE USB_LEDPOLARITY 1       ; LED ON State [0 or 1]  (default = 1)
    ;DEFINE USB_PLUGGEDLED  PORTB,7 ; LED indicates if USB is connected
    ;DEFINE USB_TXLED       PORTB,6 ;  "      "     data being sent to PC
    ;DEFINE USB_RXLED       PORTB,5 ;  "      "     data being received from PC
    
    
    ;--- Variables -------------------------------------------------------------
    Value0      VAR  WORD
    Value1      VAR  WORD
    X           VAR  WORD
    DUTY1       VAR  WORD
    DUTY2       VAR  WORD
    Old_PORTA   VAR  BYTE
    New_PORTA   VAR  BYTE
    
    ;--- Setup ADC -------------------------------------------------------------
    DEFINE ADC_BITS 8  ; Number of bits in ADCIN result
    
    ;--- Initialize ------------------------------------------------------------
    CCPR1L = 0
    CCPR2L = 0
    CCP1CON =   %00001100       ' CCP1, PWM mode
    CCP2CON =   %00001100       ' CCP2, PWM mode
    PR2     =   249             ' 0-1000 duty range
    T2CON   =   %00000101       ' TMR2 on, prescaler 1:4
    
    TRISB = 0
    OUTPUT PORTC.1
    OUTPUT PORTC.2
        
    ADCON2.7 = 0       ; left justify    (Change this if ADFM in diff register)
    ADCON1 = %1101     ; AN0/AN1 Analog
    
    ;--- The Main Loop ---------------------------------------------------------
    Main:   
        'Normally in sleep mode waiting for interrupts
        Toggle PORTE.2      ' Test LED flashing during Main loop
    GOTO Main
    
    '----------------Interrupt Service Routines Start Here--------------------
    USBhandler:
        FOR X = 0 to 1000         ; Check for incomming USB data while waiting
        @       ON_USBRX_GOSUB  _HandleRX
                PAUSE 1
            
                New_PORTA = PORTA                ; Check PORTA pins
                IF New_PORTA != Old_PORTA THEN
                    Old_PORTA = New_PORTA
                    ARRAYWRITE USBTXBuffer, ["USB Demo"]
                    GOSUB WaitToSend
                    ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTA.2, _
                                             PORTA.3, PORTA.4, PORTA.5,0,0]
                    GOSUB WaitToSend
                ENDIF
            NEXT X
            
            ADCIN 0, Value0            ; Send A/D about once/sec
            ADCIN 1, Value1
            ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTA.2, _
                                     PORTA.3, PORTA.4, PORTA.5,0,0]
            GOSUB SendIfReady
        'Code to be processed only during USB connection.
            TOGGLE PortE.3      ' Test LED that USB interrupt occured
    @ INT_RETURN
    
    ;--- Send Data if Plugged and ready, otherwise discard --------------------
    SendIfReady:
        IF Plugged AND TX_READY THEN DoUSBOut
    RETURN
    
    ;--- Wait till Ready to send of until unplugged ---------------------------
    WaitToSend:
        WHILE Plugged and !TX_READY : WEND
        IF TX_READY THEN GOSUB DoUSBOut
    RETURN
    
    ;---- Receive incoming data PORTB LEDS and CCP PWM dutycycle ---------------
    HandleRX:
        ARRAYREAD  USBRXBuffer,[PORTB, DUTY1.LowByte, DUTY1.HighByte, _
                                        DUTY2.LowByte, DUTY2.HighByte]
        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 Duty2
        CCPR2L=DUTY2>>2         '
    return

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


    Did you find this post helpful? Yes | No

    Default

    DT_HID already uses the USB interrupt.
    If you override it, then USB can't happen anymore.

    Besides, your routine is not suitable for interrupts anyway.
    There's 1000 loops with pauses and gosubs ... wouldn't work.

    There is already a way to determine if the cable is plugged in or not, and that is handled by DT_HID.

    When the cable is plugged in, and the USB is connected to the PC and has fully enumerated. The Plugged bit will be 1. When not plugged, it's 0.

    So just put your routine in the Main loop, and only run it IF Plugged = 1.

    Don't forget to restore the INT_Handler ...
    Code:
    ASM
    INT_LIST  macro    ; IntSource,          Label,  Type, ResetFlag?
            INT_Handler   USB_Handler
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
    Also, DO NOT enter sleep mode when using USB.
    <br>
    DT

  28. #228
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Unhappy Bad News!

    Quote Originally Posted by Darrel Taylor View Post

    Also, DO NOT enter sleep mode when using USB.
    <br>
    So what your saying is I can't have the MCU in SLEEP mode and wake it up with an intterrupt when the USB cable is connected? Unfortunately, that is exactly what we wanted to do to save battery power on our application. It is only going to have someone plug a USB cable into it once per month and we wanted to have the MCU sleep except for about 1 minute at midnight each night and also when it then sees a USB cable plug-in once per month. Keeping it awake all the time to accomadate a possible USB connection will not meet our battery life requirements.
    Is there any way to save power consumption by the embedded processing application when a USB cable is not plugged in???

  29. #229
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,038


    Did you find this post helpful? Yes | No

    Default

    Get +5Vfrom USB itself maybe?

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default

    You can.
    But before you put it to sleep, you'll need to put the USB module in suspend mode UCON.1, which can only be done reliably when unplugged.

    This disables the USB voltage regulator and stops the clock to the SIE, which will give the lowest current consumption.

    The USB routines are not setup to handle a resume.
    So your best bet it probably to connect the +5V from the USB cable to one of the INT pins with a pull-down resistor.

    When the cable gets plugged in, it will generate an interrupt, at which point you would execute an @ RESET to reset the processor and initialize the USB again.

    HTH
    DT

  31. #231
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Made changes per your suggestions...now an assembly error

    :(
    Quote Originally Posted by Darrel Taylor View Post
    The USB routines are not setup to handle a resume.
    So your best bet it probably to connect the +5V from the USB cable to one of the INT pins with a pull-down resistor.
    When the cable gets plugged in, it will generate an interrupt, at which point you would execute an @ RESET to reset the processor and initialize the USB again.
    HTH
    OK, so I made changes to my code per your suggestions (see partial code below) including an IF Plugged =1 test in the Main loop to pole for USB connection and go to my USB servicing procedure when connected. I didn't do anything to get SLEEP mode yet because I want to make sure the interrupts are working first in this code.
    This code compiles, but creates a single error during assembly that says
    "Error[101]c:\PathToAsmfile.asm 1132:ERROR:(INT_ENABLE priority state not found)". So I can't get it to run yet with this error.
    I'm not sure what this error is telling me...the required statement for @ INT_ENABLE INT2_INT is in the code. Does it also require an INT_ENABLE USB_HANDLER statement for the USB interrupt??
    Code:
    Include "Modedefs.Bas"
    INCLUDE "DT_INTS-18.bas"    ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP high priority interrupts
    INCLUDE "ALLDIGITAL.pbp"    ' Sets all registers for digital ops.
    
    DEFINE OSC 48
    
    ;--- if you un-comment these, you must comment the ones in the .inc file--
    ASM ; 18F2550/4550, 8mhz crystal
       __CONFIG    _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
       __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
       __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
       __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
       __CONFIG    _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
       __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    
    ' Initialize Hardware 
    ' ===================
        Spare_1         VAR PORTB.7   ' PGD for ICSP & Spare I/O for normal ops
        Spare_2         VAR PORTB.6   ' PGC for ICSP & Spare I/O for normal ops 
        'Set registers
          TRISA = 0             ' PORTA all outputs for LCD use              
          TRISB =%00011000      ' RB4 & RB3 set as RTC Alarm1 & Alarm2 inputs 
          TRISC = 0      
          TRISD = 0 
          TRISE = 0
       
    '------------SETUP FOR USING DS1337 Real Time Clock (RTC)--------------- 
    '*********************************************************************** 
    ' Setup Hardware for uart
    ' =======================
        DEFINE HSER_BAUD 115200
        DEFINE HSER_RCSTA 90h
        DEFINE HSER_TXSTA 24h
        DEFINE HSER_CLROERR 1
    
    ' Aliased Variables for CLock 
    ' =========================== 
        Alarm1      VAR PORTB.4     ' Alarm1 input from DS1337 INTA
        Alarm2      VAR PORTB.3     ' Alarm2 input from DS1337 INTB
        SCL         VAR PORTB.1     ' I2C clock pin 
        SDA         VAR PORTB.0     ' I2C data pin 
        RTC         CON %11010000   ' RTC device write address(byte addressing)
        ' This is a list of allowable clock contrl settings, one which must be
        ' setup in the SetTimeAndDate subroutine as intended.                   
        'contrl     CON %00000011   ' Starts the oscillator, sets the SQW/OUT 
                                    ' to 1 Hz, enables INTA interrupt from A1F
                                    ' or from A2F.  WORKS as intended!!
        'contrl     CON %00000111   ' Starts oscillator, enables INTA interrupt 
                                    ' from A1F or INTB from A2F. WORKS OK! 
                                    ' Both interrupts staggered 30 secs apart.
     
    ' RTC Address definitions
    ' ======================== 
        SecReg      CON $00   ' seconds address (00 - 59) 
                              ' MSB of SecReg must be set to a 0 to enable RTC 
        MinReg      CON $01   ' minutes address (00 - 59) 
        HourReg     CON $02   ' hours address (01 - 12) or (00 - 23) 
        DayReg      CON $03   ' day address (1 - 7) 
        DateReg     CON $04   ' date address (01 - 28/29, 30, 31) 
        MonthReg    CON $05   ' month address (01 - 12) 
        YearReg     CON $06   ' year address (00 - 99) 
    
    ' Alarm 1 Address definitions 
    ' ===========================
        Alm1sec     CON $07   ' Alarm 1 seconds address (00 - 59) 
        Alm1min     CON $08   ' Alarm 1 minutes address (00 - 59)
        Alm1hr      CON $09   ' Alarm 1 hours address (01 - 12) or (00 - 23) 
        Alm1Day     CON $0A   ' Alarm 1 day address (1 - 7)
    
    ' Alarm 2 Address definitions 
    ' ===========================
        Alm2min     CON $0B   ' Alarm 2 minutes address (00 - 59)
        Alm2hr      CON $0C   ' Alarm 2 hours address (01 - 12) or (00 - 23) 
        Alm2Day     CON $0D   ' Alarm 2 day address (1 - 7)
    
    ' Alias of Clock register addresses
    ' =================================
       ContReg     CON $0E         ' CONTROL register address 
       StatusReg   CON $0F         ' STATUS register address
     
    ' Clock Variables
    ' ================
        sec         VAR BYTE  ' seconds 
        MINs        VAR BYTE  ' minutes 
        hr          VAR BYTE  ' hours 
        day         VAR BYTE  ' day 
        date        VAR BYTE  ' date 
        mon         VAR BYTE  ' month 
        yr          VAR BYTE  ' year 
    
    ' ALARM1 VARIABLES
    ' ================
        A1sec       VAR BYTE  ' seconds 
        A1MINs      VAR BYTE  ' minutes 
        A1hr        VAR BYTE  ' hours 
        A1day       VAR BYTE  ' day 
        
    ' ALARM2 VARIABLES
    ' ================
        A2MINs      VAR BYTE  ' minutes
        A2hr        VAR BYTE  ' hours
        A2day       VAR BYTE  ' day
                               
    GoSub SetTimeAndDate        ' Setup current time & alarm settings 
    
    '*----------------SETUP FOR USING USB INTERFACE------------------------- 
    '*********************************************************************** 
    INCLUDE "DT_HID260.pbp"
    
    DEFINE USB_VENDORID    6017
    DEFINE USB_PRODUCTID   2000
    DEFINE USB_VERSION     1
    DEFINE USB_VENDORNAME  "Mister E/DT"
    DEFINE USB_PRODUCTNAME "USBDemo"
    DEFINE USB_SERIAL      "001"
    DEFINE USB_INSIZE      8    ;  IN report is PIC to PC (8,16,32,64)
    DEFINE USB_OUTSIZE     8    ; OUT report is PC to PIC
    DEFINE USB_POLLIN      10   ; Polling times in mS, MIN=1 MAX=10
    DEFINE USB_POLLOUT     10
    
    ; --- Each USB status LED is optional, comment them if not used ---------
    ; ---They can be assigned to any pin, and no further action is required -- 
    ;DEFINE USB_LEDPOLARITY 1       ; LED ON State [0 or 1]  (default = 1)
    ;DEFINE USB_PLUGGEDLED  PORTB,7 ; LED indicates if USB is connected
    ;DEFINE USB_TXLED       PORTB,6 ;  "      "     data being sent to PC
    ;DEFINE USB_RXLED       PORTB,5 ;  "      "     data being received from PC
    
    ;--- Variables ----------------------------------------------------------
    Value0      VAR  WORD
    Value1      VAR  WORD
    X           VAR  WORD
    DUTY1       VAR  WORD
    DUTY2       VAR  WORD
    Old_PORTA   VAR  BYTE
    New_PORTA   VAR  BYTE
    
    ;--- Setup ADC ----------------------------------------------------------
    DEFINE ADC_BITS 8  ; Number of bits in ADCIN result
    
    ;--- Initialize ---------------------------------------------------------
    CCPR1L = 0
    CCPR2L = 0
    CCP1CON =   %00001100       ' CCP1, PWM mode
    CCP2CON =   %00001100       ' CCP2, PWM mode
    PR2     =   249             ' 0-1000 duty range
    T2CON   =   %00000101       ' TMR2 on, prescaler 1:4
    
    TRISB = 0
    OUTPUT PORTC.1
    OUTPUT PORTC.2
        
    ADCON2.7 = 0       ; left justify    (Change this if ADFM in diff register)
    ADCON1 = %1101     ; AN0/AN1 Analog
    
    '------------------------SETTINGS FOR INTERRUPTS------------------------ 
    '*********************************************************************** 
    'Set interrupt related registers
        RCON.7 = 1     ' Set Interrupt Priority Enable bit (Bit7=IPEN) 
                             ' to enable priority levels on interrupts
        INTCON.7 = 1         ' Set Global Interrupt Enable bit
        INTCON.6 = 1         ' Set PEIE to enable low priority periph interrupts
        INTCON2 = %10001000  ' Enable PORTB Pull-ups (Bit7-high), set INTEG2
                             ' for falling edge (Bit4-low) on RTC's interrupt.
        INTCON3 = %10001000  ' Set INT2IP high priority (Bit7-high), 
                             ' enable INT2IE for interrupt(Bit4-high)
        RTC_INT_FLG  VAR INTCON3.1 'Alias for RB4 INTA interrupt from RTC
    'Setup external interrupt macros
    ASM
    INT_LIST  macro    ; IntSource,         Label,  Type, ResetFlag?
            INT_Handler   USB_Handler
            INT_Handler   INT2_INT,        _Alarm,   PBP,  yes
        endm
        INT_CREATE                ; Creates the interrupt processor
    ENDASM
    @    INT_ENABLE   INT2_INT     ; enable external (INT) interrupts
    
    '  -----------------------BEGIN MAIN PROGRAM LOOP----------------------- 
    '***********************************************************************  
    Main:
        Pause 1000
        IF Plugged = 1 THEN
            HIGH PORTC.6 
            GOTO USB  ' USB cable is plugged-in
        ENDIF
        ' Else, do other things if not connected
        ' If Alarm interrupt, read current time & ALARM settings from DS1337
        ' Perform range measurements if Midnight
        LOW PORTC.6
    USB:
        'Process data from EEPROM to PC via USB interface        
        
        GoTo Main                       ' Endless Loop 
    End     ' Safety measure to insure program stops if reaches here 
    
    '--------------------( Begin Interrupt Handler )------------------------ 
    '*********************************************************************** 
    Alarm:
           HIGH PORTC.7      ' Test LED if Interupt
           '  Put code here to service the Alarm interrupt
           LOW PORTC.7     
        ' Resume Main Program 
    @ INT_RETURN
    End     ' Safety measure to insure program stops if reaches here
    '------------------{ End of Interrupt Handler }---------------------------
    
    ' START LIST OF SUBROUTINES
    '**************************
    Last edited by jellis00; - 8th December 2009 at 00:30.

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


    Did you find this post helpful? Yes | No

    Default

    Put the Interrupt definitions before the HID stuff.

    That's the way it was originally. But it got reversed in your program.

    Also, don't mess with all the INTCON and RCON registers.
    DT_INTS handles all those for you.
    If you change them, it can interfere with the interrupt system.
    <br>
    DT

  33. #233
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default A couple of more questions re: USBDemo

    Darrel, first of all let me commend you on they way you created the USBdemo. It has been a god send to me to save time in getting my application to work with a USB interface. However, I have a couple of more questions:
    1) I notice that this declaration implies you must use BufferIn(X) where X is either 8.16, 32, or 64.
    "DEFINE USB_INSIZE 8 ; IN report is PIC to PC (8,16,32,64)"
    Is that true also with the BufferOut(X) per this statement?
    DEFINE USB_OUTSIZE 8 ; OUT report is PC to PIC
    I ask this question because I need 10 data elements per BufferOut transmission for my application and didn't know whether I could size the BufferOut as 10 or would have to use 16.

    2) In my application I need the PIC to read individual Bytes out of EEPROM and then send them as data to the PC via the USB interface. The data is stored in EEPROM during normal ops as 75 data sets, each data set consisting of 3 bytes. The PIC code reads each data set into a three element array, arrData(i,j,k), where i, j,k range from 0 to 74. My question is how to code the PIC to best fit this data into the BufferOut array to send each arrData(i,j,k) over the USB interface, at the rate of one per second. The data is in the PIC code in the form of:
    arrData(0,0,0)
    arrData(1,1,1
    arrData(2,2,2)
    |
    |
    arrData(74,74,74)
    I want each data set to show up at the PC as the three bytes contained in the array element. I guess my question is in essence how to convert each array element into the three BufferOut(X) bytes for transmission.

    3) I also notice that the PC's RX Window of my application is showing continuous receipt of a e garbagvalue shown as "p|?|6||", even when none of the PORTA pushbuttons are pressed. But when PORTA.4 button is pressed, the string value "USBDemo" is correctly received. However, when any of the other PORTA buttons are pressed it has no impact on the data stream and just shows another "p|?|6||". All other functions of the USBDemo interface work OK. It almost seems like there is a continuous button bounce going on in PORTA, but causing transmit of garbage values rather than the "USBDemo" string. I don't have a debug ability to see what is causing this. Any ideas?? If seeing my code would help you to assess this, let me know and I will somehow get it to you.
    Last edited by jellis00; - 11th January 2010 at 19:30.

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


    Did you find this post helpful? Yes | No

    Default

    Both USB_INSIZE and USB_OUTSIZE can only be 8,16,32 or 64.
    If you want to send 10-bytes per report, it needs to be 16.

    Question 2, I don't understand.
    If you have them in arrays, just copy them to the USBTXBuffer.

    And what looks like "garbage data" is the analog reading from the pots being sent periodically.
    <br>
    DT

  35. #235
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Question2??

    Quote Originally Posted by Darrel Taylor View Post
    Question 2, I don't understand.
    If you have them in arrays, just copy them to the USBTXBuffer.
    <br>
    That is my problem...I don't know how to structure the code to write each array element of arrData(i,j,k) to the USBTXbuffer. Each of the elements of the USBTXbuffer is a single byte, whereas each element of the array is 3 bytes.
    Are you saying I will still need to parse each array element into 3 bytes and then load each byte into one of the output buffer bytes??

  36. #236
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,038


    Did you find this post helpful? Yes | No

    Default

    Arrays in PBP can be byte or word. Not 3 bytes wide. So, what Darrel suggested is still valid.

    I suppose that you don't know how to read 3 bytes everytime into a 8-byte buffer?

    If so, just fill the rest with zero.

    Ioannis

  37. #237
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Got it!

    Quote Originally Posted by Ioannis View Post
    Arrays in PBP can be byte or word. Not 3 bytes wide. So, what Darrel suggested is still valid.
    I am ashamed to admit I missed that in terms of how PBP handles arrays. Probably because I hadn't worked with arrays in PBP until version 2.6 finally supported them.
    I now understand what I have to do...it will be simpler to read the data from the EEPROM a byte at a time and insert it into its respective BufferOut(x).

    Thanks to both Ioannis and DT for setting me straight on this!

  38. #238
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Question re: DT_INTS

    Quote Originally Posted by Darrel Taylor View Post
    Also, don't mess with all the INTCON and RCON registers.
    DT_INTS handles all those for you.
    If you change them, it can interfere with the interrupt system.
    <br>
    Darrel, I have discovered that when I am using INT2_INT interrupt source from DS1337 to the 18F4550 that I have to have the INTCON2 statement per below code...otherwise the interrupt doesn't work. When you said that I shouldn't mess with the INTCON register settings because DT_INTS takes care of them, did you mean only the GIE setting?? In fact, can you explain which of the INTCON register settings ARE NOT handled by DT_INTS, if more than just this one for INT2 falling edge??

    Code:
    '----------------------[ SETUP FOR INTERRUPTS ]-------------------------  
    ASM
    INT_LIST  macro    ; IntSource,         Label,  Type, ResetFlag?
            ;INT_Handler   USB_Handler
            INT_Handler   INT2_INT,        _Alarm,   PBP,  yes
        endm
        INT_CREATE                ; Creates the interrupt processor
    ENDASM
    
    @    INT_ENABLE   INT2_INT     ; enable external (INT) interrupts
    ' Per DT, DT_INTS already takes care of setting INTCON and RCON registers
    ' but this doesn't work unles INTCON2 set per below:
        'INTCON.7 = 1         ' Set Global Interrupt Enable bit
        INTCON2 = %00000000  ' Set INT2 for falling edge (Bit4-low)
                             ' on RTC's interrupt.
        'INTCON3 = %10010000  ' Set INT2 high priority (Bit7-high), enable INT2
                             ' (Bit4-high)

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


    Did you find this post helpful? Yes | No

    Default

    Enable bits (IE), Interrupt Flags (IF) or Priority bits (IP).
    Don't "mess" with them. That includes GIE and PEIE or GIEL.

    Many interrupt sources have registers that affect the specific peripheral.
    For instance ...
    • If you don't set TXSTA and RCSTA then you will never get proper interrupts from the USART.
    • If you don't set T1CON, you will never get interrupts from TMR1_INT.
    • And ...
      If you don't set the INTEDG bits, you may never get the correct interrupt from INT2_INT.

    You have to tell the hardware how to handle the signals.
    DT_INTS will handle the interrupts.
    <br>
    DT

  40. #240
    Join Date
    Dec 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Hi Guys,

    Ive got a bit of a problem with the USB thats got me stumped and hope you can help.

    Im using DT's interupts and have setup INT_INT to read a DS18S20+ temp sensor which works fine and I can display it on the LCD lovely.

    My problem is that trying to use the USB it works with the interupt for the temp probe ok, but as SOON as I use LCDOUT I get the USB device not recognised

    Even splattering USBSERVICE after all the lines in the main loop it still wont recognise it.

    I have tried both ON INTERUPT and DT's TMR0_INT for the USBSERVICE but nothing I do will get it working unless the LCDOUT is removed.

    I can post the code if required but thought I would just write the problem first in case its something obvious im missing.

    Many thanks,

    Mark

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08: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, 11:38
  3. Replies: 9
    Last Post: - 31st July 2008, 09:56
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 01:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 02:07

Members who have read this thread : 3

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