⏱️ Lectura: 15 min

In Portobello, a seaside neighborhood of Edinburgh, a group of volunteers climbed a steep staircase up to the tower of the neighborhood’s old police station and found something they didn’t expect: a PIC 16F628 microcontroller with no manufacturer markings, hand-soldered, that had been controlling the chimes of an 1877 clock for a quarter century.

📑 En este artículo
  1. TL;DR
  2. What happened
  3. Context and history
  4. Technical details: what the PIC 16F628 does inside the box
    1. Three generations of technology in the same tower
    2. How to confirm what the board is doing
  5. How to reproduce this if you end up with an unmarked board
  6. Impact and analysis
  7. What’s next
  8. Frequently Asked Questions
    1. What is a PIC 16F628?
    2. Why doesn’t the chime box have a real-time clock?
    3. How did they set the clock without a manual?
    4. What is Action Porty?
    5. Can the firmware of an unmarked PIC be recovered?
    6. What happens if the clock chimes incorrectly?
  9. References

The local community, organized as Action Porty, had bought the building for community use, but nobody knew how to set the tower clock or how the electronic box that rings the chimes worked. What started as an afternoon of DIY tinkering ended up being an exercise in reverse engineering undocumented hardware.

TL;DR

  • Construction of the Portobello police station, in Edinburgh, began in 1877.
  • The Action Porty community bought the building with funding from the Scottish Land Fund, but nobody knew how to adjust the tower clock’s time.
  • Inside the chime control box is a PIC 16F628 microcontroller with a date code estimated at 2001, with no manufacturer markings.
  • Lifting a pawl disconnects the motor from the shaft and allows the time to be adjusted manually, face by face.
  • The circuit also includes a lead-acid battery charger, relays, and a GMT/BST switch.
  • The only visible control is the “advance” button: you have to hold it down and release it for the chime to ring the next hour.
  • A status LED blinks in a pattern (long, long, short, short, short) that nobody has managed to decode yet.
  • There’s no real-time clock on the board: it only counts hours from the pulses of a mechanical switch on the shaft.

What happened

It all started with a message from a neighbor, who asked a technically-minded friend if he wanted to climb up to the tower of the Portobello police station, bought months earlier by Action Porty, and try to fix the clock. The organization had publicly asked for someone who knew how to change the mechanism’s time, and they couldn’t find anyone to ask.

Reaching the mechanism wasn’t trivial. It meant climbing a long, steep staircase up to a dusty attic, and from there another flight of steps that led to the clock tower. Once at the top, the reward was seeing the complete mechanism: a late-19th-century gear train connected to three clock faces, one for each facade visible from the street.

Construction of the building began in 1877, so it’s plausible that the original mechanism dates from that period. Over time, electric motors were added to replace manual winding, along with a control box to turn off the chimes at night.

To set the clock, the volunteers worked out the mechanics: a motor drives, through a gear train, a shaft that turns once per hour. That shaft splits into three secondary shafts, one for each face, and directly drives the minute hand; a gear on each face derives the hour from there. The hypothesis was simple: if they could disconnect the motor, they could turn the shaft by hand and adjust the time.

They found a pawl on one of the gears that could be lifted to release the shaft. With the pawl out, the shaft turned by hand with no resistance and allowed the hands to be moved. Each hand had a counterweight visible from inside the tower, so they worked out the position of the hand they couldn’t see by using the opposite counterweight as a reference.

There was a moment of panic when they thought they’d left the clock running backward. The explanation turned out to be simpler than it seemed: they were looking at the mechanism from inside the tower, so everything appeared mirrored. They went down to the street to check the time on the face visible from outside and, to their relief, the clock was running forward and showing the correct time.

Context and history

The Portobello police station building has a longer history than that of a police post. It was built to house meetings, administration, and the courts of what was then the independent burgh of Portobello. When Portobello was annexed by Edinburgh, the building became a public library and, later, a police station.

The Scottish Land Fund allowed Action Porty to buy the building for community ownership. While the volunteers were up in the tower, another group elsewhere in the building was stripping out 1970s polystyrene panels and woodchip-textured wallpaper that had hidden the original architecture for decades.

That dual restoration, of the building and of the clock, sums up the kind of project this is: recovering Victorian physical infrastructure with today’s tools and technical knowledge, without any original blueprints or manuals on hand.

Construction of the Portobello police station building began in 1877. Foto de CDC en Unsplash

Technical details: what the PIC 16F628 does inside the box

The mechanism upstairs, the clock itself, turned out to be relatively easy to understand: it’s a classic tower clock gear train, with an electric motor added to replace the original weight-driven winding. The real challenge was in the chime control box, which did have modern electronics layered on top of the Victorian mechanics.

Inside that box, the volunteers found a PIC 16F628 microcontroller, with a date code they estimate at 2001, mounted on a board with no manufacturer markings or model number. Next to the PIC were several relays, a power supply, and a battery charger circuit for a lead-acid battery included as backup. Nobody present knew who had designed that circuit, or whether it was a standard product from some tower clock company or a custom build made for that particular building.

