Fast PICUSB CDC example
Some people from Microchip USB forum complained about low transfer speed of new 18F4550/2550/...
devices. Here is an example how to achieve speed of 128kB/s with Microchip CDC firmware (PIC18F4550 firmware
+ Borland Builder 6 application).
.zip version (119kB)
- transmit data to PC only if local buffer, multiple of 64 bytes is filled; using 128B buffer gives 128B*1000/s speed,
- use separate thread in PC application running at high priority to call ReadFile,
- if data processing on the PC side could be time consuming (e.g. drawing or heavy logging) use queue to pass data from communication to worker thread; that way ReadFile could be called almost immediately one after another, and data loss risk is minimized,
- request large amounts of data with ReadFile in PC program (in this example I use ReadFile(hComm, &(buffer[index]), 5000, &dwBytesRead, NULL)).
None of my serial terminal emulators was able to receive data from PIC at this speed, probably because they are trying to update display after every received portion of data (that may be 1000 times per second).
There are reports of transfer speeds as fast as 800 kB/s. Keep in mind that 8-bit PIC microcontrollers are not able to use large transfer speed (even 128 kB/s) in practical applications - there would be just no time to fill the buffer with any usefull data. I think that 64 kB/s with HID class should be enough most of the times and HID is very convenient as it doesn't require installing driver under Windows.
Microchip example code collection is pretty impressive - Microchip Application Libraries, USB framework contains over 30 projects including CDC, HID, MSD, custom classes and composite devices.
Some of usefull I hope code I used with PIC18 micros: library for 25AA640 EEPROM memory CRC8 calculation (poly: x^8 + x^2 + x^1 + x^0, bytewise) simple FIFO used to transfer data over USB - just for convenience
See also: simplified generic HID demo code with Code::Blocks/MinGW PC application at miniscope page.