Skip to main content
Arduino

Return to Answer

+ First thing: do no more work than needed.
Source Link
Edgar Bonet
  • 45.1k
  • 4
  • 42
  • 81

It depends on what your processor is doing while it has no real work to do:

  • If you put it to sleep, then yes, using floats will keep the CPU awake for a longer time and burn more energy.
  • If you are instead doing busy-waits (e.g. with delay()) it should make no difference, since the CPU is busy 100% of the time anyway.

Update: According to your update, it seems your program never sleeps. Then I would expect no substantial difference in power consumption between using floats or ints. As Majenko said, there can theoretically be some small difference depending on the number of transistor transitions involved in each instruction (and, I would add, the capacitive loading of the involved transistors), but I do not expect this to be very significant.

If you are really concerned about the consumption of your Arduino, I would suggest you use it only for prototyping, then move your code to a bare ATmega (or maybe even an ATtiny) chip. Also, add at least one call to sleep_mode() inside your main loop. Each such call will put your CPU to sleep until the next timer interrupt, which typically happens every 1024 μs. There is a lot more to say about power savings, see for example this excellent writeup by Nick Gammon.

Edit: When trying to minimize power consumption, one of the very first things to do is figure out how much work has to be done, and make sure your program never does more work than required. In your case, this means you have to know how often your main loop should execute, and prevent it from running more often than needed. For example:

#include <avr/sleep.h>
const unsigned long loop_period = 5; // run the loop every 5 ms.
void loop() {
 /* Sleep while waiting for the next time slot. */
 static unsigned long last_time;
 while (millis() - last_time < loop_period)
 sleep_mode();
 last_time += loop_period;
 /* Actual work goes here... */
}

If the actual loop work takes significantly less time than the loop period, your CPU will sleep most of the time, leading to significant power savings. Then you can start digging into more advanced power-saving techniques like those mentioned in the article linked above.

It depends on what your processor is doing while it has no real work to do:

  • If you put it to sleep, then yes, using floats will keep the CPU awake for a longer time and burn more energy.
  • If you are instead doing busy-waits (e.g. with delay()) it should make no difference, since the CPU is busy 100% of the time anyway.

Update: According to your update, it seems your program never sleeps. Then I would expect no substantial difference in power consumption between using floats or ints. As Majenko said, there can theoretically be some small difference depending on the number of transistor transitions involved in each instruction (and, I would add, the capacitive loading of the involved transistors), but I do not expect this to be very significant.

If you are really concerned about the consumption of your Arduino, I would suggest you use it only for prototyping, then move your code to a bare ATmega (or maybe even an ATtiny) chip. Also, add at least one call to sleep_mode() inside your main loop. Each such call will put your CPU to sleep until the next timer interrupt, which typically happens every 1024 μs. There is a lot more to say about power savings, see for example this excellent writeup by Nick Gammon.

It depends on what your processor is doing while it has no real work to do:

  • If you put it to sleep, then yes, using floats will keep the CPU awake for a longer time and burn more energy.
  • If you are instead doing busy-waits (e.g. with delay()) it should make no difference, since the CPU is busy 100% of the time anyway.

Update: According to your update, it seems your program never sleeps. Then I would expect no substantial difference in power consumption between using floats or ints. As Majenko said, there can theoretically be some small difference depending on the number of transistor transitions involved in each instruction (and, I would add, the capacitive loading of the involved transistors), but I do not expect this to be very significant.

If you are really concerned about the consumption of your Arduino, I would suggest you use it only for prototyping, then move your code to a bare ATmega (or maybe even an ATtiny) chip. Also, add at least one call to sleep_mode() inside your main loop. Each such call will put your CPU to sleep until the next timer interrupt, which typically happens every 1024 μs. There is a lot more to say about power savings, see for example this excellent writeup by Nick Gammon.

Edit: When trying to minimize power consumption, one of the very first things to do is figure out how much work has to be done, and make sure your program never does more work than required. In your case, this means you have to know how often your main loop should execute, and prevent it from running more often than needed. For example:

#include <avr/sleep.h>
const unsigned long loop_period = 5; // run the loop every 5 ms.
void loop() {
 /* Sleep while waiting for the next time slot. */
 static unsigned long last_time;
 while (millis() - last_time < loop_period)
 sleep_mode();
 last_time += loop_period;
 /* Actual work goes here... */
}

If the actual loop work takes significantly less time than the loop period, your CPU will sleep most of the time, leading to significant power savings. Then you can start digging into more advanced power-saving techniques like those mentioned in the article linked above.

address updated question
Source Link
Edgar Bonet
  • 45.1k
  • 4
  • 42
  • 81

It depends on what your processor is doing while it has no real work to do:

  • If you put it to sleep, then yes, using floats will keep the CPU awake for a longer time and burn more energy.
  • If you are instead doing busy-waits (e.g. with delay()) it should make no difference, since the CPU is busy 100% of the time anyway.

Update: According to your update, it seems your program never sleeps. Then I would expect no substantial difference in power consumption between using floats or ints. As Majenko said, there can theoretically be some small difference depending on the number of transistor transitions involved in each instruction (and, I would add, the capacitive loading of the involved transistors), but I do not expect this to be very significant.

If you are really concerned about the consumption of your Arduino, I would suggest you use it only for prototyping, then move your code to a bare ATmega (or maybe even an ATtiny) chip. Also, add at least one call to sleep_mode() inside your main loop. Each such call will put your CPU to sleep until the next timer interrupt, which typically happens every 1024 μs. There is a lot more to say about power savings, see for example this excellent writeup by Nick Gammon .

It depends on what your processor is doing while it has no real work to do:

  • If you put it to sleep, then yes, using floats will keep the CPU awake for a longer time and burn more energy.
  • If you are instead doing busy-waits (e.g. with delay()) it should make no difference, since the CPU is busy 100% of the time anyway.

It depends on what your processor is doing while it has no real work to do:

  • If you put it to sleep, then yes, using floats will keep the CPU awake for a longer time and burn more energy.
  • If you are instead doing busy-waits (e.g. with delay()) it should make no difference, since the CPU is busy 100% of the time anyway.

Update: According to your update, it seems your program never sleeps. Then I would expect no substantial difference in power consumption between using floats or ints. As Majenko said, there can theoretically be some small difference depending on the number of transistor transitions involved in each instruction (and, I would add, the capacitive loading of the involved transistors), but I do not expect this to be very significant.

If you are really concerned about the consumption of your Arduino, I would suggest you use it only for prototyping, then move your code to a bare ATmega (or maybe even an ATtiny) chip. Also, add at least one call to sleep_mode() inside your main loop. Each such call will put your CPU to sleep until the next timer interrupt, which typically happens every 1024 μs. There is a lot more to say about power savings, see for example this excellent writeup by Nick Gammon .

Source Link
Edgar Bonet
  • 45.1k
  • 4
  • 42
  • 81

It depends on what your processor is doing while it has no real work to do:

  • If you put it to sleep, then yes, using floats will keep the CPU awake for a longer time and burn more energy.
  • If you are instead doing busy-waits (e.g. with delay()) it should make no difference, since the CPU is busy 100% of the time anyway.

AltStyle によって変換されたページ (->オリジナル) /