A Little bit of Electronics Madness……

There’s a reason many of the members of my family call me a “Mad Professor”, ever since I was little I’ve had a habit of doing extreme experiments with electronics, and trying to use things in a way they where never really intended to be used.

On top of that, many folks that know me and/or follow my socials, know me better for my software exploits mostly using Microsoft’s .NET framework.

What many don’t know is that my degree is not actually in software, well not entirely anyway, my degree when I earned it way back in 1995 is actually more digital electronics based, with robotics, digital electronics and CPU design at it’s core.

From time to time, I’m still partial to doing crazy stuff with electronics (Hence the reason I have a large box of dead Arduino’s, rPI’s and other assorted sacrificial digital lambs Smile )

Just recently, I found myself sitting, looking at a tube of 25 Microchip PIC’s (16F54’s to be exact) that was on my desk, wondering what I can use them for.

For those who don’t know the PIC16F54 is a microcontroller, just like the ATMEL chip you find on Arduino boards, and like the ATMEL it’s programmable using C.

It’s not a hugely powerful chip, you can clock it up to a maximum of 20Mhz and it needs it’s own Crystal resonator as it doesn’t have one of it’s own, and it has no interrupts or anything like that.

It’s a base level model with 12 I/O pins that looks like this:

Tutorial 1 - Intro - Microbyte

It has a 4 bit port A and an 8 bit port B, one 8 bit timer and not much else.

I got these chips for another project ages ago, and never ended up using them because they are so old, and they’ve kicked around my office for ages now.

What they are good for is non-intelligent I/O processing, that is a very tight code loop, that just runs around, never ending reading/writing pin states.  With this in mind, it doesn’t take much imagination to realise that you can program these things to behave pretty much like a lot of the really low level LS74xxxx series logic chips.

In fact I have already used one or two to replace a couple of Quad AND Gate chips that went bad in another circuit.

While letting my mind idle with the idea of using them for something, and while waiting for the latest visual studio build to update, I started fiddling with KiCad.  It’s the only app that still has a foot print in for the PIC16F54, and it was while I was browsing through KiCad’s component library, that it struck me….

I Can use these things to make some interesting custom multiplexer chips.

For those who don’t know what a multiplexer is, it’s a logic device that takes a binary input on one set of pins, and activates the output pin numbered by the binary number on the input, for example:

logic1

In the above image, we have a 2 bit multiplexer, input 0 is currently at logic 1, input 1 is at logic 0, and the selector bit is also at logic 0, which means it’s “Line 0” that’s allowed through.

If I switch the select bit, it will let “Line 1” through instead:

logic2

Whatever state the allowed line is in, will be the state that shows on the output, so if I was to toggle line 1, then that effect would be seen in that the Led would light too.

The opposite of a Multiplexer is a DeMultiplexer, and that will pass through a single input, to one of many outputs, depending on what the “select value” is.

Demultiplexers where used very often in a lot of the old 1980’s home computers to allow more memory that the CPU could physically address, by “Banking” the ram chips. (This technique is more commonly known as ‘paging’ to day).

Essentially, if a CPU only had enough address pins for 32k of RAM, then you’d find someway of latching a value out, by sub dividing those pins, so you can select between 2,3 sometimes even 4 blocks of 32K, essentially giving you 128K of memory.

The BBC Model B used this to great effect in the memory area from &8000 to &BFFF to swap between 15 possible 16K language rom slots, which later on home hardware hackers realised they could use them to put software loadable shadow ram banks in.

Fiddling with KiCad and with an idea in mind, I realised that I could use this tube of PIC16F54’s to build 25 Demultiplexing devices, and then from there that got me thinking about I/O lines in general.

What’s in an I/O pin?

Not a lot really, it’s either off in which case it’s at logic 0 or it’s on, that is, it’s at a logic 1.  I had 8 lines I could use as 8 I/O pins, and that left me with 4 pins to control them.

Something that worked out really well, because as you know from binary, you can encode 8 pins into 3 bits, from 0 to 7, so three of my remaining 4 pins where programmed to “Select” the desired I/O line, and the remaining pin was my “Toggle Bit”, my thinking was quite simple, program the device so that the PA0 to PA2 selected which pin I wanted to address PB0 through PB7, then watch PA3 for a “high pulse”.

