I am trying to send 1Ms/s of data from 2 ADCs simultaneously to the Ethernet using TCP IPv4 but I am getting very slow data throughputs, something like 1 sample per second for both channels. I have set my ADC's as such to try and sample at 1 megasamples/ s and sending the data out accordingly.
unsigned int adcValues[4];
Void tcpWorker(UArg arg0, UArg arg1) {
int clientfd = (int)arg0;
int bytesRcvd;
int bytesSent;
volatile uint32_t adcVal0, adcVal1;
char recvBuffer[TCPPACKETSIZE];
char sendBuffer[TCPPACKETSIZE];
memset(recvBuffer, 0, 1024);
memset(sendBuffer, 0, 1024);
System_printf("tcpWorker: start clientfd = 0x%x\n", clientfd);
for(;;) {
//while ((bytesRcvd = recv(clientfd, recvBuffer, TCPPACKETSIZE, 0)) > 0) {
if ((bytesRcvd = recv(clientfd, recvBuffer, TCPPACKETSIZE, MSG_DONTWAIT)) > 0) {
tcpReceiverHandler(recvBuffer);
System_printf("%s\n", recvBuffer);
} else {
// No data received
}
// Flush buffer everytime after printing
System_flush();
// Send ADC data
ReadADC();
adcVal0 = adcValues[0];
adcVal1 = adcValues[1];
sprintf(sendBuffer, "ADC0: %d ADC1: %d", adcVal0, adcVal1);
System_printf("%s\n", sendBuffer);
System_flush();
bytesSent = send(clientfd, sendBuffer, strlen(sendBuffer) + 1, 0);
if (bytesSent < 0) {
System_printf("Error: send failed.\n");
break;
}
}
}
void ConfigureADC(void) {
//SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOE);
//SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 );
// Clocked to 120MHz / 6 to get 20MHz ADC clock and takes all samples
// an ADC clock of 16MHz, generates 1MSps
//ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 7);
//SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
// SYSCTL_CFG_VCO_480), 120000000);
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE,1,0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE,1,1, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);
//ADCSequenceEnable(ADC0_BASE, 0);
ADCSequenceEnable(ADC0_BASE, 1);
}
void ReadADC(void) {
ADCIntClear(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);
GPIOPinWrite(GPIO_PORTP_BASE, GPIO_PIN_4, !GPIO_PIN_4);
// Wait until the sample sequence has completed.
while(!ADCIntStatus(ADC0_BASE, 1, false)) { }
// Read the value from the ADC.
(ADCSequenceDataGet(ADC0_BASE, 1, adcValues));
GPIOPinWrite(GPIO_PORTP_BASE, GPIO_PIN_4, GPIO_PIN_4);
}