• ### Instead of a barrel connector try...

08/07/2019 at 15:06 1 comment

I never understood why many PCB projects continue to use barrel power connectors for 5V supply. Here is what I prefer:

This is a female micro USB connector on a tiny breakout board that you can buy for 10 to 20 cents each quantity 10. The inter-hole spacing is 0.1 inch and this board can be placed flush on top of a reserved space on the edge of your PCB and soldered in place with a couple of wires for the power and another couple for the shield connection. You don't have to use the data lines.

USB wall warts are widely available, you probably have a few in your box from old mobile phones, as are USB to micro USB cables. Sure a barrel connector can handle higher current but seeing as phone chargers and connectors often go up to 2A, that's enough for most small projects.

You can buy the female connector by itself cheaper if you are up to soldering those 0.05 inch spaced pins. Just make sure you have the connector picked out before you select the PCB footprint as there are various shapes.

• ### Correctly truncating a binary counter sequence

I was working with a 7493 counter last night. This is a TTL 4-bit counter with a two independent sections, a divide by 2 and a divide by 8. It also has two reset to 0 pins which are ANDed. You can use it as a divide by N counter where N is less than 16, provided N doesn't have more than two 1 bits in the binary representation. So to divide by 6 you would reset at 110.

I wanted to divide by 12 so I decided to divide by 6, then divide by 2, so that I would have a 50% duty cycle waveform on the last output. So I connected the reset pins to bits 1 and 2.

The first section did divide by 6, but the second section stayed at 0. I tried several chips with the same symptom so not just one bad chip. What was happening?

After a while I realised that the count sequence was:

0000, 0001, 0010, 0011, 0100, 0101, 0110 -> 0000

So the divide by 2 section never reached 1.

The correct way is to divide by 2, then divide by 6, and to connect the reset to bits 2 and 3. The sequence then becomes:

0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100 -> 0000

I have to give up the 50% duty cycle, but that's cosmetic. My mistake was taking the meaning of independent too far. The counters do work independently except for the reset function. Sometimes concepts can be oversimplified.

• ### TI website 404 page

Screenshot of a diagnostic I got clicking on a dead link. I thought it was amusing, that's all.

• ### A review of Elecrow's PCB service

When I saw on PCBShopper, a PCB fab price comparison site, that Elecrow was having a EOFY sale of USD0.99 for up to ten 100x100 mm boards, shipping extra, I decided to sample their service. (This sale, until 23/06/2019, appears to be available to all, not just new signups, but can only be availed of once.)

First of all I should mention that my project is not demanding at all, it uses THT components on a 0.1 inch pitch grid. It does however have quite a few chips, and 66 nets.

This time I sent in my first design using Kicad (eeschema, pcbnew and freeRouting). I had already debugged the circuit on a breadboard and also double checked using the Design Rule Checker (DRC) and the very useful Highlight Net feature of pcbnew. The latter is the desktop equivalent of doing a continuity check on the wires in the schematic, and will guard you from rookie errors like forgetting to connect the (invisible) power pins of a component.

Elecrow's PCB order page has the usual selection of options. I took the cheapest options which were all I needed. You also specify a Gerber package (zip or rar) there. I didn't find a link to a Gerber viewer but there are many online viewers elsewhere. There is an instruction page explaining how to order, and the technical parameters. As soon as you have entered all the parameters and uploaded a Gerber file, you will be asked to pay, by credit card or PayPal. This is in contrast to my previous fab (PCBWay) where it underwent checking by a staff member before I was emailed to start the job by paying.

After I had paid, I received email thanking me for my order. After a while my account page showed the order In Production. No other feedback. I supposed this was good and meant that my job had passed the design rule checks, but can be disconcerting if you were expecting some feedback.

My job stayed In Production for a week, even though such jobs normally take only 2 days. There was no progress display. It's possible that they assigned jobs from the offer a low priority. Elecrow is not just a fab but also do assembly, and make modules. For \$1, I can't complain. So I just busied myself with other stuff.

