Friday, February 2, 2024

Fuck KiCAD - at least for now.

I want to use KiCAD.  I really do.  But I can't, and neither should you.

If you don't need a lesson in what EDA is about, skip ahead about five paragraphs, otherwise keep reading so you get enough background to understand what's wrong here.

What the hell are you talking about?

Open-source EDA (Electronic Design Automation) is almost a magical thing that we've dreamt of for decades and which, by some celestial intervention, has become a real thing.  Electronic CAD is a really complicated and unique animal - entirely unlike CAD for ordinary solid objects - because it has to bridge two worlds, the logical and the physical.  For every little black plastic "chip" you see on a board, there are (and I'm not exaggerating here) anywhere between one (1) and ten billion (10,000,000,000) gates inside it.  (I'm kind of fudging here because while you can check wikipedia for the highest transistor-count device - around 150 billion at the moment on a single chip - the number of transistors per gate varies, and I don't know if there's a generally accepted multiple.  Doesn't matter, you get the idea - a whole buttload.)

I don't want to get into the weeds, but what you need to understand is that since the advent of the integrated circuit, our designs haven't started with the physical chip you see on the board, but with the multiple logical functions inside it, and figuring out which logical function (the inverters and gates and the slightly larger things you make from inverters and gates, like counters) is going to be in which physical "package" is something that's usually decided later in the process.

So since the logical and the physical exist in two different design realms, you need tools that understand the correlation between the two.

Follow along;  If I lay down a little gate symbol on the schematic diagram that is the beginning of the design process, the CAD system needs to know how those symbols relate to the physical chips in order to "package" the design when it moves from the logical world of the paper schematic to the physical world of the fiberglass printed circuit board.  If I put a hundred gates in my design, and each chip contains four gates, obviously I'll need 25 gate chips - but much of the work is in figuring out which gate goes in which chip in order to simplify the connections between them, because 100 gates means 300 inputs and outputs, and each chip has 14 pins... you get the idea - you have to wire the chips to each other efficiently or it turns into a tangled mess.

So the key to the entire enterprise is what's called the "netlist", which is a database that keeps track of all those logical connections as you're drawing the schematic, and which, during the "packaging" stage, adds to that information the chips and pins stuff so that the connection information is maintained as you lay out the circuit board.  And since designs are always evolving, being revised and corrected, the system has to keep track of changes that occur in the schematic so they can be carried through to the PC board - and changes in the board design that need to be propagated back to the schematic so that the schematic, netlist, and board layout are always in 100% agreement with each other.

At least, that's how it's supposed to work.

Back to KiCAD.

So along comes this French guy in '92 and he's come up with a schematic package and some other stuff and that eventually forms the core of the KiCAD suite of tools.  And about 20 years later CERN starts throwing money and time at it and in a few more years it catches on and eventually joins up with the Linux Foundation, and because it's the first real free and open-source EDA suite it really catches fire because for the better part of 40 years everything has been commercial software at prices anywhere from a few hundred bucks for low-end PC stuff to hundreds of thousands for a really sophisticated suite running on a Unix workstation - Sun, HP, etc.

And this is, in theory, a really good thing, because for more than 35 years I've been using a number of those commercial packages - including the one that's been on my desk for nearly 25 years - and I felt that it was time to get updated.  Using the same software as a lot of the people around me would allow us to share and build upon each other's work or even just check and correct or offer revisions, all of which are highly desirable.  Also, the system I'm running is on a big old Unix workstation - not very portable - and KiCAD would have the extra benefit of letting me work anywhere on a light little laptop.  That'd all be so great - and for free - can you imagine?  Is this heaven?

