0
0
FreeRTOSprogramming~3 mins

Hard real-time vs soft real-time in FreeRTOS - When to Use Which

Choose your learning style9 modes available
The Big Idea

What if a tiny delay in your code could cause a robot to crash or a heart to stop beating on time?

The Scenario

Imagine you are controlling a robot arm that must stop immediately if it detects an obstacle. You try to check the sensor manually in your code without strict timing rules.

The Problem

Without clear timing guarantees, your robot might react too late or inconsistently. This delay can cause accidents or damage because your code can't promise when it will respond.

The Solution

Hard real-time systems guarantee that critical tasks finish within a strict deadline every time, while soft real-time systems aim to meet deadlines but allow occasional delays. This helps you design safe and reliable control programs.

Before vs After
Before
while(true) {
  if(sensor_detects_obstacle()) {
    stop_robot();
  }
  // no timing guarantees
}
After
vTaskDelayUntil(&lastWakeTime, period);
if(sensor_detects_obstacle()) {
  stop_robot();
}
// guaranteed timing in hard real-time
What It Enables

This concept enables building systems that can reliably control machines or processes where timing is critical for safety and performance.

Real Life Example

In a pacemaker device, hard real-time ensures the heart receives electrical pulses exactly on time to keep a steady heartbeat, preventing life-threatening delays.

Key Takeaways

Hard real-time means strict, guaranteed timing for critical tasks.

Soft real-time allows some timing flexibility but aims to be fast.

Choosing the right type helps build safe and efficient embedded systems.