Real-time system low power consumption principle and implementation, very practical solution

Click on "Uncle Wheat" above and select "Top/Star Public Account"

Welfare dry goods, delivered as soon as possible

foreword

At present, more and more embedded products are used RTOSas , and at the same time, the requirements for low power consumption in development are getting higher and higher. This article will discuss how to deal with low power consumption of microcontrollers in RTOS. characteristic.

The preemptive task scheduling mechanism based on time slice rotation is RTOSgenerally low-power design ideas are as follows:

  • When the Idletask is running, enter the low power mode;

  • Wake-up by interrupt or external event under appropriate conditions MCU.

However, it can be seen from the second point that every time the OSsystem timer generates an interrupt, it will also MCUwake up from the low power mode, and frequent entry into the low power mode/wake up from the low power mode will make it MCUimpossible to Going into deep sleep is also unreasonable for low-power designs.

FreeRTOSA low-power design pattern - , is given in Tickless Idle Mode, which allows you to stay in low-power mode for MCUlonger periods of time.

Principle and Implementation of Tickless Idle Mode

Scenario Analysis

d5d469da10aa476faea27bf4d6f2a86f.png


The above figure is a schematic diagram of task scheduling, the horizontal axis is the time axis, T1, T2, T3, T4is RTOSthe time slice benchmark of , and there are four tasks TaskA, TaskB, TaskC, TaskD:

  • Task A, a periodic task

  • Task B, periodic tasks

  • Task C, emergent tasks

  • Task D, a periodic task

It can be seen from the figure that there will be four idle periods between the scheduling of the four tasks ( RTOSthe Idletask will be scheduled to run at this time, and the goal of the software design should be to make MCUthe Idletask run in a low-power mode as much as possible).

1. Idle1

IdleDuring the running of the task, a system clock tick will be generated, and it will wake up at this time MCU. After wake-up, it MCUwill enter the low-power mode again. This wake-up is meaningless. It is expected MCUto Idle1keep in low-power mode during , so adjust the system timer interrupt appropriately so that T1the system clock interrupt is not triggered when , and the interrupt trigger point is set to Task Bwhen it arrives.

2. Idle2

Task CWake up before the system tick arrives MCU(external event), canMCU be in low power mode all the time;Idle2

3.Idle3

The same as the Idle2situation , but the Idle3time is very short, if this time is very short, then entering the low-power mode does not make much sense, so the software should add a strategy when entering the low-power mode;

4. Idle4

Same Idle1situation as .

Software design principle of Tickless Idle Mode

Tickless Idle ModeThe design idea is to put it into a low-power mode when MCUidle . From the above scenario, it can be seen that the problems that need to be solved in software design are:

  • Reasonably enter low-power mode (avoid MCUfrequent unnecessary switching between low-power mode and operating mode); RTOSthe system clock originates from a periodic timer in hardware ( Cortex-Mmostly used by series kernels SysTick), and RTOSthe task scheduling The timer can expect the trigger time of the next periodic task (or timer task), as mentioned above, adjusting the system clock timer interrupt trigger time can avoid RTOSentering unnecessary time interrupts, thus staying at low for a longer time. In power mode, the RTOS clock is no longer periodic but dynamic (interrupts will no longer be generated at the original clock reference, ie Tickless).

  • Compensates the system clock in some way when MCUit wakes up. MCUIt may be awakened by two situations, a dynamically adjusted system clock interrupt or a sudden external event, in either case, it can be calculated by some kind of timer running MCUin Time in power mode, software compensation for system time after MCUwake ;

  • In software implementation, problems should be handled according to specific application scenarios and MCUlow power consumption characteristics. In particular, MCUthe low power consumption characteristics of , MCUthe peripherals (mainly timers) that can be used in different low power consumption modes are different, and RTOSthe system clock can be adjusted appropriately.

Implementation of Tickless Idle Mode

Taking the STM32F407series as an example , the first thing MCUto be clear is MCUthe low power consumption F407mode of , which is implemented in the mode .SleepStopStandbyRTOSSRAMRTOSSleep

0ae9fe7504d6182eb9af7f449b0279e0.png


1. Enable

#define configUSE_TICKLESS_IDLE    1

2. Idle task (automatically called when RTOS is idle)

3. Low-power mode processing (write the code according to the low-power mode of the MCU, the code is a bit long...)

At last

STM32There are different series in the family, especially the L series designed for low-power applications, for which the RTOSlow- power features can be implemented in more ways (for example, when the core stops running in a certain mode, you can Use an external timer RTCor instead Systickas a system timer).

Transferred from the public account: learn embedded together

Copyright statement: This article comes from the Internet, and the copyright belongs to the original author. Copyright issues, please contact to delete.

—— The End ——

Recommended in the past

How do single-chip microcomputers of different levels realize communication?

Summary of companies in various segments of the domestic semiconductor industry

How to drive a project manager crazy? Remember these 10

MCU firmware self-update, a reliable and practical method

How to become a master? The advanced road of embedded development...

How to design a reliable solution for high-load serial communication of single-chip microcomputer?

Click on the card above to follow me

e846cbc9f736c94b47c7f0a694558d12.png

Everything you ordered looks good , I take it seriously as I like it

Guess you like

Origin blog.csdn.net/u010632165/article/details/124014257