Project Quartz

From 7West
Revision as of 14:03, 10 December 2024 by Animationb (talk | contribs) (Created page with "'''Project Quartz''' consists of two major components: # Wristwatch - small, comfortable, no wireless capabilities, and decent battery life # Base - connects to the watch to charge it and sync it's clock with GPS ===Project Metrics=== {| class="wikitable" |- | State Date:|| December 2017 |- | Completion Date:|| January 2021 |- | Cost:|| $1,000,000 |} ==Hardware== ===Base=== The base is made up of two stacked 60x160 mm circuit boards housed in a 3D printed case. The Ba...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Project Quartz consists of two major components:

  1. Wristwatch - small, comfortable, no wireless capabilities, and decent battery life
  2. Base - connects to the watch to charge it and sync it's clock with GPS


Project Metrics

State Date: December 2017
Completion Date: January 2021
Cost: $1,000,000

Hardware

Base

The base is made up of two stacked 60x160 mm circuit boards housed in a 3D printed case. The Base features three buttons and one 7-segment display. Two buttons are for changing the time zone and the third interacts with the syncing process. The display shows relevant information, depending on what is happening.

The Base is rather large probably a bit over-engineered. If I had to do it again, I would have found a way to make it all smaller.

Microcontroller

An ESP32 controls all the Base operations. An ESP32 DevKitC is plugged into female headers on the Base. From there is controls the powering up and running of the GPS Module, the setting of time zones, the 7-segment display, and the time message that is sent to the Watch. The ESP32 is in Deep Sleep most of the time and only wakes up when syncing the Watch.

Originally, I went with the ESP32 because I had never worked with it before and I had the intention of using NTP time over WiFi as a backup to GPS, but that was more work that it was worth. I should have gone with the ATSAMD21G18 or a variant with more pins.

Power

The power system is intricate but robust. The base is charged via a Micro USB port (USB-C is still out of my scope), which charges two 18650 Li-Ion batteries. The batteries are boosted to the necessary 5V for the ESP32 and 7-segment display. Also part of the Base's power system is a second Lithium battery charger for the Watch's battery (to save space on the Watch). The Base draws 6mA when sleeping, giving it a battery life of over 30 days while sleeping.

  • Lithium Chargers - MCP73871 - Great lithium battery charger (lipo and li-ion), I have used it many times and always been happy with it
  • Voltage Booster - TPS61020 -

Miscellaneous

The 7-Segment Display is just a 3 digit display that says gives time sync status and shows the time zone. The GPS Module locks onto GPS satellites and sends an NMEA message to the ESP32, of which the time is parsed.

Models

Base Eagle files (schematics and boards): File:BaseEagle.zip

Base 3D files (.stl): File:BaseSTL.zip

Watch

The Watch's main component is a 28x25 mm L-shaped circuit board that hosts the microcontroller, Real Time Clock (RTC), and the Liquid Crystal Display (LCD). It is contained in a 3D printed case with wrist-straps salvaged from another watch.

Microcontroller

An ATMega328P controls the Watch's functions: reading the time, updating the LCD, and parsing the time message from the Base. The ATMega328P was selected due to its small package (4x4 mm) and low power consumption.

Power

A 60mAh Lithium Polymer battery powers the Watch. The Watch easily lasts longer than a week on a single charge. The battery is charged via a pin when connected to the Base. The charge controller sits on the Base, not the Watch.

Miscellaneous

The LCD is an ERC12864-10 LCD. It is a black and white LCD with a built in backlight. It's resolution is 128x64 pixels. The RTC is an RV-3028, chosen for its extremely low power requirements and small size. It is smaller than a grain of rice!

Models

Watch Eagle files (schematics and boards): File:WatchEagle.zip

Watch 3D files (.stl): File:WatchSTL.zip

Software

GPS and NMEA Sentences

The first step in getting the time is receiving it from the GPS Module. GPS is normally used to calculate one's location on Earth, however, essential to calculating that, the GPS Module needs to know exactly what time it is, which the GPS Satellites help achieve. I simply take this time from the module. The GPS Module outputs National Marine Electronics Association (NMEA) sentences. They are standard across many GPS Modules and each sentence gives slightly different information. Project Quartz uses the GPRMC sentence, because it has the time, along with other basic GPS info (latitude, longitude, altitude, other-udes). Parsing of the NMEA sentence is done by a library I made, included at the end of this section. From the parsed time, the Base converts it into the bytes to be written to the Watch's RTC. Part of the conversion process relies on Andreas Spiess' NTP Library, not for NTP, but for its Unix-to-Normal time conversion and calculation of Leap Years and Day Light Saving Time. I did make some small changes to the library to make it not use WiFi.

The only flaw in this process, is that while the Base is sleeping, the GPS Module is turned off (it draws 200mA). So when the Watch is placed on the Base, the ESP32 wakes up the GPS Module and waits for a lock on the GPS's location and time, which can take up to 5 minutes. I've also found a weird bug where the time generated from my recently locked GPS Module is exactly 3 seconds fast. However, after letting the GPS stay locked for about 20 minutes, the time becomes correct. I'm not sure what the source of this bug is, but I suspect the GPS Module is getting old, because it didn't used to do this.

File:NMEAsentenceParser.zip

ERC LCD Driver

Writing to displays has always been a fun challenge with the ATMega328P. Due to it's 2KB of SRAM, it cannot hold a buffer for all 128x64 pixels. Therefore, on each screen update, the microcontroller must calculate what pixels are black or white based on the current time. The LCD is updated in 8-bit tall pages that run the length of the display; therefore, most updates do not include the date. Stored in Program Memory (so it takes up Flash, not SRAM) is a table of the bits needed for numbers 0-9 for their large and small forms. There is also a table for the few letters used. When updating the display, the code uses the current time and the location in the page to determine what bits to pull from the tables and push to the LCD. Lastly, there are two types of display updates: one that only updates the time, which occurs every second, and the other which updates the time and date, which occurs every hour.

This method saves SRAM, but does cost time in the form of CPU cycles. At the end of the day, the shorter screen update only takes a dozen milliseconds and is barely noticeable. However, designing this code did take a lot more effort. I've found that is always the trade off with microcontrollers, you can either have speed or RAM. If you need more speed you need more RAM, if you don't have enough RAM your speed takes a hit.

Watch-to-Base Interface

The interface between the Watch and Base is a complicated and time sensitive handshake, because it sets the time on the Watch. There are 5 pins that are used for this interface, wired differently on each component (Watch vs Base):

  • PLACE_W
    • Watch - This pin is tied to Ground
    • Base - This pin is pulled up, but when it is set Low by plugging in the Watch, the ESP32 wakes up and begins the syncing process
  • INT1
    • Watch - This pin is pulled down to Ground, but when set High the Watch stops everything and waits for the time message
    • Base - This pin is controlled by the ESP32 and let's it tell the Watch to get ready for the time message
  • RX/TX
    • Watch - Using UART, the ATMega328P receives the time message and sets the RTC
    • Base - Sends the time message via UART.
  • The other two pins are used for GND and VBAT to charge the Watch's battery

The process is mostly described by the pins above, but here it is more clearly. The Watch is placed on the Base, pulling the Base's PLACE_W pin Low. This wakes up the ESP32, which turns on the GPS Module (if it is asleep) and begins requesting the time. Once the GPS Module gives the time to the ESP32, it tells the Watch to prepare for the time message and converts the GPS time into a the proper time message. Before sending the time, the ESP32 inserts a delay and adds 2 seconds to the GPS time. This is done to compensate for the time it takes to receive and process the GPS time. Finally the ESP32 sends the time message to the ATMega328P.

The time message is exactly the bytes that need to be written to the RTC on the Watch. The time message also includes a multi-function byte at the end. This last byte will tell the Watch how many days until the next "Day Light Savings Event" and on that day, depending on what month it is, the Watch automatically adjusts the hour. The last byte's other function occurs if the time syncing process is cancelled before GPS Module acquires the time. In this case, the Base only sends the time change if the Watch, Base, and user have changed time zones.

The time message is pretty cool and compact, however by far the hardest part of all of this was working with the GPS Module. There seemed to me a dozen edge cases where the GPS would get a lock but not the time, or it would have the time but send it a half a second off from what was expected. The code for the Base has a lot of waiting for the GPS to "get its crap together" and produce a reliable NMEA sentence. That is why 2 seconds are added to the time, as mentioned above.

The Code

Base Code: File:BaseCode.zip

Watch Code: File:WatchCode.zip