Arduino measuring power to run code

157 views Asked by At

I have c code running on bear metal (no OS). The code takes in some sensor data, performs a computation, forms a packet and transmits. The board is battery powered.

I'm interested in knowing the energy consumed for each operation in Jules. Is this possible? How would one go about doing it?

1

There are 1 answers

0
Taylor Kidd On

The number of joules used per instruction depends upon the processor you are using and which instruction you are looking at. I believe the ARM and the Atmel AVR processors have no real hardware power management which makes things simpler.

How much energy an instruction uses has to do with how much and what type of on-silicon circuitry it uses. This means that trying to theoretically compute the number of joules will be complicated since it is not simply related to the number of cycles the instruction uses.

So you’ll have to do it experimentally. Here’s what I’d do.

  1. Remove all compiler optimizations
  2. Do a frequency analysis to find your hot operations and pick out the most used. (I’m assuming we aren’t talking ASM instructions but ‘C’ instructions.)
  3. Write a loop that repeats the instruction, say, 20 times, and have the loop run for several seconds at a minimum
  4. Replace your battery with a power supply.
  5. Use the series resistor to measure power as mentioned in the comment but (of course) scale the voltage appropriately.
  6. Run the looping program and get a statistical sampling of the power.
  7. Do this for all of your hot operations.
  8. Compute power usage for your program
  9. Validate the power usage against real power measurements of the execution of your program
  10. Adjust (i.e. normalize) your computations as appropriate

You’ll also have to take into account the memory hierarchy. Accessing off chip memory takes energy. When operations or data are cached, it’s going to change your energy equation.

I figure this should work but don’t know. Good luck.