-
Home
- Microcontroller and embedded
- Labs
- Lab 9 - low power and optimization
- Lab 9: optimization and low
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(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.
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 bit-wise 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
how does Neisseria cause meningitis
is the branch of biology that deals with the study of microorganisms.
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
How bacteria create energy to survive?
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
which site have a normal flora
Many sites of the body have it
Skin
Nasal cavity
Oral cavity
Gastro intestinal tract
Safaa
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Binomial nomenclature
adeolu
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.