Introduction

Hello, I'm Guu.
It's hot every day and I feel like I'm going to melt, but I'm still working hard on my training.
The other day, I did a microcomputer programming training.
A microcomputer is like a small personal computer, and if you write a program into it, it will perform various operations.

Come to think of it, it seems that microcomputers such as Nios® II and Arm® Cortex™-A9 can be put in FPGAs too!
Let's ask Poki later!

The "CPU" introduced this time can be said to be the brain of such a microcomputer.
The CPU is like a leader that issues commands to various devices (timers, clocks, etc.).

When I created an "interrupt program" in training, I tried to summarize the episodes that made me think "CPU is amazing!".
* An interrupt program is to forcibly switch to another operation while performing a certain operation.

In the training, we created an interrupt program that interrupts the program that blinks the red LED with the program that blinks the green LED.
In creating the program, the following problems arose.

 

Task
"Create a low power consumption mode program that does not operate (turn off) the CPU except when an interrupt occurs."

The microcomputer used in this training included the following three clocks.

And what is the problem "low power consumption mode"?
A state in which the M clock (MCLK) and CPU are turned off, and the A clock (ACLK) and SM clock (SMCLK) are turned on.

Seeing this made me immediately think.
"Because of the low power consumption mode, the CPU is not running except when an interrupt occurs..."

However!
What's issuing the commands for this program?
clock? timer?
No, it's the CPU.

that? If so,
Isn't the CPU on even when an interrupt occurs? ? ? ?

Commentary

In fact, the CPU even instructed other devices (clocks and timers) to work while it was stopped.

I will explain what this is all about using a diagram.

First, the CPU tells ACLK and SMCLK what to do.
(In this training, ACLK is set to operate at 2 kHz and SMCLK at 4 MHz.)

And the CPU takes a nap until the hour.
At this time, the CPU sets its own alarm clock (timer A) and then takes a nap.
(The CPU presets the timing for timer A to generate an interrupt, and turns on the low power consumption mode.)

■ Until an interrupt occurs

The CPU takes a nap and the rest of the devices (Timer A, ACLK, SMCLK) work as instructed by the CPU in advance.
(During low power mode, MCLK and CPU stop, ACLK runs at 2 kHz, SMCLK runs at 4 MHz)

■ When an interrupt occurs

When the time comes, the alarm clock rings 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.)

And the CPU works along with other devices.

In this way, the CPU not only gave instructions when it was not working, but also decided exactly when to sleep and when to wake up.

Looking at the sequence of events in chronological order, it looks like the figure below.

Summary

CPU was an excellent leader, able to manage himself and the devices around him.

■ Supplement

CPU consumes more power than other devices
Power consumption can be reduced by minimizing the amount of time the CPU needs to run using an interrupt program like the one introduced here.
Reducing power consumption also extends battery life.

■ guu's tweet

The CPU is really good at giving instructions in advance, even while you're asleep.
Well, I actually built this program (^^)