V-USB speed

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
spiky
Posts: 18
Joined: Mon Jul 27, 2009 4:27 pm

V-USB speed

Post by spiky » Mon Jul 27, 2009 4:56 pm

Hi,

I've been using V-USB for two weeks now. Its fantastic.Everything works so easily. I am very grateful to the author.

I have been searching through this forum to see what speed(data transfer speed) others got with V-USB. Here are two forum topics where the speed of V-USB is discussed.

viewtopic.php?t=19&start=15
viewtopic.php?f=8&t=2036&hilit=kBps

USB asp says 7kB/s or something like that
AVR CDC gives 57600kbps which is just less than 8 kBps.


It looked like 8 kB/s was the maximum achieved. I am doing an oscilloscope and for my design , 8 kBps is sufficient. Out of curiosity , I measured the actual speed with a performance timer on the host ( PC ) .

I was completely startled by the results. I got a whopping 23 kB /s .I am using the 20090415 version.
Here's a tabulation of the results. I've enabled long transfers ( >254 ) bytes.

Total Number of Bytes transferred from device to HOST speed
900 - 23.5 kB/s
700 - 24 kB/s
500 - 24 kB/s
300 - 24 kB/s
200 - 22 kB/s
100 - 18.31 kB/s
50 - 17 kB/s

I used the control endpoint.
The speeds were not the same always but they were consistent. they were always within +/- 0.5 kB/s.
I am doing a custom class device. On the host side , I use Windows XP professional SP3 . I am programming with .NET . Used windows forms with SharpUSBLib wrapper.

Using usbFunctionRead() , I transferred back 2000 bytes of data and i got 24kB/s consistently.
And for the record , i'm using Atmega16 at 12 MHz.

This is the performance timer i used.
http://www.codeproject.com/KB/cs/highpe ... cshar.aspx

Its supposed to be a microsecond accurate timer.

I am not entirely sure if i should have posted this info here. My humble apologies if i did the wrong thing in posting this information here.
I just wanted this information made available for other users who might find it useful.

Me and my friend have also found a work around for disabling interrupts for longer than a few cycles without loosing the USB connection. For the oscilloscope project we are doing , we are disabling interrupts for as long as 50 mS(this is needed as we sample data at 4 MSPS and cant afford being interrupted by USB ) . The USB link is fine( the device doesnt become unrecognized ). But there is a speed penalty. I am not sure where I should post info on that.

Cheers to V-USB.

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: V-USB speed

Post by maxi » Wed Jul 29, 2009 4:26 pm

