How can I change The timers to work correctly when The processor clock is set to 128K instead of 16 M? At present, using the delay function does not work correctly, The delay is far too long.
Add a new entry in boards.txt with the new value for
f_cpu. Note that the timing functions will become far less precise at so low a speed.
A commonly-used approach is writing an intermediate or surrogate delay function that your application calls. That delay routine needs a way to know if the clock is slow (128 KHz) or fast (16 MHz). If the clock is slow, divide the delay counts by 125 (the ratio of 16 MHz and 128 KHz) before calling the built-in
delay(). [Or, adjust all your application calls to use numbers scaled down by a factor of 125, and in the surrogate scale them back up if the clock is fast. This may give you better control than just rounding, truncating, or truncating up will do.]
For example, if you call the intermediate routine
vDelay() and change your app calls from a
delay(x) form to a
vDelay(x) form, in the function
vDelay(unsigned long ms) you will say something like
if (ClockIsSlow) delay((ms+124)/125); else delay(ms);