golf Guest
|
throughput in usb connections |
Posted: Tue Jul 22, 2008 4:36 am |
|
|
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);
}
}
|
|
|