From 656d8babe607f22b264073a8e73d93e6782609c1 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 15 Jul 2020 21:33:06 -0500 Subject: [PATCH 1/6] PCF8523: Add additional registers This adds the following registers: * cap_sel, True to add additional capacitance to clock pins * calibration_mode, select one of two different clock calibration methods * calibration, set the clock calibration (offset) value in ~4ppm steps By accurately measuring the crystal frequency, these values can be selected to improve the calibration of the RTC from "minutes per month" to "seconds per month". --- adafruit_pcf8523.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/adafruit_pcf8523.py b/adafruit_pcf8523.py index a885862..cf255a2 100644 --- a/adafruit_pcf8523.py +++ b/adafruit_pcf8523.py @@ -101,6 +101,15 @@ class PCF8523: battery_low = i2c_bit.ROBit(0x02, 2) """True if the battery is low and should be replaced.""" + cap_sel = i2c_bit.RWBit(0x00, 7) + """True for high oscillator capacitance (12.5pF), otherwise lower (7pF)""" + + calibration_mode = i2c_bit.RWBit(0x0e, 7) + """False to offset every 2 hours (1 LSB = 4.340ppm); True to offset every minute (1 LSB = 4.069ppm). The factory default, False, consumes less power""" + + calibration = i2c_bits.RWBits(7, 0xe, 0, signed=True) + """Calibration offset to apply, from -64 to +63. See the PCF8523 datasheet figure 18 for the offset calibration calculation workflow.""" + def __init__(self, i2c_bus): self.i2c_device = I2CDevice(i2c_bus, 0x68) From 539ad11ecd3317ea2668984fbba0b7149360eb5f Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 16 Jul 2020 07:01:06 -0500 Subject: [PATCH 2/6] run black --- adafruit_pcf8523.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_pcf8523.py b/adafruit_pcf8523.py index cf255a2..87db2e7 100644 --- a/adafruit_pcf8523.py +++ b/adafruit_pcf8523.py @@ -104,10 +104,10 @@ class PCF8523: cap_sel = i2c_bit.RWBit(0x00, 7) """True for high oscillator capacitance (12.5pF), otherwise lower (7pF)""" - calibration_mode = i2c_bit.RWBit(0x0e, 7) + calibration_mode = i2c_bit.RWBit(0x0E, 7) """False to offset every 2 hours (1 LSB = 4.340ppm); True to offset every minute (1 LSB = 4.069ppm). The factory default, False, consumes less power""" - calibration = i2c_bits.RWBits(7, 0xe, 0, signed=True) + calibration = i2c_bits.RWBits(7, 0xE, 0, signed=True) """Calibration offset to apply, from -64 to +63. See the PCF8523 datasheet figure 18 for the offset calibration calculation workflow.""" def __init__(self, i2c_bus): From 560cb829fd07e1a8c1c12ff617cae5da48fb65a5 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 16 Jul 2020 13:25:53 -0500 Subject: [PATCH 3/6] pylint --- adafruit_pcf8523.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_pcf8523.py b/adafruit_pcf8523.py index 87db2e7..698375a 100644 --- a/adafruit_pcf8523.py +++ b/adafruit_pcf8523.py @@ -105,10 +105,12 @@ class PCF8523: """True for high oscillator capacitance (12.5pF), otherwise lower (7pF)""" calibration_mode = i2c_bit.RWBit(0x0E, 7) - """False to offset every 2 hours (1 LSB = 4.340ppm); True to offset every minute (1 LSB = 4.069ppm). The factory default, False, consumes less power""" + """False to offset every 2 hours (1 LSB = 4.340ppm); True to offset every + minute (1 LSB = 4.069ppm). The default, False, consumes less power""" calibration = i2c_bits.RWBits(7, 0xE, 0, signed=True) - """Calibration offset to apply, from -64 to +63. See the PCF8523 datasheet figure 18 for the offset calibration calculation workflow.""" + """Calibration offset to apply, from -64 to +63. See the PCF8523 datasheet + figure 18 for the offset calibration calculation workflow.""" def __init__(self, i2c_bus): self.i2c_device = I2CDevice(i2c_bus, 0x68) From a9acb63b90ce08f2b600f3cd3150ad43ff30b415 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 19 Jul 2020 11:25:48 -0500 Subject: [PATCH 4/6] Update adafruit_pcf8523.py Co-authored-by: Scott Shawcroft --- adafruit_pcf8523.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pcf8523.py b/adafruit_pcf8523.py index 698375a..23037c4 100644 --- a/adafruit_pcf8523.py +++ b/adafruit_pcf8523.py @@ -101,7 +101,7 @@ class PCF8523: battery_low = i2c_bit.ROBit(0x02, 2) """True if the battery is low and should be replaced.""" - cap_sel = i2c_bit.RWBit(0x00, 7) + high_capacitance = i2c_bit.RWBit(0x00, 7) """True for high oscillator capacitance (12.5pF), otherwise lower (7pF)""" calibration_mode = i2c_bit.RWBit(0x0E, 7) From ccfbf8c23e5d06253d8cbd4a90f079a531112f37 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 19 Jul 2020 11:41:05 -0500 Subject: [PATCH 5/6] improvements based on review --- adafruit_pcf8523.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_pcf8523.py b/adafruit_pcf8523.py index 23037c4..cff69ea 100644 --- a/adafruit_pcf8523.py +++ b/adafruit_pcf8523.py @@ -104,9 +104,10 @@ class PCF8523: high_capacitance = i2c_bit.RWBit(0x00, 7) """True for high oscillator capacitance (12.5pF), otherwise lower (7pF)""" - calibration_mode = i2c_bit.RWBit(0x0E, 7) - """False to offset every 2 hours (1 LSB = 4.340ppm); True to offset every - minute (1 LSB = 4.069ppm). The default, False, consumes less power""" + calibration_schedule_every_minute = i2c_bit.RWBit(0x0E, 7) + """False to apply the calibration offset every 2 hours (1 LSB = 4.340ppm); + True to offset every minute (1 LSB = 4.069ppm). The default, False, + consumes less power. See datasheet figures 28-31 for details.""" calibration = i2c_bits.RWBits(7, 0xE, 0, signed=True) """Calibration offset to apply, from -64 to +63. See the PCF8523 datasheet From 31e66483d78463efac2ec7c12d746dd216d7c1e5 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 19 Jul 2020 11:42:50 -0500 Subject: [PATCH 6/6] shorten property name per pylint --- adafruit_pcf8523.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pcf8523.py b/adafruit_pcf8523.py index cff69ea..0329b49 100644 --- a/adafruit_pcf8523.py +++ b/adafruit_pcf8523.py @@ -104,7 +104,7 @@ class PCF8523: high_capacitance = i2c_bit.RWBit(0x00, 7) """True for high oscillator capacitance (12.5pF), otherwise lower (7pF)""" - calibration_schedule_every_minute = i2c_bit.RWBit(0x0E, 7) + calibration_schedule_per_minute = i2c_bit.RWBit(0x0E, 7) """False to apply the calibration offset every 2 hours (1 LSB = 4.340ppm); True to offset every minute (1 LSB = 4.069ppm). The default, False, consumes less power. See datasheet figures 28-31 for details."""