What is the fastest way to sample data periodically and do the DSP calculations? What I am doing is this, I am obtaining data from an external ADC. This data is used in a control loop. Here are some of my ideas
1) Using GP Timer and callback - every sampling interval, timer callback is executed - read adc in the callback and process data there? The problem here is that, shouldn't I keep callback as short as possible? I also noticed that I am not able to output serial data using UART framework API function that's called inside the callback. It would be nice if I could do this.
2) Using GP Timer, callback, semaphore and thread - every sampling interval, timer callback is executed. Using semaphore, transfer to the thread. I read ADC and do the process in the thread instead of doing it in the callback. The problem is I think using the semaphore and transferring from callback to thread will slower things down. Also, I'm not sure if the time it takes to transfer from callback to thread is a fixed amount of time?
3)Do away with callback and semaphores - The idea here is just use the thread loop to read adc and process data. But how do I set the timing for this. Say if I want to sample every 100us? 1ms? And how do I ensure that this timing is not affected by other threads that are running?
In reply to WarrenM:
In reply to AJ:
Hi AJ, Most of external ADCs have auto conversion command and convert completed interrupt. In that case the timer is not needed. Assign the converted interrupt as one of free IRQs and trigger communication with DMA or DTC in the IRQ callback function. In transfer completed callback you should prepare next communication if it is necessary.