The operating logic, reconstructed from measurements and trial and error, works as follows. The box turns on an AC motor that drives, via a chain, the chime striking mechanism. While that motor is running, the clock strikes continuously. A microswitch on the striking mechanism tells the box how many chimes have already rung, so it knows when to stop the motor. Another microswitch, located on the clock’s main shaft, triggers once an hour and tells the box when to start the chime sequence.

The board has no real-time clock at all: it doesn’t know what time it is in the sense of a quartz-crystal RTC. All it does is count pulses from that second microswitch to know what hour of the day it is, and compare that count against the number of strikes the mechanism has already made. It’s an elegant solution to the actual problem: there’s no need to know the exact time when there’s already a mechanical clock running right next to it, giving that away for free, pulse by pulse.

The only control exposed to the user is a button labeled “advance.” You have to hold it down for several seconds before anything happens; when you release it, the chime rings the next hour. Pressed and released again, it rings the hour after that. Adjusting the box’s hour count seems to consist of pressing “advance” as many times as needed to reach the correct hour.

There’s also a status LED that blinks in a pattern (long, long, short, short, short) that the volunteers couldn’t decode on their first visit. The box also has a selector switch for the UK’s GMT/BST time change and banana-plug connectors for the two microswitches, separate from the mains power cables, the clock motor, and the chime motor.

flowchart TD
A["Clock motor"] --> B["Main shaft, 1 turn per hour"]
B --> C["Face 1"]
B --> D["Face 2"]
B --> E["Face 3"]
B --> F["Hour microswitch"]
F --> G["PIC16F628 board"]
G --> H["Chime motor relay"]
H --> I["Striking mechanism"]
I --> J["Strike microswitch"]
J --> G

The diagram summarizes the full circuit: the mechanical shaft triggers the count, the board decides how long the chime should ring, and a second switch confirms when it’s rung enough.

Three generations of technology in the same tower

EraWhat it addsAdvantageLimitation
Original mechanism (1877)Weight-driven winding gear trainDoesn’t depend on electricity; runs for decades with no electronicsSomeone has to climb up and wind it by hand every few days
Conversion to electric motorMotor that replaces weight-driven windingEliminates manual winding maintenanceThe clock stops working if the power goes out
Control box with PIC 16F628 (~2001)Automates the chimes and allows them to be turned off at nightAllows silencing nighttime chimes without touching the mechanicsNo documentation or RTC of its own: losing the hour count means readjusting by hand

The control box has no real-time clock: it counts hours from a mechanical microswitch. Foto de ThisisEngineering en Unsplash

To better understand what kind of firmware might live on a chip like this, it helps to first look at the minimal example anyone would write for a brand-new PIC16F628, and then a reconstruction of the actual logic observed in the box.

#include <xc.h>
#pragma config FOSC = INTOSCIO, WDTE = OFF, PWRTE = ON
#define _XTAL_FREQ 4000000

void main(void) {
    TRISB = 0x00;      // RB0 as output to the status LED
    while (1) {
        RB0 = 1;
        __delay_ms(500);
        RB0 = 0;
        __delay_ms(500);
    }
}

This is the simplest possible firmware for a PIC16F628: it blinks an LED every half second using the internal oscillator. The actual LED in the Portobello box blinks in a much more elaborate pattern (long, long, short, short, short), which suggests a state machine rather than a simple blink.

static volatile unsigned char horas_objetivo = 0;
static volatile unsigned char golpes_dados = 0;

void interrupcion_switch_hora(void) {
    horas_objetivo++;
    golpes_dados = 0;
    RELE_MOTOR_CAMPANADA = 1;   // starts the striking motor
}

void interrupcion_switch_golpe(void) {
    golpes_dados++;
    if (golpes_dados >= horas_objetivo) {
        RELE_MOTOR_CAMPANADA = 0;  // all the chimes have rung
    }
}

void boton_advance_soltado(void) {
    horas_objetivo++;
    golpes_dados = 0;
    RELE_MOTOR_CAMPANADA = 1;
}

This reconstruction isn’t the box’s actual firmware, nobody has dumped the PIC’s memory yet: it’s the minimal logic that explains the observed behavior, counting strikes against an hour target and letting the “advance” button increment that target by hand.

How to confirm what the board is doing

To validate each hypothesis before touching anything irreversible, the volunteers measured continuity between the banana connectors and the PIC’s pins with a tester, and watched the status LED with the chime motor disconnected. That same protocol works for anyone who runs into an unmarked board: isolate the load (disconnect the chime’s 220V motor), use a multimeter to measure which pins change state when the “advance” button is pressed, and log the duration of each LED pulse with a stopwatch or, better, a cheap logic analyzer connected to the low-voltage signal lines.

How to reproduce this if you end up with an unmarked board

If you ever inherit an undocumented control board, from a tower clock, an old gate, or a factory alarm, the protocol they followed in Portobello can be summed up in concrete steps.

