mikaelpatel / Cosa

An Object-Oriented Platform for Arduino/AVR
https://mikaelpatel.github.io/Cosa/
GNU Lesser General Public License v2.1
338 stars 76 forks source link

Support Frequency Scaling #435

Closed mikaelpatel closed 8 years ago

mikaelpatel commented 8 years ago

Allow prescaling of the system clock (1-8 MHz). Adjust all hardware module device drivers (e.g. SPI, TWI, UART) so that they use the correct system clock. F_CPU from compile is not the correct processor clock. It has to be scaled accordingly.

First level is to allow setting at setup; run application at slower frequency. Next level is to allow more advanced dynamic setting of the system clock prescale; application may alter processor frequency depending on needs.

mikaelpatel commented 8 years ago

After a number of measurements the conclusion is; It is better to run at high speed and go to low power sleep mode (idle or standby) instead of running at lower speed. Support for voltage scaling in the processor core would have been more useful.

The software implications of frequency scaling is also large. F_CPU based settings have to become run-time variables and compiler optimizations are not possible (e.g. divide by 16 can be reduced to shift right 4 steps but divide by a variable cannot be automatically reduced).