Electronic – Mbed OS efficiency

mbed

I'm planning on using the mbed in a motion control project, where certain threads need to run at a specific, high frequency.

Using the mbed library, I could use Ticket to calculate the time spent within a thread, and then subtract that from the desired wait time, and then feed the result into the thread::wait method to ensure a consistent frequency. However, would this be efficient at high frequencies (1500hz with some heavy calculations in the thread)?

In such cases, would it be better to take advantage of the lower level CMSIS libraries?

I realise this question is quite vague, but any comments, advice, etc would be a great help.

Best Answer

If you set a Ticker it will already set a hardware timer, and the callback will run in an ISR with highest priority. You can then bounce the event back to a thread which runs at a lower / higher priority depending on the event (e.g. via Semaphore, Queue or EventQueue).

The rest of your threads can have a priority (e.g. osPriorityRealtime which I think is the highest in Mbed OS 5) and you can balance things here. If you pause the thread (Thread::wait) it'll yield back to lower priority threads.