Super loop vs RTOS

Hiya all,

I'm working on a bicycle computer, and there are many components in it which rely on timing (such as measuring speed).

At the moment I just have a loop for each of the components (radio, bicycle computer) that are called in the Arduino loop function.

Would using a rtos, like freertos provide more predictable performance? And which is the better approach in this case, super loop or rtos?

I'm no expert on RTOS, but I suspect the answer might depend on the resources of the microcontroller you're using. So it would probably be helpful if you provided that information (e.g. which Arduino board you're using).

pert:
I'm no expert on RTOS, but I suspect the answer might depend on the resources of the microcontroller you're using. So it would probably be helpful if you provided that information (e.g. which Arduino board you're using).

I haven't chosen a board for the project, but it's going to be either a nano or a mega, I have both so it shouldn't be trouble to choose either.

I'd not use an RTOS on a nano or a mega. Those devices do not have the arse to handle the RTOS overhead.

I used the RTOS, uMT on the DUE. uMT runs real well on the Due.

freeRTOS is built-in to the ESP32 as an OS. I use freeRTOS with the ESP32, runs great.

On the surface I'm thinking that a bicycle computer doesn't need a real-time operating system if the alternative -- a "super loop" as you call it -- is written correctly.

Hi,

I'd not use an RTOS on a nano or a mega. Those devices do not have the arse to handle the RTOS overhead.

Hmm.. Seems like a lot of people use it OK. Some info here:
https://create.arduino.cc/projecthub/feilipu/using-freertos-multi-tasking-in-arduino-ebc3cc
Uses 7-10K of flash.

I tried the Blink/analogread example on an Uno and it runs fast, using:

Sketch uses 8542 bytes (26%) of program storage space. Maximum is 32256 bytes.
Global variables use 358 bytes (17%) of dynamic memory, leaving 1690 bytes for local variables. Maximum is 2048 bytes.

I'll admit to a long-term relationship with RTOS's. I wrote a working one for 6502 long ago. I wrote a couple of big semiconductor test systems using IBM's EDX.

I should rewrite my robot code using one. A good Winter activity while stoking the woodstove, writing how-to stuff for Arduino, getting the snowmobile started, making a remote monitoring system for my son's new/old house, washing dishes, driving to the post office to pick up parts from China, making drinks for my Working Wife.. :slight_smile:

a bicycle computer doesn't need a real-time operating system if the alternative -- a "super loop" as you call it -- is written correctly.

Agree. I have a large home automation system running on a Mega. I need fast response to decode Morse Code. In loop() I have a State Machine that has three main calls:

checkSensors();
makeDecisions();
takeActions();

Inside the makeDecisions and takeActions routines I have a "roundRobin" state machine that gives uneven time to different functions.

Reading the temperature sensors only happens every few seconds. Checking the input bit for the Morse Code decoder happens every loop.

So I can lie in bed with my eyes closed, fumble for the switch, send "T" and hear the temperature report. The Mega has extra hardware serial ports with buffering, so I don't think sending the short serial text data to the separate text-to-speech board impacts the timing much.

Unless you are looking for every passing spoke, I don't think you have a problem.

Let us know how it all works out..

terryking228:
I have a large home automation system running on a Mega. I need fast response to decode Morse Code.

...

So I can lie in bed with my eyes closed, fumble for the switch, send "T" and hear the temperature report.

Seems we think alike in terms of controlling home automation with simple touch switches, though you are well ahead of me. :grinning:

To have responsiveness in a RTOS you are committed to implement it with interrupts. You essentially waste time in the task switching code, which same time could be used instead for polling those important inputs. So in effect, you need a faster processor simply to cover for the additional complexity. :roll_eyes: