New 5May2019, updated 8Jul2019
This note describes my only real invention this year: a USB 5V in and USB 5V out, where the 5V out will only be kept as long as a built-in watchdog timer is fed with an edge of a signal from an output of an internal I2C chip. Since Google could not find any such for me (or I didn’t feed it correctly. Update: ) then I had to invent one myself (Update: I still would have to invent this one). The unit also has two 230V AC relay outputs.
Two of my needs solved
I use an XMOS startKIT as my aquarium controller, see My aquarium notes (Controller).
- The startKIT has no internal watchdog, and it’s difficult to make one in HW on the board or in the microprocessor’s SW. See the Watchdog on startKIT processor? and Restarting a startKIT from SW? threads on XCore Exchange. So I decided that I wanted to make one by controlling the 5V USB power supply cable instead. Such a unit would probably be a new design that even someone out there may be in need of. I already had an I2C line with SDA, SCL, 3.3V and GND that I use to talk with three temperature chips MCP9808. This new unit just intercepts that pluggable line. (Aside: There are other XMOS-related blog notes listed here)
- I have also seen that it may be nice to see how the aquarium migh benefit from having a permanently installed water pump and filter, that I may run at times. (Only mechanical filtering, not for a biological filter, which would require constantly running water through it). Like the EHEIM surface skimmer Skim350 that runs on 230V and draws 5W (standard disclaimer for everything here and in all my blog notes). So I needed a small power 230V AC relay output. Or two if more comes up.
The functionality of the watchdog part of this unit may just be something you have been waiting for a long time. You could build one (diagram included) – or wait for somebody to make a little breakout board of it.
The box shown in the block diagram above works like this: when 5V_IN is powered it takes about 7 seconds before 5V_OUT is applied. Then the Supervised MicroProcessor Unit (=SMPU) has about 5 seconds to write to a port on an I2C line to tell it is alive. As long as this is forever done within 5 seconds, then 5V_OUT is stable. If not, then 5V_OUT will be removed for about 7 seconds for a new trial.
Not on (=/on) means that the line needs to be pulled down for the relay to switch from off (=not activated or /activated ) to on (=activated).
A smart thing would be if the SMPU is able to read, increment and write the number of restarts every time, and upon some request this value is shown to a user of the SMPU – for diagnostic purposes. I have a FRAM (from Adafruit: here) to do this as simple as possible (even if there are libraries to modify the FLASH in the XMOS world).
Design and construction by me. However, you may copy as much as you like. Or use it as a start for your own design.
The circuit diagram is drawn in iCircuit (1.9.1). The .icircuit file is available here. Some symbols are not correct, like the N-MOSFET HEXFET TR1-TR4 and the varistors V1-V2. (I have not used the simulator part much in this diagram. But I have taken out excerpts and made smaller diagrams for simulation.) (As I may update the diagram this unreadable front-end picture may not be updated. But the PDF is). Press for PDF:
Tip: To print the PDF on two pages, download Adobe Acrobat Reader DC and print as poster 32% and portrait mode. Then cut the two papers and glue them.
Observe that the diagram contains 230V AC circuitry for the relay outputs. Disclaimer: even if I may have some advice here, you are responsible that your local rules and regulatory claims are adherred to.
The idea with the above scope measurement (made on my Siglent scope) is to see how no watchdog pulses will keep the lower green 5V_OUT pulsing to 5V (about 5 seconds) and back to zero (about 7 seconds) until watchdog pulses (seen as the blue right part’s sawtooth pattern) finally will keep 5V_OUT stable. Until these pulses fail.. (then repeat).
- CH1 (yellow) is the voltage on the C5 capacitor of the monostable multivibrator D2.2. It times out in lack of pulses at /1B
- CH2 (purple) is the voltage at C2. It charges as long as 5V_OUT is not present and finally triggers the schmitt trigger D3
- CH3 (blue) is the voltage on C6 that is charged until watchdog pulses on D2 /2B arrives
- CH4 (green) is the 5V_OUT line on the USB. It’s stable only after watchdog pulses are seen
Both parts of the monostable multivibrator is triggered with a high-to-low pulse on /1B and /2B inputs. This is to avoid an ill defined 5V_OUT condition when 5V_IN power is on the rise. Now it takes about 7 seconds before 5V_OUT is applied. I have no LED for 5V simply because the SMPU box is rather visible beside the aquarium. Also, such a LED would give me little. It’s rather easy to see when my aquarium box has no 5V in!
The diodes are all to discharge large capacitors during power-down. They are schottky diodes, measured to 350 mV reverse voltage.
The boards have two powers that are independent of each other:
- (Power 1) 5V_IN from the USB Micro-B connector. It powers the NAND gate and the watchdog (74HC4538D multivibrator) and all the three relay coils. Also, passed in through the relay to 5V_OUT
- (Power 2) 3V3 from the I2C cable. It powers the I2C chip (MCP23008) only. My I2C line is 3.3V, finito
- GND is common for both
When 5V_OUT is at 5V it’s assumed that the powered unit comes up with a functional I2C line, including the 3.3V power.
230V AC relay outputs
See description of the relays below.
Relay outputs interfering with ongoing I2C?
Above we see oscilloscope picture of the two relays alternating between one on and the other off and then changing both. 5V is switched by pulling a 1k down. The relay needs about 4.3 ms to saturate the coil and pull the switch and about 760 μs to de-energize to release the switch.
You can see the rather extraneous bouncing of the relay contacts when they close. For this test it would enter the other contact set through via the decoupling network C8/V1 and C9/V2 that I did not passivate by shorting the two 230V AC inputs 18 and 24. When I did that only some very high frequent noise passed.
The purpose of this measurement is to see if I ever had noise from the relays disturbing the I2C message. Even if the lines MCP230008 output pins change on the second to last falling edge of SCL then the relays as both being activated and released have so much delay that there will be no noise entering the I2C comms. Thas is, if it is fast enough. I use I2C speed of 100 kbit/s (kHz). The full I2C message is seen above. However, there should probably be no new I2C comms before well after 10 ms!
- Detailed discussion of the design and parts list are not given. However, the circuit diagram is extensively annotated. But as this list has developed, I am not sure any more. It’s become close to a combined description and parts list:
- The box contains two boards, one mounted on top of the other. The top has a 230V AC section with enough distance, and a part of the box for the 230V input, fuse (250mA fast) and the double output connector, plus the 300V AC varistors (230V AC plus 30%, for contact gap arch limitation) and 760V 10 nF capacitors C8 and C9 (class X1, for EMI/RFI noise reduction) – all mounted as 3-D. However, they will stay in place and not mess around should I take the box for a bicycle ride (I did the other day when I showed it in the pause of a lecture). There also is a mechanical shield with a grounded copper foil between this compartment and the USB connectors
- The D1 I2C chip is MCP23008 (from Adafruit, here). SPI version, see below
- The D2 double retriggerable monostable multivibrator is PDIP-16 (plastic dual in-line package) or DIL-16 (dual in line) pin version CD74HC4538E. This is hard to get by these days, so a 74HC4538D in a SOIC-16 is eprhaps easier obtainable. If you do hand soldering then an SMT Breakout PCB for SOIC-16 or TSSOP-16 from Adafruit is ok, here
- The D3 chip quad 2-input NAND schmitt trigger is 74HC132 DIL-16. With inverted inputs for D3.2 it functions as an OR. See Wikipedia here. The inverted inputs are the /1Q and /2Q from D2. The schmitt function (with hysteresis) gives a precise transition when C2 charges and decharges
- I bought the USB Micro-B input (from Adafruit, here) and the USB A output (horizontal USB 2.0 A type THT slim type from Würth Elektronik) from Elfa Distrelec (here). However, the latter is upside down if you ask me
- The I2C connectors are of series 719 from Binder, bought at Elfa Distrelec
- All three relays are of type HJR1-2C from TIANBO GANGLIAN ELECTRONICS, bought at Elfa Distrelec. The coil is 5V and the contact set’s max is 240V AC, 60W. I will switch inductive 5W, and I protected the contact set well with the above mentioned varistor and capacitor, plus a shared 250 mA fast fuse. I probably would not have used these relays in a product, but for my hobby use it should be ok
- The 230V AC four pin connector for the relay outputs I have no idea where I got. I must have found it in the reuse waste container when we moved location at work. It looked like they threw everything away (I know they didn’t). From the h-type logo and number 732 063 on the unit and research on the net it’s probably a Hirschmann™ GDM or GDMF valve connector or the like. When it’s plugged in there is a screw holding it in place
- The box is made from an acrylic Saltsjön box bought at an Åhlens shop in Sweden (obsoleted?) and a green polyethylene chopping board from Ikea. Screws are Märklin 1.6 * 13 mm of type 74990. I have not studied the flammable properties of my boxes. For my hobby use they should be ok
- The two contact sets on relays REL1 and REL2, used for 230V AC are not paralleled. I don’t like to parallel contact sets since they are mechanical. A single mechanical switch is better than two if they don’t switch on the microsends simultaneously
- The transistors TR1-TR4 MOSFETS that I use for driving the relays have internal zeners. so that drain (D) to source (S) voltage is limited, which again protects the transistor against the coil’s spikes when it’s not fed any more. (The zener’s cathode is connected to the drain (D) of the MOSFET.) That’s why I haven’t connected a diode across the coils, since it’s not necessary. But I added the Z1 diode across 5V_IN so that I would not get any negative spikes at any time on 5V_IN
- If you have access to the USB A on the SMPU side, then maybe you could use the Data+ and Data- lines for SDA and SCL – or just use a line for a watchdog pulse of some sort.
- On the startKIT one of the “slices” is equipped with a USB driver from the factory, so it could perhaps have been done. But then I had the I2C already in use, so it was natural to use it in this case. I guess this would be the most general case as well
- Update:  does this!
- Use SPI instead of I2C? It should be possible to make a variant with the SPI version of the I2C chip. It’s called MCP23S08. It would need three lines instead of the two I2C lines: SCK, SI (connects to MOSI on master) and SO (connects to MISO on master). With a 5-wire variant of the update watchdog cable it could be possbible to make jumbers to route the chip’s pin 3 to either SO or A2 (high er low)
- Maybe a more general case would be to also switch or just route the USB data lines? I dropped them simply because I made a 5V watchdog, used as such. When I would use the USB line for something else (like upgrading the SW) I would need to do that, not with a watchdog box that would break the whole line
- The disable watchdog jumper could have been an external switch. But why disable it that easy?
- I have used FET transistors to take the 3.3V as far down as possible, to give the relay coils as much voltage as possible. A standard NPN transistor might also be ok
- The FET transistors have a R-R ladder on the gates, simply to make it possible to unplug D1 from its socket for testing, and to work with the two boards separately. Then the transistors would all be off. Also, because the small capacitor in the gate might keep the FET on for too long in an unconnected case. Besides, I don’t like floating FET gates
- Aside: With very high speed a chip like TC4420 high-speed MOSFET driver may be a good choice. But be sure to decouple it correctly, see here (“How to choose the right capacitor type for a circuit?! Film vs. Ceramic vs. Electrolytic”, a very recent Adafruit blog note (today!)). This would also go for C8 and C9 I guess
- X6 (from the not activated output REL3.6 of relay REL3) could perhaps just have been connected to 5V_OUT and then one could have inverted the logic. C2 would have needed to be fast charged (instead of fast discharged), but from where? Is there a Catch-22 here? I did not spend any more time on this, since that relay contact REL3.6 was available
- How to create your own usb watchdog script by David Gouveia (2018). It pulses a “USB watchdog” that’s easy to find by searching for just that. As Gouveia, I didn’t set up a url, for me because I didn’t know the original manufacturer