proveskit / fprime-proves

Apache License 2.0
2 stars 5 forks source link

RV3028 Real Time Clock Component #16

Open Mikefly123 opened 2 months ago

Mikefly123 commented 2 months ago

Setting Up the Real Time Clock (RTC) Functionality

On the latest edition of the PROVES Kit boards we have added the RV-3028-C7 Real Time Clock (RTC) which is the same one used by the OreSat C3.

We want to be able to do the following sub-tasks with the Real Time Clock:

Design Notes

Possible Arduino Library

The time is a very important thing to have on your satellite! With a real time clock onboard we can schedule actions to have at specific times and stamp and logged telemetry with the time at which it was recorded as well. We eventually want to get to a point where we trust the clock enough to be able to establish in absolute terms what the satellite should be doing at any given time.

An example of this behavior down the line would be the ability to say at the top of every minute the satellite will send a beacon message and 30 seconds into every minute the satellite will start a listen for commands window. Or perhaps we can uplink to the satellite, hey we don't expect you to be in range of any ground stations for the next hour, go to sleep until then!

Example CircuitPython Implementation

At this time the only implemented functionality for the RTC is to set and get the time and date:

    @property
    def time(self):
        try:
            return self.rtc.get_time()
        except Exception as e:
            self.error_print("[ERROR][RTC]" + "".join(traceback.format_exception(e)))

    @time.setter
    def time(self, hours, minutes, seconds):
        if self.hardware["RTC"]:
            try:
                self.rtc.set_time(hours, minutes, seconds)
            except Exception as e:
                self.error_print(
                    "[ERROR][RTC]" + "".join(traceback.format_exception(e))
                )
        else:
            self.error_print("[WARNING] RTC not initialized")

    @property
    def date(self):
        try:
            return self.rtc.get_date()
        except Exception as e:
            self.error_print("[ERROR][RTC]" + "".join(traceback.format_exception(e)))

    @date.setter
    def date(self, year, month, date, weekday):
        if self.hardware["RTC"]:
            try:
                self.rtc.set_date(year, month, date, weekday)
            except Exception as e:
                self.error_print(
                    "[ERROR][RTC]" + "".join(traceback.format_exception(e))
                )
        else:
            self.error_print("[WARNING] RTC not initialized")

Schematic Reference

image The default I2C address for the RTC is 0x52. The RTC_INT line is tied to GPIO27 on the RP2040.

Mikefly123 commented 2 months ago

Rachel has gotten started on an RTC library in the attached repo! @Lex-ari can we check this out and see if it does a thing?

https://github.com/rrakushkin/F-Prime-RV-30-28-C7