Introduction
Hello, my name is Guu.
It is so hot every day that I feel like melting, but I am still working hard on my training as usual.
The other day, we had a microcomputer programming training.
A microcontroller is like a small personal computer, and when you write a program into it, it performs various operations.
Come to think of it, it seems that microcontrollers called Nios® II or Arm® Cortex™-A9 can be put inside FPGAs!
Let's ask Poki later!
The brain of such microcontrollers is the "CPU", which is introduced in this article.
CPU is like a leader that issues commands to various devices (timers, clocks, etc.).
I have compiled episodes from my training where I created an "interrupt program" and thought to myself, "CPU is amazing!
An interrupt program is a program that forcibly switches to another operation while an operation is in progress.
In the training, we created an interrupt program that interrupts a program to blink a green LED with a program to blink a red LED.
In creating the program, the following assignment was made.
Assignment
"Please program a low power consumption mode in which the CPU does not operate (turns off) except when an interrupt is generated."
The microcontroller used in this training included the following three clocks.
And the assignment "low-power mode" means
M clock (MCLK) and CPU are turned off, and A clock (ACLK) and SM clock (SMCLK) are turned on.
When I saw this, I immediately thought to myself, "This is low-power mode, so the CPU is interrupted.
"It's low-power mode, so the CPU is not running except when interrupts occur..."
However!
What is issuing the commands for this program?
A clock? A timer?
No, it is the CPU.
Huh? If so, isn't the CPU also on when
interrupt occurs? ????
Explanation
In fact, the CPU even tells other devices (clocks and timers) what to do while it is stopped.
I will explain what this means with the help of a diagram.
First, the CPU tells ACLK and SMCLK what to do.
(In this training, ACLK is set to run at 2 kHz and SMCLK at 4 MHz.)
The CPU then takes a nap until time is up.
At this time, the CPU sets its own alarm clock (Timer A) before taking a nap.
(The CPU sets in advance when Timer A will generate an interrupt. Then it turns on low-power mode.)
Until the interrupt occurs
The CPU takes a nap, and the other devices (Timer A, ACLK, SMCLK) work as instructed by the CPU in advance.
(In low-power mode, MCLK and CPU are stopped, ACLK runs at 2 kHz, and SMCLK at 4 MHz.)
When an interrupt occurs
When the time is up, the alarm clock sounds and the CPU wakes up.
(When Timer A counts 4 seconds, Timer A generates an interrupt to the CPU. The low-power consumption mode ends and the CPU resumes operation.)
The CPU then works along with the other devices.
In this way, the CPU not only gives instructions when it is not working, but also decides when to sleep and when to wake up.
The chronological sequence of events is shown in the figure below.
Summary
CPU was an excellent leader who was able to manage both himself and the devices around him.
Supplement
Since the CPU consumes more power than other devices,
it is possible to reduce power consumption by minimizing the time the CPU is running using interrupt programs such as the one introduced in this article.
Reducing power consumption also extends battery life.
Guu's Tweet
The CPU is really a very clever guy, telling it what to do while you are asleep.
Well, it was me who actually set up this program... (^^)