Counting pulses, while the MM sleeps....


Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3379
Posted: 01:34am 01 Oct 2025      

Jim makes an important point, It can take up to 1mS to respond to the WAKEUP Pin.

Synchronizing by timing alone has limitations as the main clock is stopped and the Wake Timer accuracy is ±20%. For a 5S interval, even if it starts perfectly synchronized, it would have to wake at least 1S early to be certain of catching a set of pulses, and stay awake till they arrived. Up to 1S if it just missed a set.

Both of these accuracy problems could be reduced by first measuring the actual Wake Timer and WAKEUP Pin response time for that specific chip and saving with VAR SAVE or putting them in the code. The times could possibly be affected by temperature and supply voltage so that will need more testing.

An external timer may be more accurate but also uses some power.
  Quote  CPU SLEEP or CPU SLEEP seconds [, abortpin]
Put the CPU to sleep. In this mode the running program will be halted and the current drain reduced to about 40 µA.
In the first form the WAKEUP pin (see the pinout tables at the start of this manual) will be automatically configured as a digital input and any change in its state (ie, from high to low or low to high) will wakeup the CPU. The time required to "wake up" in this mode is less than 1 ms.
The IR command shares the WAKEUP pin and if it is running the CPU will be awakened by the remote key press and MMBasic will immediately decode the signal and execute the IR interrupt.
In the second form (CPU SLEEP seconds) the command will put the CPU to sleep for the specified number of 'seconds' (accuracy is ±20%). The TIMER function and the internal clock/calendar will be updated when the sleep finishes.
The timed sleep can be terminated early if 'abortpin' is specified. This can be any I/O pin and any change in its state (ie, from high to low or low to high) will abort the sleep. It can take up to a second for the abort signal to be recognised so the change of state must be maintained for at least this time.

Edited 2025-10-01 11:39 by phil99