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

How to transfer data from ADC about 100 KB/s via usb port

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



Joined: 16 May 2014
Posts: 11

View user's profile Send private message

How to transfer data from ADC about 100 KB/s via usb port
PostPosted: Sun Sep 07, 2014 4:04 am     Reply with quote

Hi everyone,

I use DSPIC33EP256MU806 for sending ADC data to computer via USB port. It can read ADC data up to 500Ksps(kilo sample per second).
I try to send ADC data via USB port by CDC class because it is easy to manage data using Siow CCS application.However,I do not know how to measure rate of data transferring by sending via USB CDC class. I think that USB need polling every 1 ms and the transfer rate is 1KB/ms(100KB/s).

1)How to measure rate of transfer using CDC class ?

2)Another question is how long of data 1KB complete sending after USB polling 1ms.

3)Can I use CDC class to transfer data at 100KB/s or I should change the device to HID class.

Note that I try to send printf(usb_cdc_putc, "\n\rAkiom");//my name,it use 30 us for only this function and ADC need 250 ns for RC Oscillator
Anyone has and idea about transfer data from ADC at 100 KB/s.

Thank you very much

Akiom

Code:

#include <33EP256MU806.h>
#device ADC=12 //12 bits read_adc() return

#use delay(crystal=8Mhz, clock=140Mhz, AUX:clock=48Mhz,LOCK)
#include <usb_cdc.h>

void main()
{
  usb_cdc_init();
  usb_init();
  int16 ADC_Value;
  setup_adc_ports(sAN0 | sAN1, VSS_VDD);
  setup_adc(ADC_CLOCK_INTERNAL | ADC_TAD_MUL_0);
  set_adc_channel(0);

   while(TRUE)
   {
   usb_task(); 
   while (usb_enumerated())//Returns TRUE if the device has been enumerated(specified)by the PC.
 
      {
     
     ADC_Value=read_adc();
     printf(usb_cdc_putc, "\n\r%ld",ADC_Value);
     
      }
   }

}


Last edited by AKIOM on Sun Sep 07, 2014 6:19 am; edited 3 times in total
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Sep 07, 2014 5:06 am     Reply with quote

I don't use that PIC but what I'd do is create a large array of data in the PIC to transmit to the PC. In the PC I'd create program to tell the PIC to transmit that data. When the PC receives the first data it starts a timer, when it gets the last data, it stops the timer and displays the difference.

Asking us 'how long will it take' is difficult! WE don't have your PC, know what tasks it's always running, which OS, what 'terminal program' you're using, which USB version, etc. There are dozens or more factors that can and will affect 'data transfer via USB'. I do know that running a Delphi program in a barebones XP machine is a LOT faster than a WIN7 'daily user' type PC.

hth
jay
AKIOM



Joined: 16 May 2014
Posts: 11

View user's profile Send private message

PostPosted: Sun Sep 07, 2014 7:18 am     Reply with quote

Thank you very much temtronic,

I read your answer it is useful for me to test sending much data via USB and using timer for detection. However, I do not sure all data must transfer every 1ms or not.
Please tell me how much data that I should send in 1 ms to measure speed of transfer.All in all, If I can send data 1KB/s to computer ,it is very fine for me.
Now, I have never used delphi. I appreciate very much if you advise me about easy program to measure it. I used siow from ccs to keep data and manage data with excel.

Thank you again
Akiom
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Sep 07, 2014 8:00 am     Reply with quote

As I said, you'll have to do the work. My PC & software isn't what you will be using, so while I can get 10s of thousands of data in 1 ms you may not.
Again this is a combination of hardware (PC config) as well as software( terminal program).
At the very least, get SIOW to 'transfer' a file of say 1000 data to PIC, have PIC 'loopback' the data to PC into another file. That simple test should give you a 'ballpark' timing of data transfer. Use a stopwatch or have the PC do the timing.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Sep 07, 2014 8:53 am     Reply with quote

