One way to add time control is to pair a real-time clock (RTC) chip with a microcontroller unit (MCU) – along with an independent power source, because MCU is likely to draw a sizable amount of current. My ambition is to power everything from the phone line and still keep the circuit “invisible”. Certainly, it is possible to put the MCU in a dormant state, then wake it up with interrupts generated by RTC, etc. You are welcome to do so, if you wish. I have got a simpler idea where the MCU is not needed at all for the regular circuit operation, only for its setup. Take a look at the diagram in the first image.
What replaces a complicated MCU in making on/off decisions is a very simple T flip-flop chip. Read its Wikipedia page if you are not familiar with this fundamental element of digital electronics. In short, its output, Q, toggles between 0 and supply voltage upon receiving clock impulses. (I have actually built it from JK flip-flop, M74HC112, by tying both the J and K inputs to the supply line.) Hence, it provides a nice “translator” between time pulses and on/off states.
Now, how do we use the state of Q output to connect/disconnect impedance to/from the phone line? Simple. In the analog part of our circuit the signal from ring detector activated MOSFET transistor acting as a switch. Thus, a second MOSFET paired with the first one in a logical AND configuration should be the simplest solution. Indeed, the 680 ohm resistor, R4, connects to the phone line only when: 1) ring is detected; AND 2) the flip-flop’s Q output is high.
It is the RTC chip that sets the Q output low or high. Initially, I experimented with Adafruit’s PCF8523 breakout board, but found it inadequate for my purposes: it features only one alarm. Ah, if you are not sure what I am talking about: modern RTC chips can be set to store a particular date and/or time in their memory. When real time reaches the stored value, RTC outputs an interrupt signal on one of its pins. This alarm can periodically repeat itself, e.g., every day if hour/minute/second registers are set while day/month/year ones are ignored. But we need to trigger the T flip-flop at two different times per day, thus we need two independent alarms. Another of Adafruit’s products, the precision DS3231 RTC has two alarms, but the problem here is that when either is triggered the resulting interrupt signal is a permanent change from high to low voltage. Resetting it back to high requires intervention from an MCU… Bummer.
PCF85263, a newer RTC chip from NXP Semiconductors, however, is perfect in this respect. It has two independent alarms and its interrupt signals can be configured as pulses. In addition, it’s SO8 package perfectly matches that of PCF8523, so I simply desoldered PCF8523 from the breakout board and soldered PCF85263 in its place. Works like charm!
In summary, the additional parts needed for time control are:
- U4 = M74HC112, dual JK flip-flop triggered by the negative edge of clock pulse.
- U2 = PCF85263, real time clock along with the required 32 kHz oscillator crystal, Y1, and decoupling capacitor, and battery backup, and I2C pullup resistors… Ugh, just get PCF8523 from Adafruit and swap the RTC chips.
- Q1 and Q2 = two IRF630B, N-channel MOSFET transistors. (So, you ask, what happened to the 2SK2545? Well, I simply did not have two of these, so I used IRF630B.)
- R5, R6, and R7 = Pullup resistors 10 kOhm, 1/4 W
There is a very important caveat you must be aware of (and of which I learned the hard way): the M74HC112 flip-flop will draw a relatively large current unless all of its input pins are connected! The chip has actually two JK flip-flops; I used only one leaving the other unconnected and was surprised by a huge power draw. But after securing all the unused input pins to the ground the supply current dropped to a single digit uA range. Make sure you leave the unused output pins, Q and ~Q, on both JKs unconnected!
How it works? To set it up, I connect an MCU (Arduino Mega in my case) to the P1 connector: ground pin to the ground, the SCL and SDA pins to their counterparts, and two digital pins to CLR and PR, respectively. What are these, you ask? When a JK flip-flop is first powered up, its Q and ~Q outputs are in a random state. Hence, the M74HC112 chip has preset, PR, and clear, CLR, pins that let the MCU initialize Q and ~Q to a state appropriate for the time of the day. Read the data sheet for more details. Next, the MCU transmits instructions setting the alarms, interrupt type, etc., to the RTC through SCL/SDA pins using I2C protocol. After this setup the MCU is disconnected and the circuit flies on its own solely from the phone line. For example, during the daytime MCU would set the Q output to a low state, then set the first alarm sometime in the evening hours range and the second in the morning range. When the first alarm is triggered, the RTC sends a short rectangular impulse, as illustrated in one of the images above, whose falling edge would flip the Q state from low to high activating the Q2 MOSFET. The circuit would the kill incoming phone rings during the night when the Q1 is activated. In the morning the second alarm pulse would deactivate Q2 and all phone rings would be allowed during the day since the state of Q1 wouldn’t matter.
This cycle repeats indefinitely until the MCU is connected again to change the alarm(s), or until something breaks, or the phone company comes knocking. 😉 In the embedded video, I connected an LED to the unused ~Q pin in a way that lists it up when ~Q is low => it indicates the high state of the Q pin. Next, I instructed the RTC to send an interrupt pulse every second to test the system.
Lastly, was it all worth the effort? Take a look at the last two images: under normal operation the circuit (without the LED) draws only 10 uA of current and the line voltage remains at a very healthy 51 V! In spite of more connected components the “killer” still remains “invisible”. 🙂