Close

RetroChallenge 2023/10 Log Entry #5 - DS3231 for Microtronic

A project log for PicoRAM 2090

A Raspberry Pi Pico (RP2040)-based 2114 SRAM Emulator & Multi-Expansion for the Microtronic Computer System * RetroChallenge 2023/10 *

michael-wesselMichael Wessel 10/22/2023 at 17:120 Comments

In my original RetroChallenge 2023/10 participation announcement, I promised a battery backed-up Real Time Clock (RTC) for the Microtronic. Well, here it is! I have hooked up the DS3231 RTC.


 I did not use any of the DS3231 Pico SDK C libraries found online literally, but I had used this module before in some of my previous projects (e.g., https://hackaday.io/project/177784-lambdaspeak-futuresoft-edition) and hence didn't have a lot of issues getting it to work. Most helpful I found https://github.com/bnielsen1965/pi-pico-c-rtc/blob/master/ds3231.c and I took bits and pieces of it, but heavily refactored - thanks, good code, Bryan Nielsen (https://github.com/bnielsen1965)! Nice and simple - I really dislike when people create a huge CPP framework for something that is not rocket science.

So how does that work? See, the Microtronic already has an internal real time clock in its firmware, and there is even an op-code F06 ("load time") that can be used to load the current time to register memory (registers for A-B for hours, C-D for minutes, and E-F for seconds). Two built-in ROM programs (PGM 3 and PGM 4) also allow you to set and see the current time (without using the F06 op-code).

However, the Microtronic RTC is not battery backed-up, and hence if you want to use the real time in your programs, you will always have to set the clock manually when you turn it on (using the ROM program PGM 3). This of course means limited utility.

How can the DS3231 RTC help here? Well, using similar ideas as explained in my previous log entry https://hackaday.io/project/192655-picoram-2090/log/224467-retrochallenge-202310-log-entry-3, instead of adding extra side-effects / semantics to vacuous op-codes, I can also intercept a non-vacuous op-code such as F06 ("load time"), and do anything I want by switching first into a dedicated memory bank to not interfere with the current program, then execute this program with the Microtronic, and finally return to the original program. When F06 is intercepted, the Pico first retrieves the current time from the DS3231, and then materializes a set of MOVI nx = Move Immediate Value n to Register x (op-code 1nx) into the current memory bank that will, when executed by the Microtronic, write the current DS3231 time into the A to F registers, overwriting the values that F06 had already left there. After returning from the banked-in sub-program, the registers A-F contain the correct time.

Here is a demo video:

Again, the underlying mechanism that loads the DS3231 time is entirely transparent to the calling program - from a user program's perspective, there is no difference in accessing the DS3231 vs. accessing the internal Microtronic RTC - the same single op-code is used, nothing else is required. This is the program from the demo: 

00 F6A # display "time" registers A..F on the LED display 
01 F06 # load time from RTC 
02 FF0 # wait for keyboard input 
03 F08 # clear registers
04 C00 # goto 00 

Discussions