Go Down

Topic: Programming optimization for electrical efficiency (Read 178 times) previous topic - next topic


I am looking for recommendations on how to write a sketch. The general function of the sketch will be for the uC to wake up, check sensor, make a decision to flip a switch, go back to sleep. Since the watchdog timer is limited to 8 seconds but I only need to check the sensor every 2 hours, I want it to wake up, check a counter and increment until 900 is reached (8 seconds times 900 is 2 hours). Drift due to inaccurate clocks is not critical.
I also want it to run on an ATTiny13a. I haven't written it yet but I may run into memory limits of sketch size.
So here's the strategy question. Should I write until the Mega328p does what I need it to do and then optimize until the Attiny can handle it if necessary? I also want it to run as quickly as possible. It would be ideal to have it run on battery power for extended (months) periods of time. So not only optimize for sketch size but also clock cycles per loop. Or should I write with port manipulation (that I am still learning) from the very beginning?


Very vague description of you project ;-)
I would develop the sketch on a "normal" UNO while trying to reduce code size and RAM usage. It is much easier to debug if you have a serial connection.
I don't think it makes a difference if you optimize your code for speed. Running 1 or 100 milliseconds once an hour is irrelevant to power consumption. Your batteries will self-discharge much earlier. See also Nick Gammons excellent power page

Go Up