Erriez / ErriezDS3231

DS3213 high precision RTC (Real Time Clock) library for Arduino
https://github.com/Erriez/ErriezArduinoLibrariesAndSketches
MIT License
22 stars 7 forks source link

Get milliseconds #1

Closed pyzimmer closed 2 years ago

pyzimmer commented 5 years ago

Hello, You make a good job ! Is it possible to get milliseconds from DS3231 ? thanks

Erriez commented 5 years ago

Thanks for contacting me.

The resolution of the DS3231 time registers is up to 1 second and does not support reading the time in milliseconds.

As workaround, you can configure the SQW (Square Wave Out) pin to generate a 1024Hz, 4096Hz or 8192Hz clock with function setSquareWave(SquareWaveXXXXHz). Then you can count the pulses by a microcontroller to measure times in milliseconds.

pyzimmer commented 5 years ago

Thanks for reply ! I know it, but I wish that this function is included in the library.

Erriez commented 5 years ago

Capturing the SQW pin by a microcontroller should be handled by the application, because the DS3213 library has no dependencies on the microcontroller type.

Are you using an AVR / ATMega328 microcontroller (Arduino UNO/Mini etc) for example? This controller supports a 16-bit Input Capture Register on timer 1 which can be used to count SQW pulses from the RTC. A new function can be implemented by the application to convert the number of pulses to milliseconds.