A week later, I got an email saying that my order had shipped, with an attached photo of the package just before insertion into a parcel bag.

I had taken the cheapest postage option, PLT Express, (did I already mention I'm cheap? 😀) so I was prepared for a long wait. But I was surprised a week later when I was notified that the package had cleared customs and would be delivered in a day or two. And so it was. From submission to receipt was just over 2 weeks, a nice surprise. It turns out that PLT Express is run by DHL. I wonder why if Elecrow can get the service that cheap, the other fabs don't use this service. Postage charges may be different for other countries.

The package was a sealed bubble wrap one, and contained 11 boards, 1 spare just in case. (Wonder if one would get 6 if one ordered 5?)

So how is the quality of the boards? The front copper side:

The back copper side:

I have absolutely no issues with their work, they did a good job and merit the review stars they have on the PCBShopper site. It's just that their customer facing site is not so polished.

Well it took me a while before I assembled it and then some procrastination before I worked up the courage to power it up (did I draw the schematic correctly, did I use enough bypass capacitors, and all sorts of worries) but it works fine.

A clock using the DS1287 as RTC. Two IC positions are not populated as those are used if one wants to drive multiplexed LEDs directly. U7 is a boost voltage converter for driving strings of LEDs in larger displays.

But there are lessons I will take to the next Kicad design. I should probably put the mounting holes in the schematic instead of just the PCB so that they can...

• ### Using freeRouting with Kicad 5

I was not looking forward to the manual work of routing traces in pcbnew (Kicad 5) so I started looking for autorouters. In Kicad 5 this is currently done externally, whereas 4 had a builtin autorouter.

Now I know this is a controversial topic because the best human routers can do better than an autorouter but you can always use an autorouter in the beginning until you get better. Or you can tweak the results of the autorouting. Sort of like the arguments over C versus assembly decades ago I think. Well, we know which language is used more now.

I tried freeRouting last night on a small board with about 60 nets and it did everything automatically, using 5 vias by the end. Well I moved the ICs to where I judged would be the best locations before starting which helped.

I made this shell script wrapper so that I can call it with or without a DSN file as the argument. If no argument is provided, it opens up the file browser. The advantage of providing a DSN file as the argument is you don't have to traverse the directories to find your project.

```#!/bin/sh
if [ "\$1" -a ! -r "\$1" ]
then
exit 1
fi
exec java -jar /opt/layout/bin/freeRouting.jar \${1:+-de} \$1```

(Yes, I know, this script won't handle spaces in the filename gracefully.)

A heads up, don't use Unicode characters like Ω or μ  in symbol values. freeRouting can't handle it, presumably due to not being compiled for Unicode, perhaps for another charset like ISO8859.

Another gotcha is if you create mounting holes using the mounting hole symbol, you need to assign each hole a unique reference, otherwise pcbnew's Spectra DSN format exporter complains. You should make the references invisible so they won't appear on the silkscreen. This is strictly speaking not a freeRouting issue.

Here are a few things I learnt using freeRouting:

• Symbol placement is paramount. By arranging the components in positions that make the most sense in terms of signal flow, you can minimise the trace length and number of vias needed to connect them together.
• Don't be afraid to alter the position of components to achieve the above. For example if a CPU has data pins that go to peripherals on one side, then move those peripherals close to the CPU.
• Don't be afraid to reposition components for more logical routing to make the traces shorter. For example components can be rotated to eliminate crossovers.
• If you have multi-unit ICs like logic gates, you can change the unit that is used in particular places for better routing. Go to eeschema, swap around the unit letters of particular gates, then Update the PCB and you will get a changed rats nest.
• For components like 8-bit latches and buffers, you can even change around the assignment of the bits to address or data lines for better routing. Just because the pin is labelled D0 on the symbol doesn't mean you have to use it for the lowest bit.
• If you find an execution of freeRouting is faring badly in optimisation, i.e. has lots of vias, abort it and try again. Optimisation is sensitive to the first traces attempted which appear to be random. If a bad initial choice is made, it's hard for freeRouting to discover a better layout later on. I had one design which got down to 2 vias. When I ran it again, it ended up with no vias.
• Every time before you export a new...
• ### Make 5V power supplies from surplus power adaptors

If you are like me you will have accumulated surplus power adaptors for all kinds of things, modems, external hard disk drives, and so forth. Here's how to put them to use and avoid causing more 5V power adaptors to be made.

5V has become a common standard for chargers and digital circuits. On eBay you can buy buck voltage converters that take 6-24V input and output 5V at 2A or more for about a dollar. As a bonus they have a USB A socket on the board ready to receive a USB cable. They are small, only a little longer than the USB socket. You just need to solder the input wires onto the board (double checking polarity first) and it's ready to use. Here's one powering a Raspberry Pi 1B.

The primary current drawn depends on the input voltage and the output current. Assuming 90% conversion efficiency, the formula is:

So for a current draw of 2A and an input voltage of 12V, the input current is just under 1A.

One thing to be aware of: If you are using the input voltage for other purposes at the same time, the negative lines of the input and output are common, there is no isolation.

• ### My experience using a PCB fab service (Pcbway)

When I counted a dozen 8085 CPUs in my retro tech stash, I decided to do a SBC project with them. The goals would be to learn to order PCBs online, and several other things. Coincidentally about this time a Pcbway rep contacted me asking if I would like to sample their service and post public feedback.

The design I submitted is not mine, it's a completed 8085 SBC design published by Sergey Kiselev, see my project page for the links. This means I am confident that there are no mistakes in the placement and routing. It is not a complex design, only a handful of ICs due to the use of a GAL to replace a lot of discrete logic, two layers, 0.1 inch pitch ICs, and through hole components. One step at a time; I'll learn to use Kicad/pcbnew for my own designs later.

A personal note: A PCB fab service over the Internet is something only dreamt of back in the days when I started making PCBs, first with resist pens, then later with photoresist, while dealing with noxious chemicals like ferric chloride and xylene. Well the Internet didn't even exist then. The disadvantage of course is the turnaround time so you should be fairly sure of your circuit before you commit to PCB. The old tailor's or carpenter's adage measure twice cut once is very apt here.

## Submitting the order through the website

Like many fabs, registering an account on the Pcbway site will get you starter credit.

At this point assume you have breadboarded and debugged your circuit, have laid out the PCB and are ready to generate the Gerber and drill files.

The website is attractive and the steps are easy to follow. Just click on the Quote and Order button and it will take you through the steps. There are help buttons for the various entry fields. Pcbway seems to offer a great variety of options for the boards. I accepted the defaults as I have no special requirements. Maybe one day I'll design boards requiring advanced features. Like other fabs, the magical size 100x100 mm (from the limit of the free version of Eagle EDA, Kicad EDA is always free and has no limit) has special pricing, so usually people start with 5 or 10 boards within this limit.

I noticed that Pcbway offers to upgrade you from HASL (Hot Air Solder Levelling) to the more expensive ENIG (Electroless Nickel Immersion Gold) at their discretion for no extra charge. This Pcbway page explains the two technologies. Searching on those acronyms will find you more explanations. You can veto giving them discretion if you wish.

For Kicad 5 the documentation of pcbnew explains how to generate Gerber and drill files and can also be found in Pcbway's tutorial. For other EDA software there are abundant tutorials on the Internet. Package the generated files (usually 9) as a zip archive and upload to the website.

At this point Pcbway will do a review of the files. Now I uploaded on a Sunday night so either they have software doing the checks, or there are reviewers working shifts which is plausible as a big fab like Pcbway must get a continuous stream of orders from all over the world, thanks to the Internet....

• ### Things I want to learn, a wishlist

I hope to move things from this list to the one below.

• Learn to solder TSSOP packages
• STM MCUs
• PIC MCUs
• AVR MCUs
• ARM MCUs
• ESP MCUs
• CPLDs
• FPGAs
• SMD boards
• Use up the retro components in my stash
• Use the nixies I have
• Make things with the discarded technology I scavenged
• ...
• A robot that will do all the housework, and amuse the cat. I mean that would be the greatest step towards world peace. 😁

## Things I have done

• Restored past projects in my junk box
• Arduino
• 8042/8048 MCUs
• 8051 MCUs
• TM1637 two wire interface
• I2C
• SPI
• Various displays: LED, OLED, LCD, TFT screen
• Rotary encoders
• Small Device C Compiler
• Ordering PCBs from a fab
• GALs
• eForth

Still no big project in mind, just building skills, nothing that I really need or fancy, so I guess I'm contented.

• ### Garner oscillator

The Garner oscillator is a simple oscillator generating digital ready output that requires only a complementary pair of transistors and a few other components. It features:

1. Very sharp edges.
2. High fan out.
3. Very low duty cycle.
4. Frequency depends on a RC pair.

It was first invented by Lou Garner in or before 1960 when germanium transistors were current. The original circuit relies on germanium transistor leakage. It works reliably with silicon transistors with R2 added. Various people have rediscovered it over the years. Michael Covington experimented with it at length in 2005. gusshh did a take on it in 2011. And in the same year there was a discussion thread on with a good description of the mechanics. I'm sure there are other pages on the Internet that I can't find simply because it has not been named as Garner Oscillator. I've decided to collect the information and present it here.

Here is a blow by blow description of a cycle.

1. Initially both Q1 and Q2 are off.
2. C charges via R2 and R3 until Q1 base reaches about 0.6V below the positive rail.
3. Q1 turns on and the current through R1 turns on Q2.
4. The current through C turns on Q1 hard which also turns on Q2 hard. Q2 collector drops to nearly the ground rail.
5. C charges to roughly the supply voltage.  The current through C eventually drops to a level insufficient to maintain transistor conduction and Q1 turns off, which also turns off Q2. Q2 collector rises to the positive rail.
6. The voltage at Q1 base rises to roughly twice the supply voltage, and the base-emitter junction is reverse biased. C discharges through R2 until the voltage drops to 0.6V below the positive rail, and the cycle repeats at step 3.

It can be seen that the waveform at Q2 collector is at the positive rail nearly all the time, except for sharp spikes to the ground rail during steps 4 and 5.

A simulation with the Falstad online circuit simulator yields these waveforms on two scopes. The upper graph is Q2 collector voltage with spikes toward ground, and the lower graph Q1 base voltage with the exponential discharge of C.

Since the duty cycle is extremely low, the period is determined by the time constant R2*C. To a first approximation f = 1/(R2*C). A better approximation is f = 1.2/(R2*C). The values used above give a frequency of about 120kHz. The slight irregularity of the spikes is probably due to some spikes partly falling outside the sampling period of the simulator.

## Points to note

• The ratios R2/R1 and R1/R3 should be less than the gain of the respective transistors so that both transistors can turn on hard. This is easy to achieve, the sample values give a ratio of 10.
• It's best to make large changes to the frequency by changing C, and make small adjustments by changing R2,  roughly maintaining the above ratios.
• R3 can be quite low (provided the ratios are maintained). It can even be a low impedance speaker. The waveform is highly asymmetrical but makes a suitably loud sound. If your oscillator needs are already fulfilled with (parts of) digital chips, this is probably the major application for this circuit. Another possiblity is to drive a charge pump.
• If you need a symmetrical waveform, follow the circuit with a binary divider to square up the waveform. Naturally the frequency is halved.
• Q1 base-emitter junction is reverse-biased for most of the cycle. Typical reverse breakdown voltage of Si transistors is 7V, but some transistors have lower limits. So this circuit is not suitable for higher supply voltages.
• The voltage across C alternates, although one excursion is limited to about 0.6 volts. So a non-polarised capacitor should be used.

Here is the input file for the Falstad simulator. Cut and save this text into a file and in Falstad, Open File.

```\$ 1 1e-8 7.619785657297057 42 5 50
t 880 480 864 480 0 -1 -0.7088525300036439 -0.7269275184984805 100
r 864 496 864 560 0 4700
r 1008...```
• ### Teasing a few GPIO lines from a UART

So you have an old microcomputer board that has a UART but no PIO. Maybe one like mine. No chance then of driving a couple of digital I/O lines unless you add a PIO chip?

Hmm, let's look at the data sheet for the Intel 8251, a typical UART of a bygone era. Here's part of the page describing the modem lines.

These lines were intended to for handshaking between the UART and the data set. In the past this meant the modem, but these days it could be a PC talking to the microcomputer through a serial interface.

If you are don't require handshake, then DTR and RTS can be used as output lines, and DSR can be used as an input line. CTS is an input line, but is not directly readable by the CPU, it only has an effect on the transmit buffer.

Let me cut to the chase. It works.

And here's a short video of it in action. The test setup on the Arduino Uno uses pins 2-9 to drive the data pins of the UART, A0 to drive the Control/~Data line, A1 to drive the ~Read line, A2 to drive the ~Write line and A3 to drive the Reset line. On a MCU board these would already be part of the circuit and you just have to program the UART appropriately.

Here is the program:

```//
// Drive 8251 UART with Arduino
// Pins 2-9 are connected to D0-D7
// Pins A0-A3 are connected as #define below
//

#define CNOTD A0
#define WRITE A2
#define RESET A3
#define DTRBIT 0x02
#define RTSBIT 0x20

byte cmdinst = 0;

void init8251()
{
pinMode(CNOTD, OUTPUT);
pinMode(WRITE, OUTPUT);
pinMode(RESET, OUTPUT);
digitalWrite(CNOTD, HIGH);
digitalWrite(WRITE, HIGH);
digitalWrite(RESET, HIGH);  // RESET
delay(1);
digitalWrite(RESET, LOW);  // release
delay(1);
writecmd(0x4e); // mode: x16, 8 bit, 1 stop bit
writecmd(0x10); // command: error reset
}

void writecmd(byte b)
{
for (byte i = 2; i < 10; i++) {
pinMode(i, OUTPUT);
}
for (byte i = 2; i < 10; i++) {
digitalWrite(i, b & 0x1 ? HIGH : LOW);
b >>= 1;
}
digitalWrite(WRITE, LOW); // pulse /W
delayMicroseconds(1);
digitalWrite(WRITE, HIGH);
}

{
byte b = 0;
for (byte i = 2; i < 10; i++) {
pinMode(i, INPUT_PULLUP);
}
delayMicroseconds(1);
for (byte i = 2; i < 10; i++) {
b >>= 1;
b |= 0x80;
}
return (b);
}

inline void dtr0()
{
writecmd(cmdinst |= DTRBIT);  // /DTR = 0
}

inline void dtr1()
{
writecmd(cmdinst &= ~DTRBIT); // /DTR = 1
}

inline void rts0()
{
writecmd(cmdinst |= RTSBIT);  // /RTS = 0
}

inline void rts1()
{
writecmd(cmdinst &= ~RTSBIT); // /RTS = 1
}

// First test program
//
{
dtr0();      // /DTR antiphase to /RTS
delay(500);
for (;;) {
dtr1();
rts0();
delay(500);
rts1();
dtr0();
delay(500);
}
}

/*
Second test program

Program for displaying counting from 0 - 9999 modified from
www.funwidelectronics.blogspot.in

This source code is modified from :
https://blog.3d-logic.com/2015/01/21/arduino-and-the-tm1637-4-digit-seven-segment-display/

Thanks for the code
*/

#define clk0 rts0
#define clk1 rts1
#define data0 dtr0
#define data1 dtr1

byte digits[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f };

void start(void)
{
clk1();
data1();
delayMicroseconds(5);
data0();
clk0();
delayMicroseconds(5);
}

void stop(void)
{
clk0();
data0();
delayMicroseconds(5);
clk1();
data1();
delayMicroseconds(5);
}

bool writebyte(byte value)
{
for (byte i = 0; i < 8; value >>= 1, i++) {
clk0();
delayMicroseconds(5);
if (value & 0x1)
data1();
else
data0();
delayMicroseconds(5);
clk1();
delayMicroseconds(5);
}
// wait for ACK (not available in this implementation)
clk0();
delayMicroseconds(5);
//pinMode(data, INPUT);
clk1();
delayMicroseconds(5);
//bool ack = digitalRead(data) == 0;
//pinMode(data, OUTPUT);
return true;
}

void writenumber(...```
• ### Ancient digital clock revived, and a project box

Among the old projects in my junk box was a digital clock I made in the late 70s, using the National Semiconductor MM5371, a one chip clock.

Back in the day I used an iron core transformer to supply power. I decided to replace this with a wall wart supply supplying 15V AC that used to power a modem, so that I wouldn't have to worry about exposed mains wires. This required some rework of the rectifier circuit. (I can't power it from DC, I still need the mains frequency reference.)

I fixed up the inevitable breaks and dry joints. Fortunately none of the electronics had failed, only my lousy soldering of the time.

When I powered it on, all the segments lit up., some more than others Although a semi-blinking PM LED indicating power fail seemed to indicate that the clock chip was intact. This puzzled me greatly and I set the project aside for a few months.

Eventually I looked at the circuit again. The MM5371 is interesting in that it can drive multiplexed 7-segment plasma displays directly. Even though it's implemented in PMOS technology, it holds off fairly high voltages, up to 45V, see this datasheet extract.

This is sufficient margin between the firing and sustaining voltage of plasma displays to turn them off. The voltage level translation is done by capacitors, you'd have to look at the reference circuit to work it out. Trust me. 😊

Here is the internal drive transistor:

Two observations emerge from these specs:

1. The digit anode outputs go towards Vss (positive) to turn on. This makes sense as the digit drive is connected to the anodes. However the segment cathode outputs go towards Vss (positive) to turn off. Again this makes sense as the cathode voltage must be drawn closer to the anode to extinguish the glow.
2. The logic level of high is not quite Vss, and is a minimum of Vss - 5V. This had implications for the circuit I designed decades ago.

To drive cathodes of the LEDs I had NPN transistors driven from the digit outputs, sinking current. To drive the anodes of the LEDs I had PNP transistors being turned off by the segment outputs, sourcing current. In other words a common cathode display.

All well and good, but I had neglected the 6th line of that datasheet extract. The open drain has a fairly high on voltage, up to 5V. This is not enough to turn off the PNP transistor; less than 0.6V is required.

Why hadn't I encountered the problem decades ago? I remembered that I had two positive voltage rails, a fairly high 18V rail to supply the MM5371 and a lower 9V rail for the LEDs. In that circuit, the PNP transistor is biased negative when turned off. With a single rail in my new configuration, I didn't have this offset.

Quick fix: I inserted a zener diode in the LED supply so that the PNP transistors could properly turn off.

You'll notice some other circuitry on the small PCB. Those are alarm and PWM brightness control options using 555s which I never implemented. The driver transistors are on the display board. I sprayed painted the board black to have maximum contrast. The digits are 5 cm high. Now I have to find a casing for it, something I never go around to doing. Presentation isn't my strong suit. 😊

Other for the facts that the MM5371 is out of production (any you find these days on eBay are old stock for replacements and command high prices), and that the PMOS technology requires higher voltages of 21-29V, it's still a compact 1 chip solution. Pretty good for a chip that came out in 1977. I still have a few MM5371s. I might consider making more large display clocks, this time with super bright LEDs. Or sell the chips on eBay and retire. 😊

## Update

I prefer the look of wood to plastic so I'm not keen on using 3D printing plastic project boxes. A search showed that 3D printing of wood has been developed. But this got me thinking, why not cardboard...