That is very impressive indeed! I too am working on a simple oscilloscope project, however I am not getting anything like that kind of through-put. :(
I took the hid-data example as the starting point for my design and currently getting 5-7kbs at best. Pretty much inline with what others are reporting.

I would be very interested to see some of your code if you feel like sharing, just a point in the right direction would be great.
In the meantime i'll take a look at the CDC project and see if I can get my head around how that works.

Thanks.

spiky
Posts: 18
Joined: Mon Jul 27, 2009 4:27 pm

Re: V-USB speed

Post by spiky » Sat Aug 01, 2009 7:05 am

My oscilloscope project is nearly complete. I have solder to an SMD IC to complete it. As soon as i've done that , i will put both the host and device side code on the net.

As far as the device side goes , i am using using V-USB to make a custom class device. Here's an extract from wikidot

Code: Select all

usbMsgLen_t usbFunctionSetup(uchar setupData[8])
{
    usbRequest_t *rq = (void *)setupData;   // cast to structured data for parsing
    switch(rq->bRequest){
    case VENDOR_RQ_READ_BUFFER:
        usbMsgLen_t len = 64;                     // we return up to 64 bytes
        if(len > rq->wLength.word)          // if the host requests less than we have
            len = rq->wLength.word;         // return only the amount requested
        usbMsgPtr = buffer;                 // tell driver where the buffer starts
        return len;                         // tell driver how many bytes to send
    }
    return 0;                               // ignore all unknown requests
}


This is precisely what i am doing on the device side. I am transferring back 900 bytes. i.e.. len = 900 in my case.
Perhaps HID is causing the bottleneck for u. I've read that HID implementation on the host side can be a nightmare. I find using LibUSB for C# damn easy to use. So i'm sticking by custom class devices. I've even made a wrapper around the SharpUSBLib library. With this , I dont even have to search for the device. I have only to give the name of the device and my library scans for it.

If u're using .NET , i'll be more than happy to give you my library.

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: V-USB speed

Post by maxi » Sat Aug 01, 2009 11:46 pm

Thanks for the info, I have been able to make some progress by improving my device-side code. Since I added a circular buffer I am now able to monitor a ~1Khz sine-wave consisting of approximatley 20 vectors per full wave. Now by my math that means I must be getting in the region 20ks/s or 20KB/s since I only use 8bit resolution.

This measurement is far from precise as the signal is generated by a simple phase-shift oscillator built on proto-board, however a soundcard based scope gives a reasonably stable trace at just a shade under 1Khz.

Further improvement still needs to be made as the ADC trace I get is showing intermittent distortions. I'm not sure if it's down to limited buffer size, the usb polling or even if its perhaps the host-side rendering (although I doubt that). I'll give the custom class a go since its the only one I've not yet tried, maybe that will help.

Unfortunatley I do not have, nor am I very familiar with C# but thank you very much for your offer. I think the host side is less of a worry for me, much more in my comfort zone there. It's the AVR programming that is proving to be a bit of a challenge. This is my very first attempt at programming any kind of micro-controller after all.

I look forward to seeing your solution once you get it uploaded to the net, please post a link when you do.

Thanks again for your help.

spiky
Posts: 18
Joined: Mon Jul 27, 2009 4:27 pm

Re: V-USB speed

Post by spiky » Sun Aug 02, 2009 9:27 am

You are most welcome.

With regard to the distortion you see , in my opinion , there are 2 causes

1. USB interrupts are disturbing the time critical sampling.
2. ADC is unable to produce accurate samples because supply voltage variation is too much. Try adding decoupling caps to solve this problem. If it doesnt help , you may have to put the AVR in sleep mode while taking samples.

ali_asadzadeh
Posts: 1
Joined: Mon Aug 03, 2009 5:15 pm

Re: V-USB speed

Post by ali_asadzadeh » Mon Aug 03, 2009 5:20 pm

hi
spikey can you please share your C# lib.
thanks in advance for the info.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: V-USB speed

Post by christian » Thu Aug 06, 2009 4:02 pm

Regarding the transfer rate: This is all very fragile. It depends on timing, whether the AVR can supply a result within a certain amount of time. And the time frame depends on the host controllers, hubs and operating system. You may get high rates on one operating system and much less on another.

Regarding the interrupt disable time: If the host does not send any requests while interrupts are disabled, nobody will notice. If there are requests, you get communication errors. And some operating systems even stall the endpoint so that you must re-connect the device. If you rely on such a feature, please test on multiple platforms!

spiky
Posts: 18
Joined: Mon Jul 27, 2009 4:27 pm

Re: V-USB speed

Post by spiky » Sat Aug 08, 2009 10:26 am

@ali_asadzadeh , i've written no documentation. but it should be easy as i'm giving you the source. There's nothing much in my library. It keeps attempting the control transfer for 100 times. You need SHarpUSBLib as well.

http://www.mediafire.com/?sharekey=f59081471384dbb2b94117dade8fc295e04e75f6e8ebb871

@Christian ,
Thanks for replying.

Transfer rate : I did not know that transfer rate depended on the OS. I was under the assumption that most OSes can easily manage max speed for atleast low speed USB devices. Looks like a lot more happens and its not as simple as i had thought. I can live with 8 kB/s though should the speed ever drop down.

I tried transferring a 480 kB file from the PC to an mmc card using V-USB and i obtained 16.5 kB/s average speed. I transferred 512 bytes from the PC to the atmega16 at a time and then transferred 512 bytes to the MMC card. So i think PC -> atmega16 through V-USB was taking place at 24 kB/s. The average speed was lower as part of the time was spent only doing transfers to MMC card.

Interrupts : Thanks for the tip. I think this method should work well with other environments as well. It seems like the same technique albeit for a shorter period of time is used in AVR - CDC project. AVR CDC also relies on the host to reattempt transfers when the device is servicing the UART. AFAIK , AVR CDC works well even in windows vista.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: V-USB speed

Post by christian » Sun Aug 09, 2009 9:08 pm

Regarding AVR-CDC: No, it does not work well. MANY people have problems where the device stops working all the sudden and the endpoint is stalled. This occurs most likely on Windows, other operating systems don't stall the endpoint on the first transmission error.

spiky
Posts: 18
Joined: Mon Jul 27, 2009 4:27 pm

Re: V-USB speed

Post by spiky » Mon Aug 10, 2009 7:17 pm

Sad. It worked so well for me and my friend. Better than a USB - RS232 converter we had bought a few weaks ago.

I suppose time critical tasks which require USB interrupts to be disabled at certain times are not possible on all hosts. I was hoping i could find a way to do that without having to use another AVR.

None the less , my efforts have not been in vain. In the very least , it works in my PC !

Thank you very much for all the information you have provided.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: V-USB speed

Post by christian » Mon Aug 10, 2009 7:23 pm

I don't say it's impossible. Just that you should test on various platforms before you publish something. Control endpoints may be different from the bulk endpoints used in AVR-CDC. And even if it does not work on all platforms, it may be worth publishing. But you should add a note, otherwise you'll get lots of e-mail...

spiky
Posts: 18
Joined: Mon Jul 27, 2009 4:27 pm

Re: V-USB speed

Post by spiky » Thu Aug 13, 2009 4:24 pm

I had never thought of that ! i have only windows XP at home. If i test it in other platforms , i'll drop a note here.
Thanks for all the support.

Guest

Re: V-USB speed

Post by Guest » Sun Aug 30, 2009 2:27 pm

Hi Spiky,

i'm interested in looking at your C# code [libary], but having trouble accessing the mediafile site. Is there any alternative

Thanks,

spiky
Posts: 18
Joined: Mon Jul 27, 2009 4:27 pm

Re: V-USB speed

Post by spiky » Mon Aug 31, 2009 6:54 pm

this isnt my library. The #USBLib library which has been updated is here

http://tommyfive.untied.de/usblib/

my library sits on top of this. If you give the name of the V_USB device , it scans for it and then allows you to send control messages to it.
If you want mine , i can upload it. Specify where you want me to upload it.

metRo_

Re: V-USB speed

Post by metRo_ » Wed Sep 23, 2009 11:33 pm

Hi, i will have to transfers some information from adc to computer to make a graphic. You project will give me a very good start point, thanks. It's easy to use visual basic with it?

Post Reply