




In this lab, we will learn the basics of optimizing code intended for embedded systems.
Low power modes and code optimization
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(n1) + fibo(n2);
}
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.
Got questions? Get instant answers now!
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 low power mode when a pushbutton interrupt fires, and have your program compute
fibo(50)
. Output the result to the standard out display. What is the result? (Hint: 12,586,269,025) Make the result is correct number. As soon as the calculation is done, return to low power mode. Make sure to turn on the Red LED while in an idle state.
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. If your standard out does not support such large data types then you may have to use bitwise operations to separate the number into smaller chunks suitable for printing.
Measure the power consumed by the entire device when you are in low power mode and when it is computing something. You may want to have the processor compute something indefinitely, in order to get a more accurate result.
Got questions? Get instant answers now!
Questions & Answers
what is the coefficient of 4×
the operation * is x * y =x + y/ 1+(x × y) show if the operation is commutative if x × y is not equal to 1
An investment account was opened with an initial deposit of $9,600 and earns 7.4% interest, compounded continuously. How much will the account be worth after 15 years?
lim x to infinity e^1e^1/log(1+x)
given eccentricity and a point find the equiation
12, 17, 22.... 25th term
Akash
College algebra is really hard?
Absolutely, for me. My problems with math started in First grade...involving a nun Sister Anastasia, bad vision, talking & getting expelled from Catholic school. When it comes to math I just can't focus and all I can hear is our family silverware banging and clanging on the pink Formica table.
Carole
I'm 13 and I understand it great
AJ
I am 1 year old but I can do it! 1+1=2 proof very hard for me though.
Atone
Not really they are just easy concepts which can be understood if you have great basics. I am 14 I understood them easily.
Vedant
find the 15th term of the geometric sequince whose first is 18 and last term of 387
The given of f(x=x2. then what is the value of this f(3) 5f(x+1)
hmm well what is the answer
Abhi
If f(x) = x2
then, f(3) when 5f(x+1)
5((32)+1)
5(1+1)
5(2)
10
Augustine
how do they get the third part x = (32)5/4
make 5/4 into a mixed number, make that a decimal, and then multiply 32 by the decimal 5/4 turns out to be
AJ
can someone help me with some logarithmic and exponential equations.
sure. what is your question?
ninjadapaul
okay, so you have 6 raised to the power of 2. what is that part of your answer
ninjadapaul
I don't understand what the A with approx sign and the boxed x mean
ninjadapaul
it think it's written 20/(X6)^2
so it's 20 divided by X6 squared
Salomon
I'm not sure why it wrote it the other way
Salomon
ok. so take the square root of both sides, now you have plus or minus the square root of 20= x6
ninjadapaul
oops. ignore that.
ninjadapaul
so you not have an equal sign anywhere in the original equation?
ninjadapaul
is it a question of log
Abhi
I rally confuse this number And equations too I need exactly help
salma
But this is not salma it's Faiza live in lousvile Ky I garbage this so I am going collage with JCTC that the of the collage thank you my friends
salma
im all ears I need to learn
Sherica
right! what he said ⤴⤴⤴
Tamia
what is a good calculator for all algebra; would a Casio fx 260 work with all algebra equations? please name the cheapest, thanks.
A soccer field is a rectangle 130 meters wide and 110 meters long. The coach asks players to run from one corner to the other corner diagonally across. What is that distance, to the nearest tenths place.
Jeannette has $5 and $10 bills in her wallet. The number of fives is three more than six times the number of tens. Let t represent the number of tens. Write an expression for the number of fives.
What is the expressiin for seven less than four times the number of nickels
How do i figure this problem out.
how do you translate this in Algebraic Expressions
why surface tension is zero at critical temperature
Shanjida
I think if critical temperature denote high temperature then a liquid stats boils that time the water stats to evaporate so some moles of h2o to up and due to high temp the bonding break they have low density so it can be a reason
s.
Need to simplify the expresin. 3/7 (x+y)1/7 (x1)=
. After 3 months on a diet, Lisa had lost 12% of her original weight. She lost 21 pounds. What was Lisa's original weight?
Got questions? Join the online conversation and get instant answers!
Source:
OpenStax, Microcontroller and embedded systems laboratory. OpenStax CNX. Feb 11, 2006 Download for free at http://cnx.org/content/col10215/1.29
Google Play and the Google Play logo are trademarks of Google Inc.