Tool/software: Code Composer Studio
Hello Dear TI Support team,
I need assistance regarding the problem I have been struggling for a long time. My plan for the future is to activate 3 ADC channels with MUX to measure three signal values. I have started from the adcBufContinuousSampling .example. Based on what I have understood so far, to jump between multiple channels, I need to use ADCBuf_RECURRENCE_MODE_ONE_SHOT (CCS).
To be more precise, I want to just get one sample from signal A, then sample B, then sample C and again repeat this sequence and I want to find out what is the maximum possible sampling frequency that I can achieve.
As a start, I have activated just one ADC channel at the moment and with the help of GPIO toggling, I am trying to find out execution sampling time. I have added my code.
The problem I have at the moment is that for low sampling frequency (100Hz), GPIO toggle periods at the end of each sampling look equal. But once I increase the sampling frequency (10000 Hz), It cannot follow the sampling frequency anymore and I don't understand why such thing happens, Whether it comes from the GPIO timer or ADC? Because based on datasheet, the sampling frequency should be 200Ks/S and it does not make sense to not be able to get sampling frequencies more than 10kHz.
Also, I have a question regarding the best solution to sample several ADC channels. Since I Have not found a good solution for an accurate time interval between each sample, should I use HWI for sampling?
I have added the picture of sampling intervals for two cases (100Hz and 10000Hz).
I would really appreciate if you can help me out.
Best regards,
Mori
/* * ======== adcBufContinuousSampling.c ======== */ #include <stdint.h> #include <stdio.h> /* For sleep() */ #include <unistd.h> /* Driver Header files */ #include <ti/drivers/ADCBuf.h> #include <ti/drivers/UART.h> #include <ti/drivers/GPIO.h> /* Example/Board Header files */ #include "Board.h" #define ADCBUFFERSIZE (1)
uint16_t sampleBufferOne[ADCBUFFERSIZE];
uint16_t sampleBufferTwo[ADCBUFFERSIZE]; /* * This function is called whenever an ADC buffer is full. * The content of the buffer is then converted into human-readable format and * sent to the PC via UART. */ void adcBufCallback(ADCBuf_Handle handle, ADCBuf_Conversion *conversion, void *completedADCBuffer, uint32_t completedChannel) { ADCBuf_convert(handle, conversion, 1); GPIO_toggle(Board_GPIO_LED0); } /* * ======== mainThread ======== */ void *mainThread(void *arg0) { PIN_Handle ledPinHandle; ADCBuf_Handle adcBuf; ADCBuf_Params adcBufParams; ADCBuf_Conversion singleConversion; /* Call driver init functions */ ADCBuf_init(); GPIO_init(); /* Configure the LED pin */ GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); GPIO_setConfig(Board_GPIO_LED1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); /* Turn on user LED */ GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON); GPIO_write(Board_GPIO_LED1, Board_GPIO_LED_ON); /* Set up an ADCBuf peripheral in ADCBuf_RECURRENCE_MODE_CONTINUOUS */ ADCBuf_Params_init(&adcBufParams); adcBufParams.callbackFxn = adcBufCallback; adcBufParams.recurrenceMode = ADCBuf_RECURRENCE_MODE_ONE_SHOT;
adcBufParams.returnMode = ADCBuf_RETURN_MODE_CALLBACK;
adcBufParams.samplingFrequency = 10000; adcBuf = ADCBuf_open(Board_ADCBUF0, &adcBufParams); /* Configure the conversion struct */ singleConversion.arg = NULL; singleConversion.adcChannel = 0; singleConversion.sampleBuffer = sampleBufferOne; singleConversion.sampleBufferTwo = NULL; singleConversion.samplesRequestedCount = ADCBUFFERSIZE; if (adcBuf == NULL){ /* ADCBuf failed to open. */ while(1); } /* Start converting. */ if (ADCBuf_convert(adcBuf, &singleConversion, 1) != ADCBuf_STATUS_SUCCESS) { /* Did not start conversion process correctly. */ while(1); } /* * Go to sleep in the foreground thread forever. The ADC hardware will * perform conversions and invoke the callback function when a buffer is * full. */ while(1) { sleep(1000); } }