USBout problem


Closed Thread
Results 1 to 5 of 5

Thread: USBout problem

  1. #1
    Join Date
    May 2012
    Posts
    13

    Default USBout problem

    Hi,

    I'm using the following code to send data over USB which I learned from this thread: http://www.picbasic.co.uk/forum/showthread.php?t=5806

    Code:
    DEFINE    OSC 48
    
    
    Buffer    VAR BYTE[1]
    Cnt       VAR BYTE
    counter   VAR WORD
    
    
    ADCON1 = 15               ' Set all I/Os to Digital      
    CMCON = 7                 ' Disable Comparators
    Cnt = 1
    
    
    USBInit                   ' Initialize USART
    
    
    ' Main Program Loop
    Loop:
        
        USBService        ' Must service USB regularly
        Buffer(0)=50
        USBOut 3, Buffer, Cnt, loop
        Buffer(0)=60
        USBOut 3, Buffer, Cnt, loop
        goto loop
    
    end
    
    I check the received data on HyperTerminal but it only shows getting "2"s which means that Buffer[0] is always 50 and never takes the value 60. Could you help me with this problem please, what's the problem in my code? It's supposed to send 50 and 60 in an alternating pattern which correspond to "2" and "<" according to ASCII table.

    Regards

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


    Did you find this post helpful? Yes | No

    Default Re: USBout problem

    USB "Frames" occur at 1ms intervals.
    When you send 50, it will have to wait until the next Frame to send 60.

    During that time any USBOUT statements will fail, and jump to the specified Label.
    Since you only have 1 Label, it always goes back to sending 50. 60 never gets sent.

    Using a label for each transmission will help.
    Code:
    ' Main Program Loop
    Loop1:
        USBService        ' Must service USB regularly
        Buffer(0)=50
        USBOut 3, Buffer, Cnt, loop1
    
    Loop2:
        USBService
        Buffer(0)=60
        USBOut 3, Buffer, Cnt, loop2
    goto loop1
    DT

  3. #3
    Join Date
    May 2012
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: USBout problem

    Thanks DT, I'll try this code. BTW, does 1ms time interval mean that we can only send 1000 Bytes of data in a second via USB?

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


    Did you find this post helpful? Yes | No

    Default Re: USBout problem

    Each Frame can transfer 64 bytes in Full Speed mode.
    So theoretically the transfer rate is 64000 bytes/sec.

    However, that rate is not acheivable without using ping-pong buffers, which PBP does not support.
    Without ping-pongs, I've measured approximately 56kBytes/sec.

    Other devices on the USB bus can reduce that as they use frames for their traffic too.
    DT

  5. #5
    Join Date
    May 2012
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: USBout problem

    Thanks a lot for the useful information.

Members who have read this thread : 1

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

Posting Permissions

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