2

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.

  • Your solution that makes perfect sense, however, it would be a mammoth task going updating the delay functions used in third-party libraries. – Mo Valli Oct 17 '15 at 21:51
  • Surely, there must be some way to scale down the clock counters? – Mo Valli Oct 17 '15 at 21:52
2

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.

  • I have tried changing bored.TXT, however, this seems to make no difference. – Mo Valli Oct 17 '15 at 22:09
  • You have to select the new board that you have created in the Arduino IDE. – sa_leinad Oct 6 '16 at 0:55
1

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.