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 RTOS
as , 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 RTOS
generally low-power design ideas are as follows:
When the
Idle
task 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 OS
system timer generates an interrupt, it will also MCU
wake up from the low power mode, and frequent entry into the low power mode/wake up from the low power mode will make it MCU
impossible to Going into deep sleep is also unreasonable for low-power designs.
FreeRTOS
A low-power design pattern - , is given in Tickless Idle Mode
, which allows you to stay in low-power mode for MCU
longer periods of time.
Principle and Implementation of Tickless Idle Mode
Scenario Analysis
The above figure is a schematic diagram of task scheduling, the horizontal axis is the time axis, T1
, T2
, T3
, T4
is RTOS
the time slice benchmark of , and there are four tasks TaskA
, TaskB
, TaskC
, TaskD
:
Task A
, a periodic taskTask B
, periodic tasksTask C
, emergent tasksTask 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 ( RTOS
the Idle
task will be scheduled to run at this time, and the goal of the software design should be to make MCU
the Idle
task run in a low-power mode as much as possible).
1. Idle1
Idle
During 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 MCU
will enter the low-power mode again. This wake-up is meaningless. It is expected MCU
to Idle1
keep in low-power mode during , so adjust the system timer interrupt appropriately so that T1
the system clock interrupt is not triggered when , and the interrupt trigger point is set to Task B
when it arrives.
2. Idle2
Task C
Wake 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 Idle2
situation , but the Idle3
time 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 Idle1
situation as .
Software design principle of Tickless Idle Mode
Tickless Idle Mode
The design idea is to put it into a low-power mode when MCU
idle . 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
MCU
frequent unnecessary switching between low-power mode and operating mode);RTOS
the system clock originates from a periodic timer in hardware (Cortex-M
mostly used by series kernelsSysTick
), andRTOS
the 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 avoidRTOS
entering 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, ieTickless
).Compensates the system clock in some way when
MCU
it wakes up.MCU
It 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 runningMCU
in Time in power mode, software compensation for system time afterMCU
wake ;In software implementation, problems should be handled according to specific application scenarios and
MCU
low power consumption characteristics. In particular,MCU
the low power consumption characteristics of ,MCU
the peripherals (mainly timers) that can be used in different low power consumption modes are different, andRTOS
the system clock can be adjusted appropriately.
Implementation of Tickless Idle Mode
Taking the STM32F407
series as an example , the first thing MCU
to be clear is MCU
the low power consumption F407
mode of , which is implemented in the mode .Sleep
Stop
Standby
RTOS
SRAM
RTOS
Sleep
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
STM32
There are different series in the family, especially the L series designed for low-power applications, for which the RTOS
low- 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 RTC
or instead Systick
as 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
Everything you ordered looks good , I take it seriously as I like it