how fast can a task response to a Que on PIC32?

shalongbasi wrote on Monday, May 04, 2015:

I am totally new to Freertos and now writing codes on PIC32MX795F512 running on 80MHz.
In my code, A timer triggers an interrupt every 10us and timer ISR writes a dummy data to SPI to read an ADC chip. SPI Rx interrupt is then triggered after data ready and write the ADC data to a Queue. Another task will receive the data from the Queue.

With the help of the oscilloscope, I found that SPI writing is finished in 1.6us, and Que writing is started after 2us after SPI writing finish. Que writing takes about 1.8us.
All these added together costs about 5.6us. I having another signal toggling to monitor the begin and end of queue reading, but it is not a stable waveform, looks like switching to Queue Receiving task and reading the queque cannot be finished in the rest 4.4us.

Anyone have the idea about how long normally tasking switching takes under 80MHz PIC32? I want to estimate if it is feasible to finish my application with Freertos. After this, I need to add another 4 channel SPI readings at 10K speed. Maybe it is not a good idea to use Freertos with my application. thanks.

edwards3 wrote on Wednesday, May 06, 2015:

How long does? Sounds like you answered your own question. Sounds like you are doing it the slowest way though, do you need the queue? If the isr is writing and the task is reading and the variable is 32-bits then the task can read it directly with no worry about data consistency. Write the data to a variable then use a task notification to tell the task. Its much faster than a queue. Or send the ADC result to the task directly as the value along with the notification, again must faster. Finally just have the interrupt write the data to a RAM buffer (circular probably). If there is too much disturbance in timing then use a interrupt priority above configMAX_SYSCALL_INTERRUPT_PRIORITY, but then you cant use the FreeRTOS API. I would not plan to switch tasks at that speed though.