[SOLVED !] More USB issues...


Closed Thread
Results 1 to 11 of 11

Thread: More USB issues...3302 days old

  1. #1
    wastrix
    Guest wastrix's Avatar

    0 Not allowed!

    Default More USB issues...

    Hi,

    I am still having problems with USB in PDS.

    What I am trying to do is send an 832 byte buffer with USBOut, in 64 byte packets.

    I can get it to work by copying 64 byte segments of the 832 byte buffer into another buffer, and then send this with USBOut, but every us counts here and that is too much time wasted, especially since the USBOut command then copies it to a third buffer before sending.

    What I should be able to do is something like:
    Code:
    'send 13x64 byte packets
    For k = 0 To 768 Step 64
        Repeat 
            USBOut 1, OutBuffer[k], 64
        Until STATUS.0 = 0
    Next
    For example if I dim OutBuffer at address 100, the first time the loop runs it reads from 100-163, the second time it reads 164-227, etc.

    This doesn't work however as the code generated by the USBOut command loads the indirect addressing set with lfsr, which only supports a literal argument.

    What can I do? This is ridiculous!

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,676
    Thumbs Up
    Received: 47
    Given: 95
    Total Downloaded
    1.32 GB

    0 Not allowed!

    Default Re: More USB issues...

    First of all you have to check if the previous data has been sent. USB out just copies buffers and sets state machines running. The data being sent is done by the hardware so you have plenty of time to fill the buffer for the next batch,

    Also its only the 14k50 etc that needs 64byte packets, the 2550 sends 256 bytes at a time.

    You should also know Proton will not work with buffers over 256bytes after that you do it your self
    Filling the buffer is simple

    Code:
    USBout:
    USBLoop: 
        USBPoll 
        If TRNIF = 1 Then GoTo USBLoop
    DoUSBNow:  
        Repeat  
            USBOut 1, USBOutBuffer, USBBufferSizeTX                                
        Until STATUS.0 = 0

    Dim Mybigbuffer[832] as byte
    Dim Index as byte
    Dim Index2 as word
    Dim PacketCnt as byte

    Index1 = 0
    Index2 = 0

    repeat
    FSR_1 = VarPtr __USBOut_Buffer
    FSR_0 = VarPtr Mybigbuffer + Index2
    GoSub CopyData
    Index2 = Index2 + PacketSize
    gosub USBout
    inc PacketCnt
    Until PacketCnt => noPacketstosend

    CopyData:
    Index = PacketSize
    Repeat
    POSTINC1 = POSTINC0
    Dec Index
    Until Index = 0
    Return
    Tim

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,676
    Thumbs Up
    Received: 47
    Given: 95
    Total Downloaded
    1.32 GB

    0 Not allowed!

    Default Re: More USB issues...

    Where is the Edit button???????????
    Tim

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    wastrix
    Guest wastrix's Avatar

    0 Not allowed!

    Default Re: More USB issues...

    Hi Tim, thanks for the reply.

    The data being sent is done by the hardware so you have plenty of time to fill the buffer for the next batch,
    Hmmm... OK, this makes sense; I won't worry then.

    My original issue was not a significant one, I just thought it was inefficient (and indeed it was not running fast enough) to be copying between three buffers, but it now seems that it doesn't matter anyway. I have found I was able to change the program flow and decrease the polling period (not sure why this affects comms speed?? Maybe because it polls automatically with a USBIn/Out command?), and it now runs fast enough.

    You should also know Proton will not work with buffers over 256bytes after that you do it your self
    Filling the buffer is simple
    Yes, thanks for the code, it was practically identical to what I already had - great minds think alike, eh...

    Also its only the 14k50 etc that needs 64byte packets, the 2550 sends 256 bytes at a time.
    That's interesting... I was not aware of this. I presume that 4x256 bytes would allow the MCU to load the buffer, then do other things while the buffer was sending, and do this much more efficiently than 13x 64 byte buffers.

    I only arrived at the 64 byte figure because in the help file it says:
    Buffer is a Byte array consisting of no more than 8 elements when used with a 14-bit core device.
    The 14-bit low speed USB interface adopted by the PICmicrotm, only allows 8 pieces of
    data to be transmitted in a single operation. However, when using an 18F device, this may be
    any of the compilerís variable types and up to 128 bytes may be transmitted if using CDC and
    64 bytes for HID.
    However, I think the USB commands in the help file are underdocumented. (Sorry Les, I know what a pain in the ass it is to write up all this documentation and keep it up to date, but I think a complex feature of the compiler like USB should be more thoroughly documented).
    And yes, I do have USB Complete 4th Edition, but it is very important to have information on the specific PDS implementation of USB.

    Anyway, it's all good now, thanks, I can get the speed required. Hopefully the last USB whinge from me!

    P.S. I notice that there are WinUSB descriptor + class in the USB folder of the compiler. This does not seem to be officially supported yet (not in the documentation) - I hope it gets properly integrated in the future as this would be great.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,676
    Thumbs Up
    Received: 47
    Given: 95
    Total Downloaded
    1.32 GB

    0 Not allowed!

    Default Re: More USB issues...

    I stand corrected with the buffer Les I got confused with the buffer size's

    The biggest speed increase is to tell the PC that the polling period is requested to be 1ms, you will then have a chance of reaching the max 64kbytes per second. The PC polls the Pic not the other way around. The Pic has to be ready to respond though. "Yes I have data to send" and the process starts. if you fail to do not do a USB action in the Pic the state machine goes idle, and will not respond to the PC. Think of it as insurance for the PC. No response then it will drop its connection.
    Tim

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    wastrix
    Guest wastrix's Avatar

    0 Not allowed!

    Default Re: More USB issues...

    Quote Originally Posted by Tim View Post
    The biggest speed increase is to tell the PC that the polling period is requested to be 1ms, you will then have a chance of reaching the max 64kbytes per second. The PC polls the Pic not the other way around.
    OK, I understand now, thanks for the help.

    At current I have part of it working with a poll speed of 3ms. I am getting a speed of about 25-30kBps, which is quite adequate. That is only transferring data INwards. I could decrease the poll speed further, but it will just increase load on the PIC which has a lot of other work to do.

    re buffer sizes, I don't suppose it is possible to increase the size of the USBOut buffer in the USB RAM buffer descriptor table to a value larger than the value specified in the endpoint descriptor, meaning that the hardware automatically sends more than one packet?

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    crankshaft
    Guest crankshaft's Avatar

    0 Not allowed!

    Default Re: More USB issues...

    Hi William;

    Did you ever resolve the sending of lrge data packets as I am struggling with this. I have used USB sucessfully in several projects but all of them sent a data packet les than 64 bytes.

    Now I need to send up to 254 bytes and I have tried several methods, none of which seem to work, here's my latest attempt:

    Code:
    tx_usb:            
        If strX254 <> 0 Then 
            varW1 = Len(strX254)
            Print At 7,2,Dec3 varW1
            For varB1 = 1 To varW1 Step 64
                Repeat
                    USBPoll          
                Until TRNIF = 0                
                
                tx_buff = Mid$(strX254,varB1,64)
                Repeat  
                    USBOut 1, tx_buff,64                               
                Until STATUS.0 = 0
            Next
        EndIf    
        Clear tx_buff
        Clear strX254
        Return
    Also, I'm still unsure as to whether the 18F2550 has a 64 Byte out buffer or a 256 byte out buffer, which was a point you also raised - did you solve this and if so do any files need to be edited ??

    Cheers

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    wastrix
    Guest wastrix's Avatar

    0 Not allowed!

    Default Re: More USB issues...

    Actually, I used C in the end because HID was not adequate and I used WinUSB.

    Basically you just have to define a big buffer and then copy 64B pieces into another buffer before sending the smaller buffer.

    Funnily enough someone asked me exactly the same question a few weeks ago (though his situation was a little more complex as he needed a 800 byte buffer which could not fit in user RAM, and I quickly wrote some code. He has told me that it works well, but I haven't tested it. Here is my answer:
    Code:
    Dim temp1 As Byte
    Dim Buffer[800] As Byte At 1248
    
    Dim FSR0 As FSR0L.Word
    
    temp1 = 0
    
    Repeat
        FSR0 = 1248 + (temp1 * 64)
        Asm-
        Lfsr 1, __USBOut_Buffer
    Loop
        Movlw 64
        Movff POSTINC0, POSTINC1
        Decfsz WREG
        Bra Loop
        Endasm-
        Repeat
            USBOut 1, __USBOut_Buffer, 64
        Until STATUS.0 = 0
        Inc temp1
    Until temp1 = 13
    Note also that this code has a fault, even though it should work OK - 13 * 64 + 1248 = 2080, which is past the end of RAM (2048). You could add some code to fix this, but it should work anyway. You might find that the last 32 bytes just get written with either 0s or random data.

    THe reason I chose 1248 is that it is the highest address where you can fit a 800 byte buffer.
    I dropped to assembler for the copy part of the routine, because PDS cannot handle arrays larger than 256, but you could probably do it with equal efficiency in BASIC if you are only using a 254 byte array.

    Another thing to think about is that you need to make sure that the MCU has control over the buffer (not the USB SIE), otherwise you cannot write. To ensure that, you can place the code below (from PDS manual) before the above routine:
    Code:
    Repeat : Until UIR.3 = 1
    In re your question of buffer sizes, the max USB packet size for interrupt or bulk endpoints at full speed is always 64 bytes. The PIC can have a buffer of (I think) up to 1Kbyte in theory, but for simplicity PDS keeps it the same size as the packet, and it is fixed at 64 (or less). This could be changed by modifying the descriptors and the class drivers, but it would probably be a big job.

    Les wrote some new USB routines a while back which are much more configurable than the current ones and also have better support of new devices, but these are not included with the compiler, nor are they officially supported at present.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #9
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,676
    Thumbs Up
    Received: 47
    Given: 95
    Total Downloaded
    1.32 GB

    0 Not allowed!

    Default Re: More USB issues...

    I send data up to 16 MByte in size in 64 byte chunks via HID. It works well, although it can take a while (8mins!)

    However I have to include CRC's etc as windows has the habit of losing packets..
    Tim

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #10
    Junior Member ElektroArt's Avatar
    Join Date
    Mar 2010
    Posts
    59
    Thumbs Up
    Received: 2
    Given: 2
    Total Downloaded
    14.89 GB

    0 Not allowed!

    Default Re: More USB issues...

    To preparing and storing data, pic side , extra RAM buffer connected?

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #11
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,676
    Thumbs Up
    Received: 47
    Given: 95
    Total Downloaded
    1.32 GB

    0 Not allowed!

    Default Re: More USB issues...

    I have the data stored in an external SPI Flash Memory chip (128 Megabit)
    I can read the data from the device do the CRC (CRC-CCITT-16) put it in th epic USB buffer and then send it. The bottle neck is the PC side. It runs at about 58-60 Kbytes per second.

    The thing is though that it works every time, no drivers needed, it just works....
    Tim

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. UART and USB Issues with PIC18F97J94
      By mitch in forum Absolute Beginners Section
      Replies: 11
      Last Post: 27th August 2019, 10:48
    2. [SOLVED !] Known Issues
      By IanHemmingsen in forum Website / Forum Issues
      Replies: 5
      Last Post: 15th January 2013, 06:24
    3. [SOLVED !] delay issues
      By joantabb in forum Proton Plus Compiler v3
      Replies: 26
      Last Post: 8th March 2005, 00:46

    Members who have read this thread : 9

    Actions :  (Set Date)

    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