I want to build a very low power temperature/humidity sensor. I was inspired by Nick Gammons forum (thanks so much Nick for the enormous help you provide there!) and built a standalone atmega328, added a lillypad bootloader and started experimenting. I did several sketches I found at Nick’s forum and my results pretty well apporached his. One of the things I could not figure out was how to measure processor frequencies. I found in “Arduino Internals” from Dale Wheat a way to lower the processor frequency in software, like:
const uint8_t prescale_factor = 2; // Lilllypad has an internal clock of 8Mhz const uint8_t prescale_multiplier = (1 << prescale_factor); noInterrupts (); CLKPR = (1 << CLKPCE); CLKPR = prescale_factor; // set it back a factor 4: 2 Mhz interrupts ();
It seems to work, as delays last longer (so I divide the delay time by the prescale_multiplier) and I have to divide the baud rate in the serial monitor by the prescale_multiplier as well. I have several issues with this approach:
- How do I know what the “real” frequency is of the CPU? Using F_CPU does not help as it only returns the value in boards.txt.
- When I set a baud rate of 9600, my serial monitor should be set to 2400 (in the example above). I thought to be clever and to multiply the baud rate by the prescale_multiplier, yielding 38400 but that results in gibberish. Highger baud rates seem hardly possible when changing the processor frequency
- I also read that lower batter voltages yield lower frequencies. Does this mean that I should deduce the current prescale_factor and _multiplier and adjust all my timing settings or is this handled automatically at startup?
Thanks in advance for any answer!