So I did a fresh penguix install on an old laptop, stuffed in KiCAD (after receiving a recommendation from a trusted friend that the version that had been released in early 2023 was really ready for prime time), and thought I was made in the shade (note: I don't usually pack that many rhymes into a sentence).

Making a switch like this always comes with a learning curve, and I knew this would be no exception, so I started with an easy design:  A circuit board originally designed by someone else more than 40 years ago, part of a system that hasn't been made for many years but is still needed by a select few.  I was going to do a "reproduction", and as a board that's in no way challenging by modern standards, it promised to be a fast, easy, and relaxed way to learn the software.  A couple of hours into the initial schematic entry, I had to edit a symbol, which is a perfectly routine operation.  You find a mistake in a symbol and want to correct it, or just move some parts of it around in order to better suit its surroundings.  In this case, a 555 timer, which anyone - even the most novice hobbyist - who's built any hardware since the mid-70s will recognize.  The stock symbol (that came with KiCAD) was just wrong - it didn't respect the normal "inputs on the left side, outputs on the right side" convention that we try to adhere to for logical flow and readability, no different, really, than the Western convention of reading left-to-right.  So I fired up the symbol editor, moved the pins and their names around to where they should be, found that the editor had a couple of nice features I hadn't ever seen before, and returned to the schematic, where I got a shock.

Pay attention - this is where it goes to shit.

Before editing the symbol, I'd connected some signal lines (wires) to its pins - let's simplify this by saying I connected wire 1 to pin 1 (on the left side of the little symbol box), and wire 2 to pin 2 (on the right of the box).  Those pins have specific functions, and they were in the wrong places on the symbol - the one on the left should have been on the right, and vice versa.  So that's all my little edit was - swapping the two.

Having swapped the pins, the wires should have stuck to the pins they were originally connected to:  1-1 and 2-2.  But that didn't happen.  The wire ends had stayed where they were, so now wire 1 was connected to pin 2, and wire 2 to pin 1.  What should have happened was each wire staying connected to the pin I connected it to.  Instead, those two connections were swapped.

This would not happen if the schematic software understood, respected, and maintained the connections the designer originally made.  A properly-functioning system would have, after the edit, kept wire 1 with pin 1 and wire 2 with pin 2, with the wires stretching (what we call "rubberbanding") across the symbol body to their proper pins.  It looks a little messy, but it maintains the design's integrity and is easy to clean up (that is, to restore orthogonal routing, as we say).

This is very bad, because where modifying a symbol is just a cosmetic operation meant to improve the organization of the drawing, not maintaining correct connections trashes the netlist (remember, that's the database of connections, and what the schematic is about) and in turn introduces errors into the board layout, and in days or weeks, after this schematic has passed through the PCB layout process and manufacturing and come back as a completed assembly, it wouldn't work because the connections were wrong.

Now, you may be thinking "What are you making such a fuss about?  Isn't editing a symbol an edge case that's outside of the normal schematic editing process?"  A perfectly reasonable question to which the answer is:  No.  In the normal course of events, a symbol - depending on its size and complexity as well as those of the surrounding schematic - can be modified (everything from a little tweak to a major overhaul) dozens, or even hundreds of times.  But where the rubber really meets the road is that this failure extends to the schematic itself.  You put down your symbols, you spend hours wiring them up, and when you have to move a symbol (that's "when", not "if") it leaves all of your connections behind, dangling on the page as though you never connected them at all.  (That is, apparently unless you're using drag rather than move, itself a problem because these guys also suffer from the million-monkey-malaise - that everyone who thinks he has a Great Idea (tm) adds another command to a list that's already way too long rather than someone cracking the whip and saying "No, we have too many commands and too many menus and/or hotkeys to get there, so start paring it down and rationalizing it."  I mean, their pull-down menus alone are out of control; when you click on a button and it opens a menu that has dozens of commands that extend below the bottom of the screen, you should realize you have a problem.)

A brief treatise on drawing schematics.

It's awfully simple, really.  In schematic capture, connections (between wires and pins or between wires) can't just "happen" or "unhappen".  That is, a connection or disconnection cannot be an inadvertent byproduct of some other operation, like moving a component.  The creation or removal of connections need to be explicit acts - you're telling the software in no uncertain terms that this is how you want it wired.  And as I explained, when you make a connection, it sticks to the pin, so if the two move relative to each other they remain connected.  In practice, when you move something, the result is often a rubberbanded line that crosses an unrelated pin, line, or vertex (a bend in a line), and it's critical that the software doesn't do something stupid like connect them together just because they've touched.  Instead, it should place a marker warning you that though these may appear to be connected, the netlist says you didn't intentionally connect them, so you need to clean them up.  Strict observance of the netlist.  If you didn't connect it, it's not connected.  If it's connected, it stays that way until you disconnect it.  How hard is that?

For KiCAD, it turns out, really hard.   Move something and connections break.  Or they connect where you had no intention of a connection being.  Its "boosters" say "well, so you just have to carefully proofread your schematic before moving through to PCB layout," to which I say "what the hell is wrong with you?  My system maintains the netlist so I don't have to scrutinize hundreds of lines on the drawing to catch mistakes because it prevented me from making them in the first place."

Now, back to how editing a symbol broke the schematic.

So, since this represented a failure of the most basic function of a schematic capture package - MAINTAINING NETLIST INTEGRITY - I figured I must have made a mistake, perhaps missed a step like clicking on a button that tells it that I've just modified a symbol, so please merge the changes and update the drawing.  But I couldn't find anything like that, so I took the next step, which was to sign up to the forum and ask how to do it.  Which I did.

And you'd think that I'd just fucking invaded Poland.

Because what followed was an online war of more than a hundred heated exchanges in which most of the skilled and experienced KiCAD users, after telling me I'd done everything correctly, explained that it was behaving as it should.  Which, I carefully explained to them, is complete bullshit, which turned me into a war criminal.

To be fair, there were actually a few (well, maybe a couple) who had extensive enough design experience to understand what I was talking about and agree with me.  But the rest?  Fucking delusional.

Here's just one argument I received from topsy-turvy world:

"The main use of a schematic is to have a visual representation of a circuit that humans can interpret. That it can also create a netlist is a secondary goal...

It’s the same with programming. If I write a C++ program, the goal is to write text that is human readable and understandable... That the text is also supposed to pushed though a compiler is only a secondary or tertiary goal."

His initial argument does have a fragment of merit in it, but only outside of the EDA context.  If you draw a schematic, and then hand-wire a prototype, anything in that drawing that looks like a connection to you, while you're building it, is a valid connection.  In fact, I've done this a lot.

But it's completely out to lunch if the schematic is the means of human-friendly data entry for information that will then be fed into a pipeline of software tools, including the netlisting, packaging, and layout I described previously.  And you get a glimpse of confusion in extremis when he tries to carry this argument into programming by claiming that the primary reason for writing software is for people to read it, not for it to be turned into executable code to run on an actual computer.  How can you even communicate with someone like this?

To summarize, then, KiCAD's schematic capture is a joke.  What looks like a connection, and you may think is a connection, turns out not to be one at all.  It's a faux connection, one that looks connected but really isn't.  Instead, it's just coincident points in space that have no actual significance to the schematic capture system.  It's up to some downstream netlisting tool to extract that meaning, but by then you'll have had hundreds of opportunities to introduce errors into the diagram without the software doing its job, which is to try as hard as it can to keep you from making those mistakes by understanding the nature of what you're doing.

And that's why - unless and until someone I trust tells me that they've changed their tune - I won't be wasting any more time wallowing in this dumpster fire.  One of the developers who was involved in that fray made it clear that what I was suggesting "isn't [their] paradigm", but he didn't explain what their paradigm is, if in fact there is one.  Put that together with a comment from someone about the coming revision of the software having 500 commands, and you get a clear picture of the worst aspects of an open-source project:  Badly thought out software completely out of control.  Which is a damn shame, really, because for all I know they may have an outstanding PCB layout package.  But since the schematic comes first in the design flow, as long as it stays fucked I'll never get the chance to find out.

And it's becoming an industry standard, not just because it's free, but also because:

Open-source software users tend to exhibit cult victim behaviour

This is fairly easy to understand.  Open-source developers, who in general, are unpaid (at least initially) and doing the work purely for idealistic reasons, are viewed as being morally superior to the "code whores" being paid to write software for for-profit companies.  Similarly, those companies are tarnished by being motivated simply by "filthy lucre" rather than... I dunno... the intrinsic nobility of the art?  Of course, if the users of that software want to adopt that view, there's not a lot you can do about it, nor does it really matter - they're entitled to their own opinion.  But in their fanaticism, there's a tendency to view the product of that morally superior process as technically superior as well, one conferring the other, regardless of how it actually stacks up against "competing" or "comparable" commercial packages.  Such a conflation is, of course, ludicrous, but just try to make that argument and someone is likely to suggest that "perhaps this software really isn't for you" in the tone of voice that strongly implies that you're a heretic about two posts away from being stoned to death (I know because it happened to me).  It's a short leap from idealism to zealotry.  Come for the free software, stay for the brainwashing that this is the One True Way and without sin.

But lots of KiCAD users design good circuit boards, so where's the harm?

I've only recently figured this out.  By chance I found myself redrawing a very bad schematic done in KiCAD, one that had been reverse-engineered from a small, simple circuit board, the original drawings for which had been lost.  I wanted to reproduce this board (I only needed one for my own use, so I artisanally wired it rather than fabbing a PCB), and the schematic was so poor that I had to refer to data books and other schematics and (even) photographs - in addition to a healthy dose of inference - in order to figure out the things that the drawing should have conveyed.  It was utterly chaotic - rather than providing a logical overview of the (very simple) circuit, with the signal flow left-to-right and top-to-bottom, with connectors on the periphery of the drawing, signals entered in the middle and went in all directions.  Where there were a couple of latches grabbing signals to light indicator LEDs, one flowed left and the other flowed right.  In a circuit trivial enough that I should have been able to take it in at a glance, I had to stare at and slowly unravel it in order to see how simple it was.  It pissed me off enough to put a couple of days into redrawing it properly so I'd have a good reference document for myself (and anyone else in the community who might want to build one), as a thank-you to the board's original designer, and as a lesson in how schematics are supposed to look.  Clearly, the guy who drew it had no idea what schematics are really about.

But I hadn't yet made the KiCAD connection.

Around the same time I built an unrelated widget - also for my own use - that had been designed by someone else using KiCAD.  The board was fine and I didn't encounter any problems in getting it populated and up and running, but his schematic was hard to follow because - rather than consisting of contiguous, unbroken lines connecting symbols together - many of the lines were stubs and fragments that had been labeled, indicating that they connect to similarly-labeled stubs and fragments elsewhere in the diagram.  This is really a pain in the ass - you have to waste time where's-waldoing around a drawing looking for the matching tags, and what usually happens is you get sick of it and break out the 10-colour hilighting marker set.  I've worked with extreme examples of this nonsense in the past - diagrams spread over dozens of nearly-empty B-size sheets and with almost no lines connecting the schematic symbols; instead, every line-end tagged to indicate which tag on which sheet it's connected to.  It was awful.  You spend all your time flipping back and forth between pages, trying to find the connections, and can't get a coherent picture of what the whole circuit actually looks like.

Slowly it dawned on me what these two schematics had in common:  They were bad because KiCAD makes doing good drawings harder - exactly the opposite of what CAD is supposed to do.  Because the software doesn't have any understanding of what a connection is, moving anything is going to break the drawing and result in wasted effort reconnecting what you'd already connected (or so you thought) - or looking for the connections you didn't put there.  Enough of that, and pretty soon you're just saying "Fuck it, there's no point in actually drawing these connections because they're just going to get trashed later.  So let's sidestep the problem by putting a label on a stub so there's no line to mess up."  Similarly, reverse engineering - even a simple circuit - is a lot of work because you usually just slap down the symbols, wire them up as you gather the connection information from the example PCB, then rearrange the drawing into logical sense.  If that rearrangement process is a painful one, you're more likely to just leave the symbols where they were, regardless of how incomprehensible the drawing is as a result.

So the lesson here is that: 

Bad schematic capture breeds bad schematics.

And that is how a gradual degradation of standards happens.  The more people adopt (and are conditioned to accept) shoddy tools, the more bad schematics will become the norm, and the new generation will come up without understanding how these drawings should look and function.

Finally (I hope?), a personal note:

Another result of the widespread adoption of KiCAD has been the pernicious European influence on our schematics.  I grew up reading Popular Electronics, but in the late 70s and early 80s I bought the odd issue of (the English magazine) Elektor and found the schematics not just foreign, but perverse (like German porn is to North Americans), so I'm going to exhibit a shameless North American chauvinism here:

Goddammit, we invented the electronics industry, and allowing the invasion of this software to drive a Eurotrash replacement of our symbols is not acceptable.  Resistors are fucking zigzags, not boxes.  Capacitors are curved, not flat.  And (default) grounds have parallel lines - if you want to lay down a triangle, it had better be a different ground.  So if you're in the US or Canada, show some fucking pride and use our schematic symbols rather than being a lazy piece of shit and letting these immigrants poison the blood of our schematics with their degenerate symbol libraries, motherfucker.


Saturday, December 4, 2021

Warts.

 (Originally posted April 23rd, 2019)

I mean warts - the actual skin growths caused by HPV.  This is a little outside of the scope of the things I usually write about (like I stick to a topic...), but it's been bothering me.  The treatment, that is, not the wart - it's gone, and that's what this is about.

A few years ago one appeared near my thumb's knuckle, just around the corner where the fingerprints start, and it bugged the hell out of me, because it was exactly in the right place to rub it with my middle finger, which for a fidgeter is a real distraction.  So I, predictably, asked my (terrific) GP about it, and he gave it a shot from his liquid nitrogen bottle and told me to use one of the over-the-counter salicylic acid-based wart removers until it was gone.  I failed at the followup - having to do it multiple-times daily was a pain in the ass, and the bottle dried up and I didn't get around to replacing it, and the wart just stayed.  On subsequent visits to the sawbones I brought it up again, and he froze it again, and we went through this pointless cycle a few more times.  Eventually he referred me to a hand surgeon, and after waiting months for the appointment was told by the surgeon (in about 45 seconds) that it was in a spot where there was too much flexing and stretching of the skin for surgery, so he wouldn't touch it.  And the stupid thing kept growing and I just kept it under control by snipping the top off, flush with the skin (with Snap-On's 710 flush cutters - my favourite for many years).

Ultimately I got tired of all this - the salicylic acid stuff didn't work and liquid nitrogen didn't work and hurt like hell.  So I brought up with the doc a little ancient medical history:  That I'd only once before (in my early teens) had a (plantar) wart, and that my then-GP had successfully dispatched it with a single application of fuming nitric acid.  Present doc had never heard of it, and was (and, I think, remains) skeptical, confident that time has distorted my memory and that I'm confusing nitrogen and nitric acid.  I've always been pretty sciency, so I reject that theory (though I do acknowledge how unreliable memory usually is).  I even contacted the clinic in my hometown where I'd had that treatment as a kid, but my records had, unfortunately, long since been purged, so I couldn't prove it to him.  He wasn't ready, willing, or able to supply the treatment I wanted, but I was shortly (by pure coincidence) introduced over coffee to a FOAF who worked in a local medical lab.  I explained the problem, and a couple of days later he slipped me a couple of mls of 70% nitric acid - perfect, since I only needed a little and didn't much want to have to buy a litre of the stuff from a chemical supplier (which would only tempt me to make nitroglycerine, right?).  It wasn't the 90%+ fuming, but it would probably do.  And it did - I applied the smallest possible drop (probably a µl) and a second drop a couple of hours later, then left it alone.  It caused a little burn, a little pain, and within a couple of weeks my thumb was all healed up, the wart gone and without recurrence to date.

What happened to this fast, cheap, effective treatment in the intervening 40 years?  You can search around the 'net and not find a trace of it being used in modern medicine.  About the only plausible theory anyone has offered is that the recent introduction of WHMIS (Workplace Hazardous Materials Information System) requirements simply made it too much of a hassle to deal with compared to liquid nitrogen, regardless of efficacy.

There's one footnote to this story.  Before trying the nitric acid treatment, I happened to be at our vet's office for some routine dog or cat thing.  I mentioned to her the problems I'd had with this stupid persistent wart, and she told me about having had great success using neoplasene for removing cancerous skin lesions in dogs, and gave me few mls of it.  She did say that it was a controversial (and unapproved?) treatment, and that simply acquiring it took some unusual steps.  Regardless of her endorsement, I was a little suspicious of this goo, having seen/heard a piece or two on "black salve", a caustic paste making the rounds in "alternative" (read: quack) medicine circles that has caused a lot of people serious damage and grief (iIrc, an episode of Botched featured a woman who, quite literally, destroyed her nose overnight with this stuff.  I won't get into further details on black salve here; you can google it yourself).  Sure enough, that's what the vet gave me, so that tube remains sealed on my desk; I trust her regarding having had good outcomes with dogs, but I'm not using it on me.

So the question remains:  How does modern medicine "forget" a treatment as good as nitric acid for warts?  And how many others have suffered the same fate?

Sunday, November 28, 2021

Young Brent, Catamaran Sailor

I shouldn't even be telling this story, because although I'm half of it, it's not really my story - it's Brent's.  But I don't know if he puts stuff like this down (in a blog or elsewhere), and it'd be a shame to lose it, because it's pretty good.

I've been sailing small boats most of my life; first dinghies at the Calgary sailing school, then Fireballs in the racing school (where I first fell in love with the trapeze), then back to a dinghy - my own first boat - for a couple of years, then finally to a Mystere 17 cat when I was 21.  Those first few years with the Mystere were pretty great, because I'd intentionally gotten a boat that I knew was a well beyond what I could handle, especially solo.  So while I was learning I constantly had friends out with me, and even pickup crew I didn't know, until I learned enough, sorted it all out, and tweaked the boat enough to really be able to hold it down alone.  And I became an evangelist, always happy to get the chance to take out people who'd never been on cats - or ever sailed at all - as well as the folks with experience.  And more than one bought cats themselves after sailing with me, which is a nice compliment.  But I'm not a drifter.  If there isn't enough wind for me to raise a hull and get out on the wire, I'm not much interested in rigging up.  I wanna get out there and jam.

It's now 2021 and I'm a bald, middle-aged greybeard git.  Two years ago I got a serious itch for a new ride (there have been a number of pretty exciting boats over the years), something that would present a serious challenge.  For a number of reasons I'll be sure to get into somewhere sometime, I settled on an old SuperCat 19 and made a (really great) road trip to Long Island NY to get it.  It's taking a couple of years to really get it together, and it still scares the hell out of me - it's a boat that seasoned beachcat sailors call "a handful".

So back in mid-July I took it out to Lake Newell (Brooks, AB) for a weekend.  There was a big regatta on with boats and sailors coming in from all over the place (province?); I don't race, but it can be fun to hang out and meet a bunch of new people, especially when you've got a bitchen ride.

I was out in the parking lot, stepping the mast, when another bald, middle-aged greybeard git strolled up, introduced himself, and said that he was on 14th St S in Calgary (very near the Glenmore Reservoir) a week or two previous and saw some old guy in a beaten-up black Subaru pulling a big cat with the Boston Whaler logo on it.  (At this point you need to know that for a couple of years in the early 80s Boston Whaler made the SuperCats, but in 1983 sold the works back off to Tom Haberman, who's been building and supporting the SuperCat and ARC catamarans designed by Bill Roberts ever since at Aquarius Sail in Minnesota.  Fantastic guy, fantastic boats.)  He said that what was surprising was the "Boston Whaler" part, as he didn't know they'd ever built cats.  After I finished giving him shit for calling me "some old guy",  he went on to say that when he was 15 (about 40 years previous, and making him about six years my junior), he had a Sea Spray, a single-hand 15' cat that used to be very popular around here.  He said that whenever the wind really came up on Glenmore - enough to make it exciting - all the other boats would pack up and go home... except for him and one other guy on a Tornado, just the two of them left, giving it the business.

And as he told this story, it was familiar, because that's how I've described sailing over the years - we're the guys who go out when everyone else is calling it a day because the wind's too high.

So I told him "Yeah, that sounds about right, except for the "Tornado" part, which is an understandable mistake, because the Mystere is a slightly scaled down Tornado that was designed as a trainer - they look a lot alike.  That was me.  So why the hell didn't you ever ask to come aboard?  I would have put you on the trapeze and we would have had a gas."

When he regained his composure, he said "What can I say?  I was a shy 15-year-old."  At that point there was only one thing to do, and that was to invite him out for a 40-year-overdue sail on the SuperCat.  It was a light day, so we weren't out there hammering nails, but it was great to hang out for a couple of hours.  And for the rest of the weekend - and weeks afterward, as we kept running into each other at Glenmore Sailboats or at the reservoir, he'd launch into the story for the benefit of anyone else around:  "Lemme tell you about this guy..."

So, you see, it's really more his story than mine, and I'll be looking for another chance next summer to finally get him out on the wire.

 




Fuck KiCAD - at least for now.

I want to use KiCAD.  I really do.  But I can't, and neither should you. If you don't need a lesson in what EDA is about, skip ahead...