The key thing to understand is that there isn't an absolute speed. There is a limit (about 1.2MB/sec for full-speed USB), but the actual performance of a USB bus will depend on your PC, and the other traffic going on at the time. Remember that there are lots of other things using the USB controller, and these share the 'bus time'. The polling interval, effectively only specifies the latency (how long it'll be before the PC next polls the device), and even this slows when the bus is busy. I've managed over 800KB/sec from a hardware connected memory, to USB CDC, on a PIC18, but using Linux as the host. This was limited by how fast the PIC could actually read the data. However the same hardware on Windows slowed to under 500KB/sec. This then improved with the next Windows chipset driver. Put a hard disk on another connector on the same PC using the same USB controller, and the speed approximately halved.

It is a bit like 'how fast is a motorway'. It depends as much on congestion, as the speed of your car...
AKIOM



Joined: 16 May 2014
Posts: 11

View user's profile Send private message

PostPosted: Sun Sep 07, 2014 10:56 am     Reply with quote

Dear Ttelmah,

Thank you very much for your answer. I think I have to test rate of transfer by capturing the time as "temtronic" advise me. I have few questions to ask you about transferring data via USB.

I try to understand sending data to USB by reading website that describes about USB interface eg. "http://www.usbmadesimple.co.uk" and read "usb_desc_cdc.h" but I have some questions about it.

1) Maximum one packet of usb is 64KB and It can send 19 packets for bulk mode(1.2MB/s). If I send " printf(usb_cdc_putc, "\n\r%ld",ADC_Value)" , it use one packet or not. If this use one packet,I can maximum send only 19 ADC value/ms.

2) I search the same topic that use USB sending ADC data via USB
usb_cdc_putc_fast(make8(adc_val,0));
usb_cdc_putc_fast(make8(adc_val,1)); //send LSB, then MSB
it is very good idea to send data via usb. If I correctly understand, it can send 32 times per packet and ideal maximum packets are 19.

3) I found that the "usb_desc_cdc.h" determine USB packet size "USB_CDC_COMM_IN_SIZE 11". it mean that I can send only 11 packets or not.

4) Ttelmah, Do you use original usb_desc_cdc.h for transferring data 800KB/sec? If I correctly understand , you repeat function "usb_cdc_putc_fast" 800K times/s. Is it right?

Note that ,First time I use printf function because siow.exe from ccs need Ascii data. I think I should study VB or delphi to interface between PC and PIC. If it do not bother you, please advise me what PC program(VC++,Delphi or VB etc.) that I should start to connect to PIC.

All in all, I prefer sending data about 100 KB/s via USB port that less than 500KB/s.


Sincerely Yours
Akiom
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Sep 07, 2014 11:25 am     Reply with quote

just for reference...

OK, I don't use that PIC rather the 18F46K22 with external TTL<>USB module, but my demo unit happily transmits data at 115k200 all day long without any loss or corruption. This goes to 10 year old PC running 'RealTerm' in 'datalogging' mode.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Sep 07, 2014 11:45 am     Reply with quote

No, I filled the whole buffer from the external memory, then updated the pointer to say that it was full.
With the PIC18, you haven't got time to do multiple putc's for this sort of speed.
AKIOM



Joined: 16 May 2014
Posts: 11

View user's profile Send private message

PostPosted: Sun Sep 07, 2014 11:45 pm     Reply with quote

Thank you both Ttelmah and temtronic.

Ttelmah, If it does not use much time for you, please share an idea how to fill the buffer and send it to computer without doing multiple putc.

Temtronic, Your idea is good. Sometime, I may use your idea if direct USB interface is not suitable for me.

Thank you again for your kindness.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Mon Sep 08, 2014 2:49 am     Reply with quote

I can't post this. Part of a commercial product.
I read 'how' the buffers worked, by looking at the code in the CDC handlers.

Had my own buffer. Just fractionally smaller than the usb_cdc_put_buffer (had increased the size of this).
Did a high speed read from the external memory to my buffer, polled to see if the USB tx buffer was empty (there is a test directly for this), and when it was, used a memcpy, from my buffer to the usb_cdc buffer, and updated usb_cdc_put_buffer_nextin, to be the size of my buffer, to say how much data was waiting.
Then looped back, and performed my next read _while the USB hardware was handling sending the buffer_.
It is the fact that I'm doing my reads, while the USB hardware is sending, that was critical.
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