Hi,
I'm trying to read data from I/O port C on the FX2 development board into my computer and then immediately write the received data back onto port E using the CyAPI library. I'd like to be able to run this cycle of data transfer (IOC->BulkInEndPt->PC console application->BulkOutEndPt->IOE) at a few kHz, but so far I've had no luck. I'm using two 512 byte 4x buffered bulk endpoints. My TD_Poll() function in my firmware looks like this:
void TD_Poll(void) // Called repeatedly while the device is idle
{ xdata unsigned char test = IOC & 0x01;
//Reads status of pins on i/o port C and readys the data to be transferred to the computer
if(!(EP2468STAT & bmEP6FULL)) { FIFORESET = 0x80; SYNCDELAY; FIFORESET = 0x06; SYNCDELAY; EP6FIFOBUF[0] = test; SYNCDELAY; EP6BCH = 0x02; //BCL and BCH regard endpoint buffer size SYNCDELAY; EP6BCL = 0x00; SYNCDELAY; EP6BCL = 0x00; SYNCDELAY; EP6BCL = 0x00; SYNCDELAY; EP6BCL = 0x00; SYNCDELAY; OUTPKTEND = 0x82; SYNCDELAY; FIFORESET = 0x00; SYNCDELAY; }
//Reads data sent from the computer and writes it into i/o port E. if(!(EP2468STAT & bmEP2EMPTY)) { xdata unsigned char *src = EP2FIFOBUF; xdata unsigned char value = *src;
IOE = value; FIFORESET = 0x80; SYNCDELAY; FIFORESET = 0x02; SYNCDELAY; FIFORESET = 0x00; SYNCDELAY; EP2BCL = 0x80; SYNCDELAY; EP2BCL = 0x80; SYNCDELAY; EP2BCL = 0x80; SYNCDELAY; EP2BCL = 0x80; SYNCDELAY; } }
And the following is the relevant code in my console application:
if(USBDevice->BulkOutEndPt && USBDevice->BulkInEndPt) { cout BulkInEndPt->XferData(buffer, length); USBDevice->BulkOutEndPt->XferData(buffer, length); } }
As you can see, whatever data is on port C should be immediately looped through the endpoints and computer to port E. However, I get about a 500 microsecond delay delay between the rising edge of a generated waveform on port C and the corresponding edge on port E. Can you make any suggestions for speeding this up? I'd like to get the delay as small as possible, so that port E can effectively follow port C at a higher frequency like 8 kHz. Let me know if you need any clarification.
Thanks so much, Zach