First, identify the chip. The PIC 16F628 comes in an 18-pin DIP package with the part number printed on top, even if the rest of the board has no markings. That number is enough to download the full datasheet from microchip.com and learn the pin assignment for each one.

Second, map the connectors before powering anything up. With the equipment unplugged from the mains, use a multimeter in continuity mode to trace each wire to its destination (clock motor, chime motor, strike switch, hour switch, mains power) and label them physically.

Third, observe before intervening. Power the board with the motor loads disconnected and just watch what the status LED does and which pins change voltage when the only visible button is pressed. That was the step that let the Portobello volunteers deduce the logic of the “advance” button without risking the mechanical mechanism or the 1877 electrical installation.

Fourth, if you need to re-read or dump the PIC’s program, an ICSP programmer compatible with PICkit can connect to the clock, data, and MCLR pins, as long as the chip’s code protection bit isn’t enabled; if it is, there’s no way to read the program without erasing it first.

💡 Tip: Before touching any microswitch connected to a 220V motor, disconnect power to that load at the fuse box, not just at the control board: the relays in these boxes often leave the motor connected directly to the mains when energized.
⚠️ Watch out: Working inside a clock tower means climbing long, steep staircases in narrow spaces. Any work like this should be done with another person below, never alone.

Impact and analysis

The Portobello case isn’t unique. Many community buildings, churches, and small town halls inherit control systems installed twenty or thirty years ago by a local electrician who’s no longer around, or who never documented what he did. When that person retires or loses touch with the building, the knowledge of how the board works goes with them.

An unmarked PIC 16F628 is, in that sense, a small case study of a bigger problem: the technical debt of physical infrastructure. Buildings of this era accumulate layers of control electronics, for heating, alarms, gates, tower clocks, installed piecemeal and almost never documented for whoever comes next.

The advantage, in this case, is that the problem was bounded and reversible. They could disconnect the motor with the mechanical pawl, and the worst consequence of a mistake was a clock off by a few hours, not a critical system like a fire alarm. That gave them room to experiment with the “advance” button without fear of breaking something expensive or dangerous.

The building restoration happening in parallel, stripping out the 1970s polystyrene and wallpaper, also shows that this kind of community project tends to combine very different trades: carpentry, electrical work, and, in this case, reverse engineering of low-level embedded electronics.

What’s next

Open questions remain. The volunteers couldn’t decode the status LED pattern or confirm exactly what the “reset” button does beyond turning off the clock motor, and they also didn’t test what happens if the chime ends up ringing thirteen times in an hour due to a counting error.

The plan, according to what they documented in their original post, is to come back with more time to finish that mapping: decode the LED, confirm the reset button’s behavior, and leave a written guide for whoever has to work on the box after them. It’s, on a small scale, the same documentation exercise that’s missing from much of our legacy physical infrastructure.

📖 Summary on Telegram: View summary

If you have an unmarked board sitting around in a drawer, download the datasheet for whatever chip is printed on it from microchip.com and start by mapping continuity before powering anything up.

Frequently Asked Questions

What is a PIC 16F628?

It’s an 8-bit microcontroller from Microchip’s PIC family, in an 18-pin DIP package, widely used in simple control electronics from the late 90s through the 2000s for its low cost and reprogrammable flash memory.

Why doesn’t the chime box have a real-time clock?

Because it doesn’t need one: there’s already a mechanical clock running right next to it, with a microswitch that marks each hour. The board just counts those pulses instead of keeping its own quartz-crystal timer.

How did they set the clock without a manual?

They found a pawl that disconnects the motor from the main shaft. With the motor decoupled, the shaft turns freely by hand and allows the three clock faces to be moved to the correct time.

What is Action Porty?

It’s the community group that bought the old Portobello police station building, in Edinburgh, with funding from the Scottish Land Fund, to turn it into a community space.

Can the firmware of an unmarked PIC be recovered?

It depends on whether the chip’s code protection bit is enabled. If it isn’t, an ICSP-compatible programmer can dump the program memory by connecting to the clock, data, and MCLR pins. If it is enabled, it’s not possible without erasing the chip first.

What happens if the clock chimes incorrectly?

This is one of the questions the volunteers left unanswered: they didn’t test what happens if the strike count gets completely out of sync, for example if the chime ends up ringing thirteen times.

References

  • Fixing the Portobello Police Station Clock: the original Point in the Cloud post with photos of the mechanism, the control box, and the full process.
  • Wikipedia: PIC microcontroller: background on the microcontroller family the PIC 16F628 found in the box belongs to.
  • Microchip Technology: the official manufacturer of the PIC16F628 family, with the datasheets needed to identify any chip in this series.
  • Wikipedia: Portobello, Edinburgh: historical and geographical background on the neighborhood where the building is located.

📱 Like this content? Follow @programacion on Telegram for daily tech content in Spanish: quick summaries, fresh content every day.

Imagen destacada: Foto de Josh Redd en Unsplash

Categories: Noticias Tech

Andrés Morales

Developer and AI researcher. Writes about language models, frameworks, developer tooling, and open source releases. Covers ML papers, the tech startup ecosystem, and programming trends.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.