When that High Pulse was detected, I simply did a “PBx = ~PBx” operation, and inverted the pin.  If it was off, I turned it on, if it was on, I turned it off.

With a 20Mhz clock crystal on my bread board, this ended up working really well, and what’s more it was really suitable to work with the rPI too.

Watch the voltages……

As many of you will know the Raspberry PI runs at 3.3v and most digital logic, the PIC16F54 included, runs at 5V.  We could never feed the output from a pin on a PIC Micro directly into an rPI, you’d kill it… something which I have painful first order experience in doing unfortunately.

What does work however is feeding 3.3v into the PIC Micro, so it’s more than possible to wire up 4 GPIO Pin’s on the rPI to control the 4 input control pins on the PIC, and set/reset my 8 I/O pins as needed.

If you power the PIC Micro of a totally separate 5v power supply, then you get one more benefit… you don’t draw too much current through your PI either.

Anyone who has one of the latest model rPI’s will know that most of the PSU’s available for them, only just manage to deliver enough juice to keep the PI operational, once you start drawing more mA’s through it, you start to get random reboots very quickly.

This was great, I had a chip, that gave me 8 toggleable I/O lines, and used only 4 lines on the rPI as any good electronics engineer knows a 2:1 increase for a 1:2 stake is a good thing.

Then it hit me……

I’m playing with multiplexers here…. and I can daisy chain them…..

I’m sure you can all see where this is headed. Open-mouthed smile

What IF I can use one DeMultiplexer to control access to several others?

So a quick rake about in my “Chips” box, and I found a bunch of “Octal Live Driver” chips.

Line drivers for want of a better word are like electronic gates, or valves if you prefer that terminology.

I driver, is kind of like a single transistor in that it won’t let a signal flow through it, until a voltage is provided at a specific pin (Usually the Base).  The main difference between a driver and a transistor, is that a driver is all or nothing, where as a transistor has a breakdown voltage, where it starts conducting on a logarithmic curve.

In simple terms, transistors are slightly wobbly, think of turning a tab on, just a little, then watching the amount of water increase to maximum the further you open the tab, drivers are “sharp”, think pressing a button on the tap and having it transition very quickly between nothing and full flow.

With this in mind, and taking our 4 pins from the rPI, in parallel into a number of drivers, again, in parallel, then hooking the “valve” switch on the drivers, to the DeMultiplexer, which is now in turn hooked up to another 4 pins on the rPI, I gave my self the ability under software control, to select one of 16 (0 to 15) Sets of drivers, attached to the 4 pins already in use, effectively allowing me to switch one of 16 set’s of 8 toggleable lines at once.

Unfortunately, I only had enough components to wire up 10 of these set-up’s but even that, gave me a 10X increase.

That is, I suddenly found myself with the ability to control 80 I/O pins, using ONLY 8 pins on the rPI, ,if you want to know, what that looks like, here you go:

logic3

The green arrow, shows the main DeMultiplexer that controls which of the 10, 4 line, driver units is currently selected.

The blue arrow, are the 4 line driver units, and the red arrow the PIC16F54 programmed as a togglable 8 line I/O unit.

If we zoom in a bit on the input pins, you’ll see the scheme I mentioned earlier, 4 pins to select the bank, 3 to select the line, and one to perform the toggle:

Logic 4

Now, most people would have been happy at this point, and marked that down as a good days work.  I could after all if I wanted to, add another 40 lines to this, giving me 120 in total, however, your probably starting by that point to draw quite a lot of mA’s maybe even full amps, especially if your using CMOS logic, something you need to be very careful of and keep a close eye on, especially if your taking the power from the 5 volt rail on one of your PC’s USB ports…  again… I have experience here Open-mouthed smile

I went a little bit overboard…

By this point, I’d been chatting to “Pete Codes” on twitter, explaining to him what I’d been up to, and it occurred to me that I could do this without using the PIC16F54 Microcontrollers.

First off all I needed was a reliable way of constructing a “T-Type” flip-flop.  That is a flip flop that toggles it’s state, every time a control line goes high.

I didn’t have any “T-Type” flip flops to hand, but I did have a box full of Quad NAND gate 74LS chips…. about 500 to be precise Smile

