Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 8 months ago.
PIT generated IRQ from Ticker & Timer API
Hi, I have been having a little trouble with the PIT module in a MK20DX256. I am aware that the mbed API functions Ticker and Timer both make use of the PIT module. Specifically Ticker uses PITch(0&1) and Timer uses PITch(2&3). In my project I desire to use a PIT channel to trigger a relatively slow per 1mS interrupt to handle house-keeping tasks. You may ask, "what is the problem, why not simply use a Ticker object". Very reasonable response.....but.
When I configure a Ticker object I begin to see problems with interrupt priorities. In the rest of my project I have the processor running almost flat out well over 90% utilization as it handles DSP code. Therefore any mS based Ticker must have an IRQ priority lower than those used by the DSP functions. Okay, then I shall set all the PIT channels with a lower priority using:
NVIC_SetPriority(PITX_IRQn...
When I do this its makes no difference, I still see the DSP code which is running in a higher priority begin 'glitched'. It does not block, but simply causes a few samples to be missed. This is possible because I only call the DSP ISR if it has finished its last block of data. I use :
if(!NVIC_GetActive(DSP_IRQn)) NVIC->STIR = DSP_IRQn;
So anything causing the DSP ISR to slow does not lock the system.
So why do the PIT channels do this? Regardless if I set them at the lowest possible IRQ priority.
I have worked around the problem by writing my own Timer class, that has counters updated from within the DSP code, and simply calls a STIR when 1mS timer has been reached. This STIR IRQ I set lower than the DSP and heypresto, it stops the glitches totally. I can then load the DSP right up to over 99% utilization and still I can run background tasks without glitches.
But if I use either a Timer or Ticker object, I am forced to keep utilization to below 50% or it seems the IRQ from these APIs cause the problems described.
Anyone have any insight as to why and exactly how the Ticker and Timer functions use IRQs, I have delved into the API code and can find how the PIT is configured within the file: targetxx/devicexx/us_ticker.c Nothing to strange. but what I struggle to understand is what is going on with the PITch IRQs.
I suspect both these functions generate uS IRQs and perhaps what is happening is that the stacking and unstacking is hogging the resources.
Anyone with further insight?