View previous topic :: View next topic |
Author |
Message |
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
USB Data transfer |
Posted: Sat Aug 06, 2011 5:08 am |
|
|
Hello!
I need to transfer streaming audio data from a pic18f2455 to the pc via usb, about 6Mpbs (bits per sec.)
Which is the fastest way to do this? Does anyone know the speed of the CDC driver?
Thanks! _________________ George. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Aug 06, 2011 6:43 am |
|
|
Not enough information provided but obtaining 6Mbps is easy enough to do.
Cutting out none essential code from the driver will speed things up, running the PIC at full rated speed,using very tight ISRs,integer ring buffers,etc.
I suspect the acutal data collection will be the problem not the USB transfer in getting the speed(throughput) you want.
As for the speed of the driver,just program a PIC with a simple loop to tranfer 'The quick brown fox' as data say 1,000 times and set markers for start and finish(on the PC side). That will give you an idea as to overall performance.
Be aware that the PC side program will affect throughput, so again, trim code to a minimum,get rid of ALL unneeded background tasks.Your 'PIC USB reading program' should be the ONLY task on the PC. |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Sat Aug 06, 2011 7:04 am |
|
|
Data collection is already solved and working.
I also have the PIC sending data to the PC but each byte takes 9.2uS.
This is how I measure it:
Code: |
while(1){
usb_task();
output_high(PIN_A0);
usb_cdc_putc(0xff);
output_low(PIN_A0);
}
|
The oscilloscope is connected on pin A0 so I can measure the time for each byte transfer. 9.2uS/ byte is very slow.
I do not know how to first fill the TX buffer of the PIC and then flush it.
The size I think is 64 bytes. Right?
From the PC side I have a VB program that receives the data in byte arrays and saves directly to a file in binary mode. _________________ George. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19550
|
|
Posted: Sat Aug 06, 2011 9:33 am |
|
|
CDC, normally uses a single 64byte buffer, and is 'flat out' theoretically at about 1.2MB/sec. You can get to about 800K/sec, using the standard drivers, but you need to be doing block transfers, to the buffer, not single byte as you are showing.
USB bulk transfers, are better designed for real speed. Look at ex_usb_scope.c, for an example of using these, sending 512bytes in nine packets at a time.
Best Wishes |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Sat Aug 06, 2011 9:40 am |
|
|
The problem is that I have to stick with CDC because it is easy to use from the PC side as a virtual com port.
When you say 800K/sec. you mean 800KBytes/sec? this is 6.4Mbps. Right?
And how can I do block transfer in CDC? _________________ George. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Aug 06, 2011 10:29 am |
|
|
Unless you can make better PC side software, I'd go with good old RS-232. Right now I have several systems up and running at 920KBytes/sec without any problems. |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Sat Aug 06, 2011 10:45 am |
|
|
The maximum rate allowed by visual basic mscomm32 is 256000.
How can you achieve 920KBytes/sec?? This is 7.36Mbps. _________________ George. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Aug 06, 2011 11:00 am |
|
|
I do not use VisualBasic !! |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Sat Aug 06, 2011 1:33 pm |
|
|
Any ideas for visual basic??? Anyone? _________________ George. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19550
|
|
Posted: Sat Aug 06, 2011 2:50 pm |
|
|
Use a third party MSCOMM replacement. You can double the speed straight away doing this. Look at usb_cdc_putc_fast. Be aware of it's limitations, but in terms of actually writing data to the buffers more quickly, it is the simplest way to go if you are stuck with VB and a cdc device.
Best Wishes |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Sat Aug 06, 2011 3:48 pm |
|
|
The point is that when I use the vb mscomm with CDC, I do not have to set baud rate. The software handles all the speed stuff.
I think it is the PIC side that limits my speed.
I do not know how to first fill the TX buffer and then to flush it, so I use
usb_cdc_putc(); which sends one byte at the time.
I just want 6Mbps speed from PIC to PC.
Is it so hard to implement with a PIC? _________________ George. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Aug 06, 2011 5:31 pm |
|
|
It's not the PIC side(hardware) that is limiting you ! Rather the form of communications and the protocols. As I previously stated I can easily get 920KBaud using simple RS232. Higher if I reduce the overhead of the protocol/error checking, etc. I did get over 2MBaud PIC to PIC one day while waiting for the 2nd pot of coffee to be made.
You can get better throughput using alternative drivers on the PC side using VB, even faster response using another language (Delphi ((Pascal)) for instance). Keep in mind that since USB is non interrupt driven it has a LOT of 'overhead' that you must take into consideration, going 'old school' RS-232 can really speed things up.
However if you're 'stuck' using USB, search the web for hints on how to achieve higher throughput. Perhaps reading about USB 3.0 will help 'trim the fat' off your code ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19550
|
|
Posted: Sun Aug 07, 2011 2:36 am |
|
|
Are you sure you have set the USB up in fast mode?.
Have to ask, since your performance seems worse than it should be....
I wrote a simple 'test' code into a 18F4550, setup to send a 64byte string (using usb_puts), and loop similarly to your code, and setup a VB6 app, with 1KB buffer enabled on the MSCOMM, and just read the contents and count the buffers filled in a second. It averaged just over 750KB/sec, quite comfortably.
Then tried again with Sax CommStudio, and hit nearly 2MB/sec.
Not calling usb_task for every byte, helps a bit.
Best Wishes |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Sun Aug 07, 2011 3:35 am |
|
|
Thanks for the suppport!
How can I test if I am using the USB in fast mode? _________________ George. |
|
|
|