How an Interrupt Driven Embedded System Can Save You Power

What is an interrupt driven system?

Our lives revolve around ener­gy. This is a fact I’m remind­ed of every time there’s a bad storm in my area and the elec­tric­i­ty goes out. In the world of advanced dri­ver assis­tance sys­tems (ADAS) power also reigns supreme. Semi-autonomous and self-dri­ving cars need more and more sen­sors to oper­ate effec­tive­ly, mak­ing low power oper­a­tion increas­ing­ly impor­tant. It just so hap­pens that how you inter­act with all of those sen­sors has a huge effect on your system’s ener­gy con­sump­tion. There are three main schemes you can use to gath­er data from your sen­sors: con­tin­u­ous polling, fixed inter­val pro­cess­ing, and inter­rupt pro­cess­ing. Out of these three options, inter­rupt pro­cess­ing will save you the most power by gath­er­ing data only when data is avail­able. There can be a few prob­lems, though, that you’ll need to watch out for when using inter­rupts.

Data Gathering

As I said before there are essen­tial­ly three ways to han­dle events or gath­er data in a sys­tem: polling con­tin­u­ous­ly, polling at inter­vals or han­dling events trig­gered by inter­rupts. Let’s quick­ly go through how each of these work

  • Con­tin­u­ous Polling - This is by far the sim­plest way to han­dle events. In this arrange­ment, your code will check on periph­er­als con­tin­u­ous­ly until one rais­es an event flag. Once that mark­er has been noticed, your pro­gram will take care of that event and then go back to polling.
  • Inter­val Polling - In this method instead of polling con­tin­u­ous­ly you poll at cer­tain incre­ments. Let’s say you have a LIDAR array that com­pletes 20 full 360° sweeps in one sec­ond and stores each sweep for pro­cess­ing. You could set your pro­gram to sam­ple that data at 20Hz and get a full 360° pic­ture every time.
  • Inter­rupt Pro­cess­ing - With this scheme, your pro­gram doesn’t poll its periph­er­als to see if they’re ready, it waits for them to inter­rupt the pro­gram. So, when­ev­er a sen­sor has some­thing to say to the proces­sor it will send an inter­rupt sig­nal, ask­ing the con­troller to stop what­ev­er it’s doing and han­dle that event.


Use inter­rupts to make your sys­tem more ener­gy effi­cient.

Why Are Interrupts More Efficient?

Uti­liz­ing inter­rupt ser­vice rou­tines (ISRs) in your pro­gram can help you great­ly reduce your system’s power usage. They do this by keep­ing your micro­proces­sor from con­tin­u­ous­ly run­ning in idle loops that do noth­ing. Inter­rupts are also more sim­ple to imple­ment than inter­val polling.

Remem­ber that with con­tin­u­ous polling, and even inter­val polling, your micro­con­troller unit (MCU) is check­ing periph­er­als regard­less of whether they are ready. If you have a sys­tem that is con­stant­ly updat­ing any­way, this may not be a big deal. How­ev­er, if you’re check­ing a sen­sor 10 times a sec­ond and it only updates once per sec­ond, you’re just burn­ing power the other nine times. Most MCUs now have sleep states they can enter when not exe­cut­ing instruc­tions. Using inter­rupts allows your sys­tem to wake on events, deal with what­ev­er is hap­pen­ing, and then go back into power sav­ing mode.

If you know exact­ly when a sen­sor will be ready to com­mu­ni­cate you might think about using inter­val-based polling. After all, you won’t waste ener­gy because you know when events are com­ing up. Time-based archi­tec­tures are dif­fi­cult to imple­ment, though, and the same effect can be achieved with easy to use inter­rupts.


Make sure not to cor­rupt any data when exe­cut­ing ISRs.

What To Watch Out For

Inter­rupts can be pow­er­ful but come with a risk, just like point­ers in C. If you alter vari­ables or other parts of your code dur­ing an ISR you could upset the pro­gram when it returns to main. In addi­tion, you need to be aware of how long your code will take to han­dle an inter­rupt event.

When writ­ing ISRs you need to take care not to dis­turb any essen­tial data in the main pro­gram. There is always a risk of upset­ting anoth­er vari­able or piece of mem­o­ry on acci­dent, which is why it’s impor­tant to test your sys­tem while it’s run­ning. Usu­al­ly, an inter­rupt will save what’s in your reg­is­ters and other crit­i­cal pieces so that your pro­gram can resume nor­mal­ly after the ISR is fin­ished. That being said, you should still take care not to write over crit­i­cal vari­ables or oth­er­wise dis­turb what­ev­er func­tion might be run­ning when an inter­rupt occurs.

Some­times you’ll have crit­i­cal func­tions that must fin­ish their oper­a­tions before an inter­rupt can be han­dled. Be very care­ful when dis­abling inter­rupts for these pieces of code, as you can then intro­duce long inter­rupt laten­cies. You may not care right now if your sys­tem is sig­nal­ing that tire pres­sure is low. Though you’ll care a lot more if one of your ultra­son­ic sen­sors is say­ing that your car is about to crash into some­thing. To keep laten­cy down you should assign your func­tions and ISRs dif­fer­ent pri­or­i­ties so that mis­sion-crit­i­cal code is always exe­cut­ed. You should also re-enable inter­rupts as soon as pos­si­ble in your nor­mal code and dur­ing ISRs.

There are lots of dif­fer­ent ways to make your code per­form more effi­cient­ly, but not all of them have to do with com­pil­er opti­miza­tions like loop unrolling or func­tion inlin­ing.  Some­times the way your code inter­acts with other parts of the sys­tem can have an even greater effect. Using inter­rupt pro­cess­ing instead of any kind of polling will almost always save you ener­gy. Just be care­ful that you don’t cor­rupt your pro­gram in an ISR or ignore a crit­i­cal inter­rupt sig­nal.

As I just said, your sen­sor com­mu­ni­ca­tion is only part of the issue. The soft­ware you choose to make your pro­gram can also great­ly impact the per­for­mance and effi­cien­cy of your sys­tem. TASKING has devel­oped a wide vari­ety of prod­ucts that are made specif­i­cal­ly for smart vehi­cles. They have pio­neered things like a stand­alone debug­ger and an excel­lent sta­t­ic analy­sis tool that can help you write fast and excel­lent code.

Have more ques­tions about han­dling periph­er­als? Call an expert at TASKING.

Scroll to Top