Low Power Timer

This section refers to the following sample application(s):

  • 02-lptimer

This application is new to OCSDK 1.2.0

The 

LTC5800

 features a 16-bit low-power timer input, the DN_LPTIMER_DEV_ID device (DP2/GPIO 21,  LTC5800 pin 34).  The timer can be used in two ways:

  • pulse counter - the source signal is used as the clock, and can be up to ~1 MHz.  A one-shot mode is supported.
  • pulse width measurement - the 32 KHz clock is uses as the reference, so the resolution is ~30 µs.  

Your application can register an event handler to receive notifications when a gating event is captured, the compare value is reached, or when the timer overflows.

The 02-lptimer Sample Application

The application provides 7 CLI functions (available by typing help) for configuring the lptimer:

  • open <mode> <events> <single> <pol> <cmp> <clrCmp> <capGate> <clrGate> - opens the lptimer device. The device must be opened before enabling/disabling  Arguments are:
    • mode - one of the modes external clock, count single edge, count both edges, or count while polarity (i.e. pulse width) defined in dn_lptimer.h. External mode should be used for high frequency (> 16 KHz) clocks.
    • events - a bitmask of which events will generate notifications (compare, overflow, capture)
    • single - use as a one-shot timer (1) or normal recurring timer (0)
    • pol - set the polarity, i.e. clock on rising (1) edge / high level, or falling (0) edges / low level, depending on mode
    • cmp - compare value. Note that in the 1.4.1 stack library, the value passed in the open function is not used and must be set separately
    • clrCmp - if 1, clears the lptimer value when a compare value is reached, i.e. count up to the compare value
    • capGate - if 1, capture the counter when the corresponding gate event occurs
    • clrGate - if 1, clears the counter when the corresponding gate event occurs
  • close - closes the lptimer device. Closing and re-opening the lptimer device is required for configuration changes other than the compare value to take effect.
  • enable - enables the lptimer input
  • disable - disables the lptimer input
  • set - sets the compare value. A notification will be generated if the corresponding event is enabled. Note that while the registers are 32-bits wide, the lptimer is a 16-bit timer. In revisions of the stack library >= 1.4.2, setting compare > 65535 will result in an error.
  • getcap - gets the value of the capture register when a gate event occurs (for pulse width timing when capGate=1).

  • getcount - gets the current value of the lptimer counter register

In the case of a failure, each command will print the error code, otherwise nothing is returned.

Low Power Timer app, ver 1.2.0.1
SmartMeshIP stack, ver 1.4.1.6

> open 
Usage: open <mode> <events> <single> <pol> <cmp> <clrCmp> <capGate> <clrGate>
> open 0 0x7 0 0 12345 1 0 0

> set 12345
Compare: 12345
> enable

> disable

> close

Once configured, the application will print notifications for each configured event, e.g. 

COMP Event 1
CTR = 12409
COMP Event 3
CTR = 381

Important points:

  • Opening the lptimer device more than once will generate an error
  • Closing the lptimer device more than once will generate an error

Implementation Details

The 02-lptimer sample application uses the Helper Modules to initialize the CLI Module and for interaction with the local interface. It passes JOIN_NO in the fJoin flag when initializing the local module in the loc_task_init() to prevent the local module from attempting to join. It has one lptimerTask application task that installs event handlers for the various possible capture/compare events, and prints them on the CLI continuously as they occur.  The application relies on CLI commands to otherwise drive the application to demonstrate lptimer features.