Delving into and supporting Timing with Clock Rates (module/library)

Engle

Member
The attached module was originally used for a game where the clock rate hadn't been finalised and the audio interface required consistent timings to be near minimum levels. Modifying more than a few pause commands by hand is unwieldy and error prone, particularly because arithmetic like "Pause 1 * ClockMultiplier" is not allowed with the pause commands. Ultimately, a short list of logarithmic timings was easy to remember and they provided all the accuracy needed on most projects. It became a bit of fun to delve deeper into PICAXE timing and record some timing on an oscilloscope and this module emerged. This module's list of pause statements doesn't consume any extra program memory, and the module has these features:

  • A list of pause statements that provide timing delays regardless of the PICAXE clock rate: Pause1mS, Pause3mS, Pause10mS, Pause30mS, Pause100mS, Pause300mS, Pause1S, Pause3S and Pause10S.
  • The macro ``Pause_mSec(t)`` allows you to specify specific pause times regardless PICAXE clock rate.
  • The PICAXE clock rate is set using a kHz value: 31, 250, 500, 1000, 2000, 4000, 8000, 16000, 32000, or 64000 (Dependent on chip).
  • The debug terminal baud rate is automatically set to the appropriate value for the PICAXE clock rate.
  • For X2 chips, the "timer" variable is set to increment at a configured rate if ``TIMER_IN_HUNDRETHS`` is defined in your program and given a value. This proved useful to measure lap time in a game.
  • A reference list of actual pause timings is shown in the Programming Guide notes below, these are valid if you use this module, or just use regular pause commands and do integer math based on the ratio of actual clock rate to default clock. From this some subjective recommendations are made for minimum clock rates with certain durations. Just don't expect a 1mS delay to be added when you use ``pause 1`` :)

The attached file should be renamed to Timing.basinc with the basinc extension. There’s a lot of help information in the file and you can also download the master file with the basinc extension from GitHub here .
 
Top