This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-F2800157: Advice for running motor control with FreeRTOS

Part Number: LAUNCHXL-F2800157

I'm transitioning a motor controller to using FreeRTOS for task scheduling. However, I'm relatively new to using an RTOS, and am uncertain about the best way to execute high frequency tasks:

1. Some of my tasks need to run at 10 kHz. It seems ridiculous to run FreeRTOS fast enough to schedule these, so I think I have to use a timer and interrupts to run these, via deferred interrupt handling (https://www.freertos.org/deferred_interrupt_processing.html).

2. Some of my tasks need to run at 1 kHz. I'm not sure whether I should try to run FreeRTOS faster (perhaps ~5kHz?) or use a timer and deferred interrupt handling for these as well.

3. FreeRTOS noob question: If I do use a timer and deferred interrupt handling, how do I avoid messing up some in-progress task when an interrupt happens mid-task? Ie, if taskA is interrupted and the interrupt is going to resume taskB, is there a way to manually save the taskA context so everything is in order when taskB is completed and we return to taskA?

4. Finally, any other obvious mistakes I'm making here? Or advice to give?

I'm mainly using https://www.nxp.com/docs/en/application-note/AN12881.pdf as a reference for this work.

  • Hi Michael,

    1 & 2 : It is generally not recommended to go over 1KHz with time slicing, since too much time will be spent on switching tasks (However, no upper limit is enforced by FreeRTOS). So yes, using deferred interrupts would be a good choice here.

    3: The FreeRTOS scheduler will handle the context save and restore when switching between tasks. This does not need to be done manually. 

    4. You seem to be on the right track. A few things to look out for would be to make sure your priorities are configured correctly (both for the FreeRTOS tasks, and the control ISRs), and that you are using the _FromISR() APIs from within the interrupt ISRs.

    Thanks,

    Arnav