CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

USB Data transfer

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

USB Data transfer
PostPosted: Sat Aug 06, 2011 5:08 am     Reply with quote

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: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 6:43 am     Reply with quote

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.

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 7:04 am     Reply with quote

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: 19537

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 9:33 am     Reply with quote

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.

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 9:40 am     Reply with quote

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: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 10:29 am     Reply with quote

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.

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 10:45 am     Reply with quote

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: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 11:00 am     Reply with quote

I do not use VisualBasic !!
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 1:33 pm     Reply with quote

Any ideas for visual basic??? Anyone?
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 2:50 pm     Reply with quote

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.

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 3:48 pm     Reply with quote

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: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 5:31 pm     Reply with quote

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: 19537

View user's profile Send private message

PostPosted: Sun Aug 07, 2011 2:36 am     Reply with quote

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.

View user's profile Send private message

PostPosted: Sun Aug 07, 2011 3:35 am     Reply with quote

Thanks for the suppport!

How can I test if I am using the USB in fast mode?
_________________
George.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group