[From the last episode: We saw what it means for an electronic systemThis is a very generic term for any collection of components that, all together, can do something. Systems can be built from subsystems. Examples are your cell phone; your computer; the radio in your car; anything that seems like a "whole." to sleepThe state of a machine where as many non-essential electronic elements as possible are shut down, without powering the machine completely down..]
You’re on a phone call having a conversation, and you hear the sound that indicates that someone else is trying to call you. So excuse yourself to the person you’re talking to and quick take the new call, placing the old call on hold. Once you finish your business with the new call, you go back to the old call and continue where you left off.
Sorry for Interrupting, but…
ProcessorsA computer chip that does computing work for a computer. It may do general work (like in your home computer) or it may do specialized work (like some of the processors in your smartphone). have a feature that works a similar way. And it’s not a modern feature; it goes way back. It’s called an interruptA processor feature that let’s some event interrupt the program that a processor is running for a short time before returning the processor to the original program. In and IoT device, it may wake the processor rather than interrupting some other task.. Now, we know that processors take a program and simply march thought it, taking branches and calling functionsA small portion of a program that’s set aside and given a name. It helps isolate key code in an easy-to-understand way, and it makes changes easier and less error prone. It’s a really important way to make programs easier to understand. May also be called a subroutine. as necessary. Why would it need a way for something else to barge in and interrupt the flow of a perfectly well-behaved program?
Well, depending on what the processor is doing, there may be other side tasks that need attending to, and it might be time-sensitive. Picture yourself as a manager in an office working away on something, and the admin comes in and says, “You’re 3:00 is going to be a little bit late.” You briefly stop what you’re doing, make an adjustment in your calendar, and then get back to work.
The processor does the equivalent of this. Each processor has an interrupt scheme built into it. When an interrupt of sufficient priority comes in (yes, some processors can ignore lower-priority interrupts for a time), then the program currently being executed is set aside – which usually means saving some information about where it was – and the code associated with the interrupt starts executing. When it’s done, then the processor restores the original program and continues on its merry way.
Interrupts and the IoT
So what use might this be in an IoTThe Internet of Things. A broad term covering many different applications where "things" are interconnected through the internet. device?
Well, as we’ve seen, pretty much any IoT device is going to have some kind of sensor. And a processor in the device will do something with the sensor reading. So how does it get the information from the sensor?
Well, it can simply go and read the sensor electrically. Simple. But… let’s say that you’ve got a temperature sensor that’s supposed to provide a temperature reading every 15 minutes. How will that work? Well, here are a couple possible ways:
- The processor can poll the sensor. That means that, on a regular basis (every second? 10 times a second?), it goes to see if there’s a new measurement. This is the computing equivalent of the kid in the back seat asking, “Are we there yet?” over and over until the answer is finally, “Yes!”
- The processor can count down 15 minutes and then go read the sensor.
Sounds straightforward, but there’s a problem here. We’re talking about a simple processor doing pretty simple stuff. So it’s likely that, between readings, all the processor will be doing is asking, “Are we there yet?” continuously or counting down the minutes until the next read. Not particularly useful work. And the biggest problem is that it’s burning energy – probably from a battery – to do it. That can drain the battery pretty quickly.
A Lower-Power Approach
What would be nicer, from an energy-saving standpoint, is if the processor could go to sleep for 15 minutes, wake up to take a measurement, process the measurement, and then go back to sleep until the next 15 minutes are up. But, if it’s not counting the time, how does it know when 15 minutes have elapsed?
This is where an interrupt can help. With an interrupt, the processor can be mostly asleep, with nothing but timing and interrupt-related stuff still awake. When it’s time to take a reading, we can issue an interrupt, which will wake the processor so that it can do its thing before going back to sleep. This gives us a couple of options:
- We could have the sensor interrupt the processor when it takes a new reading. It would have to be able to count the 15 minutes itself so that it knows when to take the reading, but that’s not a tall order. Many sensorsA device that can measure something about its environment. Examples are movement, light, color, moisture, pressure, and many more. do support interrupts this way.
- We could have some other timer that counts down the 15 minutes, waking the processor when the time elapses so that it can ask the sensor what the latest reading is. This may sound like the second option above, but the critical difference is that, above, the processor itself is counting the 15 minutes. In this case, the processor is asleep while some other circuit counts down the time.
Either way, we save lots of energy by putting the processor to sleep and relying on other, much lower-power circuits, to handle things while the processor sleeps.
Everyone Loves a Nap (Except Maybe Your Boss)
I suppose that this specific example would have us modify the office analogy above. Instead of the manager working on one thing and being interrupted with something else, here the manager is taking a nap, with someone waking them up when the next appointment arrives. To be clear, interrupts can be used for lots of different things, and they don’t all involve putting the processor to sleep. But that’s one way in which it applies to the IoT.
Leave a Reply