Using a PSoC4 MCU
Antique electric clocks are both beautiful and elegant, but they really can’t provide accurate timekeeping. In this project article, Aubrey makes use of modern Cypress PSoC4 MCU technology to convert an antique clock into a device that can continuously keep accurate time.
My friend Nigel is a clock collector. Amongst his collection are two types of antique electric clocks (from the turn of the 20th century), which appear to have different mechanisms but work on a similar principle. One is an American-designed Eureka clock (Figure 1) and the other is a French designed Bulle clock (Figure 2).
The Eureka “pendulum” consists of a balanced disk that rotates in one direction—tensioning a coil spring—and then returns in a mesmerizing display. A video of this  is included in the RESOURCES section at the end of this article. An electromagnetic coil is mounted in the center of the disk, and a voltage is connected to the coil via a momentary mechanical contact. Two fixed magnets are on the circumference of the frame around the pendulum. When the coil and the magnets align (as determined by an electrical contact), a current is passed through the electromagnet, creating repulsion against the magnets, and energy is imparted to the pendulum.
The Bulle mechanism may boggle your mind . Although the electromagnet is visible at the end of the pendulum, the arc at the bottom is a 3-pole bar magnet, north at the ends and south in the middle. Apparently, this creates a strong magnetic field in the center, but is also an unstable configuration. So, the magnet sometimes needs reconditioning—something not for the faint of heart .
As with the Eureka clock, a voltage is presented to the electromagnetic coil with a switching contact when the electromagnet is at the midpoint, creating repulsion, and the pendulum gains energy. The pendulum on each unit drives an escapement mechanism that is geared to drive the clock hands.
There are several explanations of both clocks on that impeccable source: The Internet. Both devices are intended to be operated from a 1.5V battery, and, surprisingly, the coils of each one measure about 1,200Ω, despite some claims to the contrary. See the RESOURCES section at the end of this article for links to descriptions of the Eureka  and Bulle .
There are several other sources out there—including an article that describes some electronics to regulate the timing of the Eureka. That article is not included in my References because it is no longer available. It is suggested in several places to parallel two batteries to extend battery life. I trust that Circuit Cellar readers will understand why that is a bad idea. I can find no discussion why the Bulle needs a 3-pole magnet, and the picture  clearly shows only half an arc for the bar magnet. Any suggestions from readers will be welcomed.
Neither clock is great at timekeeping, though the Eureka is worse. The primary cause is thought to be the decaying battery voltage over time, but there are many other possibilities. Temperature, humidity and the cleanliness of the switching contact (affecting the current through the electromagnet) are some of the suspects. Nigel had read the description of the aforementioned electronic regulator, and thought that together, we might come up with a suitable means of regulating the time. These clocks have value as antiques, so we needed to control the timing by external means only.
According to the sages (Galileo included), the frequency of operation of harmonic oscillators is independent of the range of motion in the first approximation—so we will have to operate beyond that approximation. Our experiments will change the amount of energy imparted to a pendulum, in the hope that it controls the time. We think the further the travel, the more likely it becomes that we will exceed the first approximations of the mathematical analyses.
The energy imparted to the electromagnet can be controlled by the applied voltage. In the video in Reference , the contact is just visible behind the hour hand. It’s also clearly visible at around 56 seconds in the video in Reference . That contact closed for several tens of milliseconds, and ordinarily the energy is supplied for the full period of the contact. If we can control the period of the voltage for less time than that of the contact, this could create a second method of controlling the energy imparted to the pendulum.
The initial thought was simply to use a voltage regulator to ensure a constant voltage. That quickly evolved into switching that voltage through a relay. We then headed toward some forms of control that would measure the period of the pendulum and adjust the energy supplied. And, though this pointed in the direction of PID (proportional, integral, differential) control, there was clearly an awful lot we did not know.
We decided to use a microcontroller (MCU) and some electronics to allow us to check different modes of operation. At this point, we were reluctant to commit to a dedicated PCB, so the best choice was a development board. We also put the battery-operated requirement on hold, pending the results of the development.
It is no secret that I am a Cypress Semiconductor PSoC aficionado, and so I opted for the CY8CKIT-042 PSoC4 Pioneer kit (Figure 3). The PSoC4 is extremely versatile in configuring its internal peripherals, and the kit is compatible with the Arduino Uno. I invested in an OSEPP PROTO-01 prototype shield for the custom electronics, and an OSEPP 16X2SHD-01 16×2 LCD Display and Keypad Shield. Nigel has always accused me of overkill, and this kind of proves his point.
To test each stage, we created a series of “modes”—some of which had associated parameters. These could be selected using the keyboard and LCD display (Figure 4). I am ashamed to admit that despite several of my Circuit Cellar articles on creating menu hierarchies (Circuit Cellar 160, November 2003  and Circuit Cellar 342, January 2019 ) I approached this with brute force. For the sake of brevity, though, I will not spend any time describing its operation.
The schematic in Figure 5 shows the internal configuration of the PSoC4 MCU. This should be read with the schematic in Figure 6, which shows the external electronics. Different portions of both pertain to the different modes, and so I will need to refer to different subsets as we go through the modes.
Test Mode M0: The first mode (M0) is only a vague improvement on the original operation of the clocks. It merely provides a regulated power supply through the Texas Instruments (TI) step-down regulator LM317 (Figure 6, U1). The voltage can be adjusted using the R2 trimpot. The electromagnet coil is connected between the terminals Z and SCL. Do not confuse this with an I2C signal—it is merely the silk-screen name given to a screw terminal.
M1: If we are to control the clock by means of voltage, then we need a controlled voltage output. I called this mode 1 (M1), but with two sub-modes. The PSoC4 only has a current output DAC. I configured this as an 8-bit device, and passed it out through an analog multiplexer (DAC and AMuxHw, Figure 5). The multiplexer will be used later to generate a voltage pulse, but let’s ignore that for the moment. Initially it is configured to pass the current.
On the protoboard (Figure 6) the current is converted to a voltage using R4, and is buffered by a LM358 configured as a voltage follower. The LM358 op amp from TI is capable of supplying up to 20mA, and since the coil is said to be 1,200Ω at 1.5V, it should be capable of supplying the nominal 1.25mA. The coil is connected across terminals X and SCL. The voltage can be set as a parameter using the LCD-based user interface, and the value is stored in EEPROM. This is the first sub-mode useful in proving that the DAC voltage driver works.
Now for the second sub-mode of M1. In later modes we will need to measure the current flow as the contact to the electromagnet closes. We will need to know the time the contact is closed (let’s call that PW) as well as the period of a single cycle of operation (which we will call PD). To measure these two parameters (which we will also need to do later), I added a series resistor to the current path. In other words, the coil is connected between X and SDA.
Although this would reduce the overall current, it can be compensated by elevating the source voltage. I chose a low value for R5 (Figure 6), and then amplified the voltage so that it drives an LED, D2 and also a comparator (U3, LM393). The LED indicates when current is flowing. The comparator is used as a signal to the PSoC4 that the current is flowing. This signal has been wired to the COMP_IN terminal (Figure 5). The MCU can then measure PW and PD, which it shows on the display, and can be noted down. With the addition of this piece of software, no oscilloscope is necessary to take the reading.
M2: In the timing regulator article (mentioned earlier) the principle of operation was that the controller would generate a regular voltage pulse, and the oscillations of the pendulum would gradually synchronize with them. To try this mode in all its simplicity, I added a reed relay to the design (K1, Figure 6). The regulated supply is connected to one terminal of the relay contact (Y to Z), and the coil across terminals W and SCL. Through the parameters, it is possible to adjust the period the relay is on, as well as the cycle time. But for the experiment, I just wanted the selected period to be greater than PW and less than PD. Of course, the LM317 voltage may be adjusted independently using the pot. There is an LED on the Pioneer Kit board, and I used this to indicate when the relay was energized.
Although this is driving a relay (with activation/deactivation and bounce times), I opted to use a hardware timer to drive the relay. The RELAY_MUX multiplexer (Figure 5) is configured via bit CONTROL_2 on the CONTROL_SELECT register to feed the output from the PWM_LED counter to the output. The two parameters are programmed onto the counter.
M3: Mode 3 (M3) is essentially the same as M2, except that it uses the DAC-controlled voltage source, so the DAC output is a third parameter. The relay is fed from the DAC (connect X to Y, Figure 6), and then we can go in one of the two sub-modes, as in M1, for energizing the coil. D2 will flash when the relay is active AND there is current flowing through the coil.
MORE TEST MODES
Before I move on to the next modes, I have to explain why we need to know PD and PW when we are measuring the current flow through R5. Refer to the timing interrelationship shown in Figure 7.
Current can only flow through the clock’s contact when the contact is closed and there is voltage. If we are switching the voltage off and on, we need to think about the relative timing. The pulse voltage must be high before the contact closes, or the current through the coil will not reflect the initial closure of the contact. By definition, the pulse turns on and off. If the pulse width (coincident with the start of the current flow) is longer than PW, it will be limited to PW. If it is shorter than PW then it can only be re-energized after PW, but before PD, to ensure synchronization with the contact closure.
The same timing concept as in M2 is set up on the PWM_LED timer, but the PWM_LED output is channeled to the AMuxHw by the setting on the DAC_SEL control register (Figure 5), thereby toggling the output current on and off.
M4: This mode (Mode 4) is an extension of M2, along with the current detection connection. The relay pulse is synchronized with the contact closure. The energy imparted to the pendulum is related to the regulated voltage and the pulse time (≤PW). The pulse time and the voltage restoration time (>PW, but <PD) are configurable variables.
The program waits for the COMP_IN signal, which it reads through the status_0 pin READ_COMP input register (Figure 5). It then initiates the counter sequence, as described in M2.
M5: Mode 5 (M5) mimics M4, except it drives the coil with the DAC voltage. This adds an additional parameter. The output current is toggled when the COMP_IN signal is seen.
M6: This is the ultimate goal—PID control. We would like to maintain the clock time using a PID technique that modifies the pulse width or voltage. To begin, I just wrote the software for pulse width control. After our initial tests, I think the voltage would be the better control variable. I have not opted to implement a version of this using the on-board relay. I am just switching the output DAC voltage on and off.
SOME CONTROL THEORY
Reiterating some control theory, the calculated output is based on the measured error, as in Equation (1). The overall control function can be expressed mathematically as:
where KP, KI, and KD are all non-negative and denote the coefficients for the proportional, integral, and derivative terms, respectively. In this case, the parameters are 1,024 times greater than the resulting coefficient. For example, if KI is 0.046, the parameter would be 0.046 × 1,024 = I 47. The binary number will make the division much quicker. There are six parameters to this approach. The additional three are scaled coefficients of the PID equation.
The period time is measured on the PW_MEASURE timer (Figure 5), and the time of the output pulse is generated on the PID_COUNTER timer. The timers are controlled in hardware from the COMP_IN signal. Unfortunately, there were not enough resources on the PSoC4 to implement the full PID loop and all the other settings, so the activation of the current output is implemented in software.
From early measurements, I think future development of the PID loop would have to use the output voltage as the control instead of the pulse time, but a lot more development is needed before getting to that.
In addition, we have presumed that in all the modes, the period time would be approximated, and nudged close to the correct period. In truth though, if the gearing ratio from the escapement to the hands were known, this would be a fixed number. The gearing ratio may also vary from Eureka to Bulle, and even different Bulle models. To my knowledge, the ratio has not been published, so the only options left are to count the teeth or, more tediously, to count the number of oscillations for a given time period.
When creating a PCB, we would like to include a boost converter from 1.5V, so that the unit will operate from a battery but maintain a regulated voltage. In turn, that poses a problem choosing the user interface, since the LCD display does draw current. We thought that we could sell a few of these, but didn’t know the level of expertise that would be required, so the simplest possible setup was desirable. Some of the literature, however, suggests that temperature and humidity affect the output. It would be possible to monitor these variables over time, and create an historical record with a more sophisticated user interface. Finally, the MCU would be crystal controlled, making the time measurements and pulse generation much more accurate and tolerant of temperature variation.
Unfortunately for this project, Nigel lives in England and I live in Canada, so this report is inconclusive to date. As an impoverished engineer, I don’t have the wherewithal to buy an $800+ Bulle, much less the $3,000+ for a Eureka. And then we have to service the unit. Although we have done some preliminary testing, it is clear that this project is going to take a long time to complete, especially because time gains or losses for a particular setting must be measured over several days, at the very least. I hope to check back with you when I have more conclusive results.
References: Video: EUREKA Mantel TOP Condition!! Clock Antique Electric Restored UK 1906 England  Video: Bulle-clock.AVI  Video: Bulle Clock Restoration  Restoration/ Repair of an Eureka Battery Clock
 Restoring a Bulle Clock
 Hierarchical Menus in Embedded Systems. Circuit Cellar #160 Nov 2003
 Hierarchical Menus for Touchscreens Circuit Cellar #342 Jan 2019
The Eureka Clock
Video: Instructions Adjustment pendulum Bulle clock https://www.youtube.com/watch?v=aA5qRfx7Wbk
Magnet Charger/ Revitaliser
OSEPP PROTO-01 Proto Shield
PUBLISHED IN CIRCUIT CELLAR MAGAZINE • MAY 2020 #358 – Get a PDF of the issue