You can easily create a “T-Type” flip-flop using one Quad NAND chip, if you wire the gates up like so:

Logic 5

I’m not going to describe it in detail, but essentially your creating a feedback loop that bounces from one side of the NAND to another, meaning that when a toggle pulse hit’s one side get’s switched off, while the other side get’s switched on.

This little circuit, duplicated 8 times, and attached using it’s own 3 line DeMultiplexer, basically allowed me to construct a single device, that effectively duplicated what I’d programmed one PIC16F54 Microcontroller to do, and in “Digital” (The logic software I use), it looks something like this:

Logic 6

Each of those small yellow rectangles, contains the NAND gate configuration seen in the previous image.

As you can see, it’s simply just an 8 line Demuxer, with 8, 1 bit drivers to control which line is toggled.

The rest of the circuit just uses the same master Demuxer and 4 line driver chips, to select which of these custom units get’s to toggle at any given time.

The Total component cost, 10 Octal Driver IC’s, 80 Quad  NAND IC’s, 10 8 Line DeMux’s and 1 15 Line Dmux.

Oh… and a lot of wire and bread board space Smile

It’s a bit impractical for most normal scenarios, but with a little bit of re-Jigging and different thinking, you can easily use the same techniques to increase anything you need to.

Using a Multiplexer for example, you could easily feed 2 TTL Level serial Uarts into one Uart input, and have logic switchable serial data streams, or you can use SPI to control one 8 bit port, that is then expanded to 16 or more lines easily.

If folks find this post interesting, I’ve been toying with the idea of doing a whole series of these things for sometime now, in fact I’ve actually been toying with the idea of doing a series of YouTube videos, with practical ideas for IoT circuits in, and the theory behind them, if you’d like to see more of this kind of stuff, hit me up on Twitter and let me know.

Using Dotnet Core Logging without using the DI container

Just before Christmas, one of our regular contributors to Lidnug posed the question on how to use the ILogger interface in dotnet core 3+ without injecting logger instances into classes used within a dotnet core application.

Continue reading “Using Dotnet Core Logging without using the DI container”

Making Blazor validation play nice with Bootstrap 4

There’s no doubt about it, blazor’s forms module and it’s validation features are fantastic.

You get all the benefits of using validation attributes on your models, along with a very fluid and real time UI model that works exactly the same in server and client modes.

There is however, one small problem with it all “Class Names

Continue reading “Making Blazor validation play nice with Bootstrap 4”

Rediscovering Postgres and EF core

Its ok folks, you can relax, yes I’m not ill, yes I have gotten around to writing another blog post, yes I know…. I don’t write enough anymore and I should 🙂

With that out the way, why am I suddenly getting all excited about Postgres and EF again (specifically EF core)

Continue reading “Rediscovering Postgres and EF core”

Pure HTML Validation in Blazor

There’s been a lot of talk about Validation in the Blazor gitter chat recently.

The Blazor dev team have added some validation routines in that closley mimic the way validation works in ASP.NET MVC and many folks have been playing with them to see what they can do with them.

Chris Sainty has even produced a blog post [https://chrissainty.com/using-fluentvalidation-for-forms-validation-in-razor-components/] showing how to wire in the “Fluent Validation” libraries to make form validation even more awesome.
Continue reading “Pure HTML Validation in Blazor”

Bootstrap 4 Succinctly Released

The 8th book Iv’e written to date for Syncfusion’s ever popular Succinctly eBook series, and the third one one Bootstrap.

As Bootstrap continually gets better and more feature rich, then there is a need to keep up to date with the latest offerings it provides.

In this book, I take you on a just over 100 page tour of what’s new, and what it can now do (Hint: Flexbox rules!!!) and show you how to produce some interesting layouts.

Best part about it all is it’s free!!!

You can grab a copy here: Succinctly eBooks

 

Typescript for the C# developer

Over the past couple of years, my most popular talk that Iv’e taken around user groups has been the one where I describe what Typescript is, and how it relates to the backend C# developer.

Iv’e found that many back-end devs who would like to jump into client side development, are often put off from doing so simply beacuse of the percieved mess that the JavaScript eco system is in at present, and let’s be fair it’s not a compleatly unfounded reason either, beacuse JavaScript is bleeding at the edges in a great many places.
Continue reading “Typescript for the C# developer”