Skip to content Skip to navigation

Connexions

You are here: Home » Content » 5.4 - Lab 5: Optimization and Low Power Modes

Navigation

Content Actions

  • Download module PDF
  • Add to ...
    Add the module to:
    • My Favorites
    • A lens
    • An external social bookmarking service
    • My Favorites (What is 'My Favorites'?)
      'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.
    • A lens (What is a lens?)

      Definition of a lens

      Lenses

      A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

      What is in a lens?

      Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

      Who can create a lens?

      Any individual Connexions member, a community, or a respected organization.

    • External bookmarks
  • E-mail the author

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual Connexions member, a community, or a respected organization.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • TI MSP430

    This module is included inLens: Texas Instruments MSP430
    By: Texas InstrumentsAs a part of collection:"Introduction to the Texas Instruments ez430"

    Comments:

    "This is the entire course organized at Rice University for all the basic lessons for using an MSP430. It is designed for the use of an eZ430 tool and is still under construction."

    Click the "TI MSP430" link to see all content affiliated with them.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

5.4 - Lab 5: Optimization and Low Power Modes

Module by: Naren Anand Based on: Lab 9: Optimization and Low Power Modes by adrian valenzuela

Summary: In this lab, we will learn the basics of optimizing code intended for embedded systems.

Low Power Modes and Code Optimization

Exercise 1: Fibonacci Optimization

The Reducing Power Consumption module discusses why it is important to keep power in mind when programming embedded devices. We have yet to consider this while programming the previous labs. Writing efficient code is the first step in improving power consumption, next we can disable all parts of the board that aren't currently being used.

Take the following piece of code:

long fibo(int n) 
{
  if (n < 2)
   return n;
  else 
   return fibo(n-1) + fibo(n-2);
}
It recursively calculate the nth number in a Fibonacci sequence recursively. Recursion makes this piece of code easier to read, however, it is very inefficient and consumes far more memory than it has to. If you try to compute a large number, say fibo(50), then it will take much longer and will consume more power than it should.

The original program is very inefficient and wastes memory in several of the ways described in the inefficient Memory Conservation module. Modify the code to eliminate the memory waste and improve the speed of the program. Note that there is a tradeoff between speed and memory (though at first the program is simply gratuitously wasteful). What is the nature of the tradeoff? Assuming the one addition takes one cycle to complete, how long would it take the original code to complete fibo(50)? How long would it take your new, improved version? Assume that you are only considering the addition operations.

Exercise 2: Low Power Modes

Modify your project so that the processor remains in one of the low power modes whenever it is not doing any calculations. Wake up from the low power mode using a timer interrupt (change the timer settings so that there is a substantial time period between interrupts) and have your program compute fibo(50). You may want to make the program compute fibo(50) more than once so that the MSP is in the ISR performing an intensive task for longer and thus make it easier to read the current consumption value. Output the result to the standard out display. What is the result? (Hint: 12,586,269,025) Make sure the result is correct number. As soon as the calculation is done, return to low power mode. Perform the same process to calculate the current consumption during the use of your Fibonacci function. You should have measured three current consumption values: 1) in the low power mode, 2) while processing fibo(50), and 3) while processing the 50th Fibonacci number using your function.

HINT:

A number must be small enough to fit in its given type. If it is too large, you may get unpredictable results. Try using a long long for extra huge numbers. Because of our printf settings, we cannot output such large data types. You must use bit-wise operations to separate the number into smaller chunks suitable for printing.
From now on, instead of while(1) at the end of programs, simply place the tool into a low power mode. This will allow future applications to more closely resemble and operate as real-world embedded programming.

Comments, questions, feedback, criticisms?

Send feedback