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 support@ccsinfo.com

throughput in usb connections

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







throughput in usb connections
PostPosted: Tue Jul 22, 2008 4:36 am     Reply with quote

Hi
I'm making a very simple oscilloscope. It periodically sends adc values though a usb port. once in the computer, i read it using the libusb linux library (also exists in windows).
the behaviour is the expected; only there is a thing dancing in my head: this code sends every 1 ms a read (theoretically); but in the computer i read it 3 times slower (as a result i read 3000 packets in ~9 seconds).
I tried different programming languages, and different libraries, unable to find the bug - could be a firmware problem. I'm asking for some help
Thanks

Code:

#include <18F2550.h>
#fuses HSPLL NOWDT NOPROTECT NOLVP NODEBUG USBDIV PLL5 CPUDIV1 VREGEN NOMCLR
#id 0x1234
#device adc=10

#define USB_HID_DEVICE FALSE
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT
#define USB_EP1_TX_SIZE 8
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT
#define USB_EP1_RX_SIZE 8

#use delay(clock=48MHz)
#include <pic18_usb.h>
#include "usb_custom.h" // descriptor only
#include <usb.c>

int1 adc = FALSE;
int8 data[2];

void main() {
   setup_oscillator(OSC_NORMAL);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(3);
   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_1);
   set_timer0(-12000);
   clear_interrupt(INT_TIMER0);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);

   usb_init();
   while (TRUE) {
      if(usb_kbhit(1)) {
         usb_get_packet(1, data, 8);
         adc = (data[0] & 0x04) != 0;
      }
   }
}

#int_timer0
void timer0() {
   int16 adc_data;
   set_timer0(-12000);
   adc_data = read_adc();
   if (adc) {
      data[0] = (adc_data & 255);
      data[1] = (adc_data >> 8);
      usb_put_packet(1, data, 2, USB_DTS_TOGGLE);
   }
}
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