diff --git a/miosix/kernel/scheduler/priority/priority_scheduler.cpp b/miosix/kernel/scheduler/priority/priority_scheduler.cpp
index 1ecefc648349e0c73d98bff7efb363bae3bc227b..8fbee9b6921e6ae75ad4cf86a346c6fba1de4f29 100644
--- a/miosix/kernel/scheduler/priority/priority_scheduler.cpp
+++ b/miosix/kernel/scheduler/priority/priority_scheduler.cpp
@@ -215,16 +215,12 @@ static void IRQsetNextPreemption(bool curIsIdleThread){
     else
         firstWakeupInList = sleepingList->front()->wakeup_time;
     
-    if (curIsIdleThread){
-        timer.IRQsetNextInterrupt(firstWakeupInList);
-        nextPeriodicPreemption = std::numeric_limits<long long>::max();
-    }else{
-        nextPeriodicPreemption = timer.IRQgetCurrentTime() + preemptionPeriodNs;   
-        if (firstWakeupInList < nextPeriodicPreemption )
-            timer.IRQsetNextInterrupt(firstWakeupInList);
-        else
-            timer.IRQsetNextInterrupt(nextPeriodicPreemption);
-    }
+    if (curIsIdleThread)
+        nextPeriodicPreemption = firstWakeupInList;
+    else
+        nextPeriodicPreemption = std::min(firstWakeupInList, timer.IRQgetCurrentTime() + preemptionPeriodNs);
+    
+    timer.IRQsetNextInterrupt(nextPeriodicPreemption);
 }
 
 unsigned int PriorityScheduler::IRQfindNextThread()