5 years, 6 months ago.

How to set ticker lowest priority??? (Using XNUCLEO-F411RE)

Now I'm trying to set ticker with lowest priority.

But it doesn't work.

#include "mbed.h"

volatile int counter = 0;
void timing_critical() {
    counter++;
}

void long_event() {
    wait_ms(50);
}

PwmOut out(PB_4);
InterruptIn in(PA_0);
Ticker tick;

int main() {
    out.period_ms(10);
    out.pulsewidth_ms(5);
    in.rise(&timing_critical);
    
    //__NVIC_SetPriority(EXTI0_IRQn, 0);
    printf("1) InterruptIn only...\n\r");    
    for(int i=0; i<5; i++) {
        counter = 0;
        wait(1);
        printf("counts/sec = %d\n\r", counter);
    }


    tick.attach(&long_event, 0.1);    
    
    printf("2) InterruptIn plus long running occasional ticker event...\n\r");    
    for(int i=0; i<5; i++) {
        counter = 0;
        wait(1);
        printf("counts/sec = %d\n\r", counter);
    }

    printf("3) InterruptIn plus long running occasional ticker event at lower priority...\n\r");    
    NVIC_SetPriority(TIM3_IRQn,255); // set mbed tickers to lower priority than other things

    for(int i=0; i<5; i++) {
        counter = 0;
        wait(1);
        printf("counter = %d\n\r", counter);
    }
}

Could you please spell out what does not work?

posted by Zoltan Hudak 16 Oct 2018

I set TIMER3 at lowest priority. But the ticker is still at highest priority...

posted by wonjae ryu 17 Oct 2018
  • How are you able to figure that out, with your program? What suppose to happen if ticker's priority was lower than the priority of InterruptIn?
  • I think, Ticker is based us_ticker and that is using TIM5
posted by Zoltan Hudak 17 Oct 2018

After 3rd printf comes out, the variable 'counter' should have larger value than 100. But still lower than 100, I changed TIM3 to TIM5, But it doesn't work in my intention.

posted by wonjae ryu 17 Oct 2018
  • But the counter is incremented in the timing_critical function which is is attached to the InterruptIn.rise event (activated when a push button is pressed?). The Ticker is serviced in the long_event ISR which does not increment the counter but rather only waits 50ms.
  • Are you pressing the push button so frequently that it's getting incremented so quickly? Or is the PwmOut pin (PB_4) connected with wire to the InterruptIn pin (PA_0)?
  • How could the counter be at the same time larger than 100 and lower than 100?
  • If the Ticker's ISR is called in critical section, as Naveen said, then it means that all interrupts are disabled on entering the ISR and resumed only on returning from it. This means that no interrupts are triggered (and hence serviced), no matter how high priority they could have, while the Ticker's ISR is executed.
posted by Zoltan Hudak 17 Oct 2018

Yes, PwmOut pin(PB_4) is connected to InterruptIn pin(PA_0). So it has same value 100. But when the ticker comes out, the value of counter becomes 60 as the ticker has higher priority than InterruptIn. You mean priority of ticker interrupt can never be changed?

posted by wonjae ryu 18 Oct 2018

Effectively not. However, you can achieve your goal by using an EventQueue instead of a Timer.

posted by Zoltan Hudak 18 Oct 2018

Thank you for your kind explanation! Zoltan!

posted by wonjae ryu 19 Oct 2018

1 Answer

5 years, 6 months ago.

Hi Wonjare,

The ticker's interrupt runs at highest priority and in the implementation, it is serviced with in a critical section and thus disabling all other interrupts. This will result in the priority being virtually elevated.

I hope that answers your question. Please let us know if you have any further questions.

Thanks,

Naveen,

Team mbed.

Accepted Answer

You mean no way to modify the priority of the ticker??

posted by wonjae ryu 17 Oct 2018

Yes, since it is virtually elevated to the highest priority, you wouldn't be able to lower the priority.

posted by Naveen Kaje 22 Oct 2018