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, 5 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); } }
1 Answer
6 years, 5 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.
Could you please spell out what does not work?
posted by Zoltan Hudak 16 Oct 2018I 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,
posted by Zoltan Hudak 17 Oct 2018Ticker
is basedus_ticker
and that is usingTIM5
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
- Are you pressing the push button so frequently that it's getting incremented so quickly? Or is the
- How could the
- If the
posted by Zoltan Hudak 17 Oct 2018counter
is incremented in thetiming_critical
function which is is attached to theInterruptIn.rise
event (activated when a push button is pressed?). TheTicker
is serviced in thelong_event
ISR which does not increment thecounter
but rather only waits 50ms.PwmOut
pin (PB_4) connected with wire to theInterruptIn
pin (PA_0)?counter
be at the same time larger than 100 and lower than 100?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 theTicker
's ISR is executed.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 2018Effectively not. However, you can achieve your goal by using an EventQueue instead of a Timer.
posted by Zoltan Hudak 18 Oct 2018Thank you for your kind explanation! Zoltan!
posted by wonjae ryu 19 Oct 2018