npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@johntalton/pcf8523

v2.0.1

Published

Like many other chips, the PCF8523 packs a range of addition features and flags.

Downloads

87

Readme

pcf8523 (Real Time Clock)

Like many other chips, the PCF8523 packs a range of addition features and flags.

Usage

Basic mode and usage is around setting and retrieving the clocks time value. This is of extended value when used with the chips Battery circuitry (which need to be enabled to work in "off line" mode).

Additionally, the chip provides several timers, which can, when enabled, feed the physical interrupt pin(s). With the addition of several variation and periods, many unique combination of interrupt events can be driven from this single chip.

Examples

Basic Time

Using the legacy Date object, the time can be set.

Note however, without enabling the proper Power Mode (aka, switch to battery when off line) this will only keep time while on main power.

It is also "recommended" to start/stop the oscillator when changing time (as well as most other time related parameters of the chip).

import { I2CAddressedBus, I2CBus } from '@johntalton/and-other-delights'
import {
  PCF8523,
  DEFAULT_PCF8523_ADDRESS,
  BASE_CENTURY_Y2K
} from '@johntalton/pcf8523'

const bus:I2CBus = /* ... */
const abus = new I2CAddressedBus(bus, DEFAULT_PCF8523_ADDRESS)
const device = PCF8523.from(abus)

/*
... stop oscillator and set power mode
*/

const now = new Date(Date.now())

await device.setTime(
  seconds: now.getUTCSeconds(),
  minutes: now.getUTCMinutes(),
  hours: now.getUTCHours(),

  day: now.getUTCDate(),
  month: now.getUTCMonth() + 1,
  year: now.getUTCFullYear() - BASE_CENTURY_Y2K,

  ampm_mode: false,
  century: BASE_CENTURY_Y2K
)

/*
... start oscillator
*/

Update Control 1 Register (Stop Oscillator)

const device = PCF8523.from(/* ... see basic example */)

/* note:
  these two calls are likely not transaction on the underlying
  bus implementation this can be of particular interest for Worker threads
  and when using async with multiple devices, or clients controlling
  the same device (even when a single event-loop)

  however, this works for 99% of people 🤷🏻‍♂️
  */
const current = await device.getControl1()
await device.setControl1({
  ...current,
  stop: true
})

Setting Power Mode

const device = PCF8523.from(/* ... see basic example */)

await device.setControl3({
  // enable power switchover mode (this enable fallback to battery)
  // use standard mode
  pmSwitchoverEnabled: true,
  pmDirectSwitchingEnabled: false,

  // enable detection of low battery events (see interrupt enable bellow trigger)
  pmBatteryLowDetectionEnabled: true,

  clearBatterSwitchoverFlag: true, // clear any existing switchover events

  // enable both battery events to trigger an interrupt
  batterySwitchoverInterruptEnabled: true,
  batteryLowInterruptEnabled: true,
})

Interrupts

As per the datasheet this is the list of all things that can be enabled and generate an interrupt(1):

  • Second timer
  • Timer A
  • Timer B
  • Alarm
  • Battery switch-over
  • Battery low detection
  • Clock offset correction pulse

The second interrupt (for chips that have that pin) can be generated only from Timer B