Skip to content

DS3231: Add calibration, temperature, and force_conversion #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 20, 2020

Conversation

jepler
Copy link
Contributor

@jepler jepler commented Jul 16, 2020

This device has a temperature sensor with 0.25°C precision, and an "aging offset" which can be used to calibrate the crystal
frequency for increased timekeeping accuracy.

Expose these as properties.

This requires adafruit/Adafruit_CircuitPython_Register#39 as the temperature and calibration registers hold signed values.

With these changes, I was able to use a precision frequency meter to "tune" the RTC so that it would have less than .01 seconds per day of error at 27°C, by assigning the best value to the calibration register.

jepler added 2 commits July 16, 2020 08:27
This device has a temperature sensor with 0.25C precision,
and an "aging offset" which can be used to calibrate the crystal
frequency for increased timekeeping accuracy.

Expose these as properties.

This requires
adafruit/Adafruit_CircuitPython_Register#39 as the
temperature and calibration registers hold signed values.
@jepler jepler marked this pull request as draft July 16, 2020 18:28
return self._temperature / 4

def force_conversion(self):
"""Forces a conversion and returns the new temperature"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conversion seems a bit vague. Is there a more detailed way of describing it? I expected it to be force_temperature_conversion but then calibration calls it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll rework this a bit and rename it. (the checking for conversion-completed is wrong too) It is forcing a temperature conversion, which is necessary for the new oscillator calibration to become effective.

Datasheet says:

Bit 5: Convert Temperature (CONV).
Setting this bit to 1 forces the temperature sensor to convert the temperature into digital code and execute the TCXO algorithm to update the capacitance array to the oscillator.
This can only happen when a conversion is not already in progress. The user should check the status bit BSY before forcing the controller to start a new TCXO execution.
A user-initiated temperature conversion does not affect the internal 64-second update cycle.
A user-initiated temperature conversion does not affect the BSY bit for approximately 2ms.
The CONV bit remains at a 1 from the time it is written until the conversion is finished, at which time both CONV and BSY go to 0. The CONV bit should be used when monitoring the status of a user-initiated conversion

and explains why triggering a conversion after setting the calibration value ("aging offset") is useful:

The offset register is added to the capacitance array during a normal temperature conversion, if the temperature changes from the previous conversion, or during a manual user conversion (setting the CONV bit). To see the effects of the aging register on the 32kHz output frequency immediately, a manual conversion should be started after each aging register change.

`

@jepler jepler marked this pull request as ready for review July 19, 2020 16:25
@jepler jepler requested a review from tannewt July 19, 2020 16:25
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

@tannewt tannewt merged commit 5d81a9e into adafruit:master Jul 20, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jul 22, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_DS3231 to 2.4.0 from 2.3.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_DS3231#27 from jepler/calibration-and-temperature

Updating https://github.com/adafruit/Adafruit_CircuitPython_PCF8523 to 1.5.0 from 1.4.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_PCF8523#19 from jepler/calibration-registers

Updating https://github.com/adafruit/Adafruit_CircuitPython_PM25 to 1.0.2 from 1.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_PM25#3 from dglaude/patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_PyPortal to 3.3.0 from 3.2.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_PyPortal#82 from fede2cr/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 3.2.2 from 3.2.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#44 from 2bndy5/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_ProgressBar to 1.3.0 from 1.2.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_ProgressBar#8 from FoamyGuy/performance_boost

Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.5.0 from 1.4.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#29 from brentru/update-cellular-3g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants