Generic Array Logic Hexadecimal Display

I’ve always wanted a decoder that did more than the TTL 7447 BCD to seven segment display decoder did.  I wanted the full hexadecimal output.  One of my first real projects for the GAL was to create such a chip.  I have an old PAL databook that was published by National Semiconductor in 1982.  I pulled the book off my shelf, just to see what information was in it and to my surprise was a hex display “Application suggestion”.  What luck!  Here’s a picture of the page in the book (click for larger image):

What I didn’t realize when I started this project was that it was going to be a real learning experience.  At first, the chip did not produce any outputs at all.  Then I had issues with several of the segments lighting all the time.  Typing the data into the JEDEC file was tedious and verifying that the fuses were correct was more tedious.  The first problems I found were due to my translation to the .JED file.  I expected that to occur, so I went over the file several times in detail.  Once I determined that I typed it in as it was shown in the book, I began to suspect that the book was wrong (that turned out to be an understatement).

I found a few typos in the diagram above.  First, the PTD fuses were not all correct.  There’s a pattern that they followed when the fuses were set and I noticed that some of the PTD fuses (the “X”s on the AND gates to the right side of the diagram) were not “X”d when the row was empty.  I fixed those and obtained some results.

In order to fix the segment problems I took a look at these two pages:

The page on top is the design page with PALASM logic formulas.  The bottom page is the segment diagram showing which segments will light up given a set of inputs D0-D3.  Both diagrams have mistakes.  I printed a bunch of segment display diagrams so I could work out the logic formulas and determine which formula would cause each segment to light up.  That appeared to be the way the fuses were laid out in the chip.  I focused on the D segment first:

The logic formula for the D segment was listed as follows (ignoring the RBO and LT lines):

/D = /D1*D3 + /D0*/D2*/D3 + D0*D1*/D2 + /D0*D1*D2 + D0*/D1*D2

What this translates to is that the D output (inverted) will be equal to the not D1 AND D3, or the not D0 AND not D2 AND not D3, etc.  As you can tell by my hand writing the /D1*D3 causes all the D segments to light for the binary combinations where D1 is zero and D3 is a one.  I wrote a 25 next to each of those because this logic is used on line 25 of the fuse map.  Unfortunately, this combination occurs for 1001, which should be segments ABCFG (no D segment).  To fix this, I added a /D0 to the equation:

/D = /D1*D3*/D0 + /D0*/D2*/D3 + D0*D1*/D2 + /D0*D1*D2 + D0*/D1*D2

That fixed the D segment.

I noticed an issue with the G segment.  This turned out to be a bug in their segment diagram.  If you look at the numbers 5 and 6, you’ll see that G is not listed.  Sigh.

While I was attempting to reverse engineer the formulas for this chip, I decided to add a simulation of this chip to my logic simulator.  I added code to allow me to read the .JED file in and set fuses according to the fuse map.  My intention was to verify that I had the right fuses set.  Of course, this turned into a different set of problems, all programming related, that I had to troubleshoot in order to make that work correctly.  The simulation software will pay dividends when I start to setup my next GAL circuit, because I can simulate the whole thing before I burn it to the chip and wire it to a circuit.

One lesson I learned is that it is very time consuming to type in the individual fuses.  It’s easier to build a set of formulas.  The number of formulas you can use is a maximum of 7 ORd terms for each output.  In other words, the D segment has 5 terms and they are setup for rows 26 through 29.  There is also a lamp test (LT).  So that’s a total of 6 terms.  One other input is the IC, which is connected to the enable lines for each OLMC.  What this means is that one row is not used and needs to be shut off.  So the PTD line for 31 should shut off that line (the fuse on line 31 actually belongs on line 30 to keep the pattern of fuses consistent).

The bottom line is that you have to get creative on your formulas.  Each segment can be lit for more than 7 different combinations of inputs, so it’s not possible to setup this circuit using terms of 4 like this:

/D = /D0*/D1*/D2*/D3 + /D0*D1*/D2*/D3 + etc.

Some combinations and minimization is required.  This also means that there are limits to what circuits the GAL16V8 can represent.

Here’s a picture of the actual circuit with a “2”, “A” and “F”:

Final Circuit

If you want a copy of the JEDEC file you can download it by clicking here.  You can download the logic simulator project by going to my GitHub account here.  Be aware that this software is still a work in progress.  So there will be changes in the near future.

Update

I was looking at this page:

I noticed that the “9” has the the “D” segment lit.  So the original logic formula in the book was correct.  However, that means that the segment list for “9” was wrong.  Here’s the correct segment list (for the diagram above):

 

Digital Electronics for the Beginner (Part 2)

I’m going to continue this series while it’s still fresh in my mind.  In case you missed it, part 1 is here.

I learned electronics when I was in High School.  I had two years of electronics classes and I also built circuits out of digital logic gates as a hobby.  This is in the late 70’s when Radio Shack sold chips in packages on the rack.  One of the problems with the subject of electronics is that most of the knowledge you need to become an “expert” is very dry.  To compound the problem, the subject is always taught with the basics of DC circuits and then the subject works up to AC circuits.  All rather dry stuff until you arrive at the transistor.  Then the subject of oscillators and amplifiers will put one to sleep just as fast (unless you’re interested that subject).  If you know nothing about electronics you should still be able to buy the parts I listed in my last blog post and assemble the circuits I described without too much trouble.

In my last blog post I also assumed you have some small hand tools.  If you purchased everything on the list provided, you might be wondering how to strip the ends of the wire or cut the wire to length.  That would require a pair of diagonal cutters and maybe a pair of wire strippers.  You might also need a pair of needle nose pliers to hold short wires.  You can use scissors to cut 22 gauge wire, but your scissors might not be good for paper after that.  The only tool you really need is this wire cutter/stripper:

You can find them at Jameco and they are cheaper here.

Larger Circuits

If you built the circuits in the previous blog post, you’ll realize that each circuit only involved one gate.  Larger circuits can be built by connecting outputs of one gate to inputs of other gates.  If you bought all the chips on the list that I provided, you should have 12 Inverters and an assortment of 40 other gates.  You can create quite a large circuit with that many chips.

There are several problems you’ll run into if you keep building larger and larger circuits.  First, you’ll probably run out of breadboard space.  That’s easy to fix, just buy a bigger breadboard or a second board.  But that’s not what I’m getting at here.  Circuits have limitations as well.  You should be aware of the limitations that you might run into and how to solve them.

One limitation is your power supply.  If you wire up enough LEDs and chips, you can exceed the total amperage of your power supply.  When that occurs, then your power supply will not be able to maintain the voltage that you have set and it might trip the built-in power protection.  If this happens, you’ll need to get a larger power supply to run your circuit.

If your circuit is complicated and you connect a lot of gates together, you could run into the fan-out limitation.  Each output can only drive so much current.  This rating is listed in the spec sheet and you need to compute the current rating of each input your connected to in order to see if the output can handle it.  This should only be looked at if you are connecting to more than about maybe 6 or 8 gates, or if you measure the output of your gate and it can’t achieve the voltage necessary to trigger a high (or maybe a low).  You’ll need a meter to measure the voltage.  This will probably be your first test tool.  Don’t splurge for the expensive meter, just buy something like this:

Jameco sells this meter for $6.95.  Click here.  You can also shop around, Amazon might have an even better price.

Eventually, you’ll get into clocking circuits.  You can build some pretty fast circuits that can do sequences, computations and other crazy stuff.  When you get to this level of sophistication you’ll need to understand the basics of DC and AC circuits.  Why?  Because the real-world is not perfect.  A signal traveling down a wire and through a circuit takes physical time.  It’s lightning fast, but the delay is still there.  Voltages will not switch exactly between 0 volts and 5 volts.  There is a transition time and there are overshoots (when the signal spikes beyond the top of the square wave).  This overshoot looks like this:

real-square-waveAs you increase the speed of your circuit, this imperfection becomes a real problem.

Circuit switching can cause spikes to form on your power.  This can transmit to adjacent chips and cause errors in your circuit.  There is a simple remedy for that and it involves installing a capacitor near the power lead of your chips.  If you own an oscilloscope, you can put your probe on the power supply and see the spikes.  Here’s a photo that shows how capacitors (orange and yellow) are installed near memory chips on an old circuit board:

old_memory_boardNone of these “problems” are difficult to overcome.  You just need to be aware that they exist.  Oh, and there are so many more complicated issues that can occur.  Don’t let that scare you away from enjoying this hobby/career.

The Binary System

The binary system only has two symbols a zero and a one.  So numbers in binary take more digits than the decimal system that people are most familiar with.  Here’s an example of a 3-digit binary number counting from zero to 7 (binary is on the left and decimal is on the right):

When we add two numbers together in binary, it’s similar to decimal.  If both inputs are zero, then the output is zero.  If either input is a one, then the output is a one.  If both inputs are one, then we need to set the output to zero and carry the one.  This is just like carrying a one when we add 9+1 in the decimal system:

Your Next Circuit

Let’s build a binary adder.  We’re going to start out with the simplest circuit.  The one-bit half adder.  Here’s the circuit and truth table:

 

The first thing you’ll notice is the exclusive or gate.  You can purchase a TTL XOR gate (74LS86) or you can build one out of NAND gates.  Which is what we’re going to do.  So change your circuit to this:

The NAND gate and the NOR gate have a special relationship to digital circuits.  They are the universal gates.  Any gate types can be built with just NAND gates (or just NOR gates).  Here is a list of gates and their NAND gate substitution:

Now, if you run out of OR gates, you can build one out of any spare NAND gates.

Back to our fancy half-adder circuit.  I’m going to add the pin numbers to the NAND gate chip so you can wire this easily:

Setup your breadboard and find a 74LS00 and a 74LS08.  Plug these into your breadboard like this:

I added two LEDs with resistors (100 ohm) connecting the cathode to ground.  This is the same as in previous circuits.  You can pre-check your LED wiring by connecting the other side to positive and see if the LED lights up.  If it does, then you’re good.  If it doesn’t light up, then reverse the LED leads and try again. Also, make sure the markings on your chips face up (look for pin 1).

Wire the output of the sum (NAND gate pin 11) to the lower LED and wire the output of the carry (AND gate pin 3) to the upper LED:

If you have power applied, you’ll notice that the carry LED has lit up.  That’s because there is nothing connected to the inputs of your AND gates and if you remember, TTL treats an unconnected input as a “1” or high.  Now wire up the rest of your gates.  I’ve taken photos of all 4 combinations of inputs, from left to right, 00, 01, 10, 11 (click to zoom):

Here’s another copy of the truth table to check your work:

Review

So what did we learn?

  • The NAND and NOR gates are universal and can replace any other gate.
  • The binary system only uses the numbers zero and one.
  • Using a simple circuit we can add two one-bit numbers together.
 

Generic Array Logic Devices

I’ve been blogging a bit about digital electronics lately.  One of the devices that I have never had the opportunity to experiment with is the Programmable Array Logic or PAL.  The last time I built a circuit was when I was in College in the early 90’s.  At that time I owned a Mac Plus and a 386sx generic PC.  With my limited resources (see college student), I couldn’t afford a device to program PALs or EPROMs.  I ended up building my own EPROM programmer to program some 2716s and 2732s.  Those days are long gone.  Now things are cheaper and better.  Now the PAL has been kicked to the curb and even the GAL is obsolete.  Fortunately, the GAL was manufactured for so long that there are a lot of cheap chips available.  I’m going to get into the weeds on the GAL16V8 device.  My purpose is to publish some information that is very difficult to find on the web.  Lattice is the company that made these devices and they have stopped manufacturing them as of 2014 (not to worry, there are substitutes from other companies).

Programming the GAL16V8 Device

I own the MiniPro programmer which can program a bazillion different devices.  I bought it to program EPROMs, but it’ll do PALs, GALs and a bunch of other embedded devices.  It’s a simple USB connected device and it’s cheap.  Here’s the product website: TL866 Universal Programmer.  I wasn’t able to find a copy of the PALASM program in any language other than FORTRAN and I decided I needed to make progress on programming this chip, so I reverse engineered the JEDEC file and manually set the fuse links.  Technically, the GAL doesn’t have any fuses.  The old PALs used to have a fuse link on each grid wire and you blew out all the fuses for pathways you didn’t want.  This leaves the paths you want intact which form a circuit.  Your programmer blows the fuses based on a JEDEC file.  If you make a mistake and blow a fuse you didn’t intend to blow, well, you throw away the chip and program another one.  The fuses are permanent, like a PROM (Programmable Read Only Memory).  The GAL uses flash memory to represent the fuses and they can be erased and reprogrammed.  This is very convenient because it took me about 20 tries to get my first GAL to do something simple.

The JEDEC file is a text file that contains the fuse definitions.  I discovered the details of this file by opening my programmer window and saving a blank file (after selecting the correct device).  The programmer created a .JED file and I opened it with Sublime to see what format it was in.  I was pleasantly surprised that it was in text format and not binary.  So I changed some of the “1”s into “0”s, saved the file and read it back into my programmer software and it worked.  Next was the task of figuring out the layout.  This took a lot of research (a.k.a. Internet searches) plus trial and error.

First, let’s describe the device.

How the GAL16V8 Works

The spec for the device can be found here: GAL16V8.  If you scroll down to page 8 you’ll see this diagram (this is just the top):

This diagram shows the grid of wires that connect the internals.  The OLMC is a configurable block of logic that can determine how the chip behaves.  Each row of wires can connect to any wire in the 32 columns of wires.  However, each row is not really one wire.  Each row represents the AND of each wire leading to the OLMC.  You can see the tiny AND gates to the left of the OLMC blocks:

Inside the OLMC is an OR gate that ORs all the ANDed lines together.  Like this:

What this really represents is something like this:

The idea is to set fuses to connect input lines to the inputs of the AND gates.  Pin 1 and Pin 2 inputs can be setup so that one of the AND gates will trigger an output if both inputs are a “1”.  Here’s an example of the fuses to set (all others will be removed):

The left “X” represents a connection from pin 2 high and the right “X” represents the connection from pin 1 high (pin 1 wraps around the OLMC).

You might have noticed the little “PTD” and “2128” at the top of the GAL diagram.  That fuse allows you to turn off any AND gate that you don’t want to include in your circuit (PTD stands for Product Term Disable).  So you need to keep fuse 2129, but you can remove fuses for 2128 and 2130 through 2135.  This will prevent any other lines from interfering with your first circuit.

Next, you’ll need to understand that all the OLMCs can be programmed to behave in different ways.  To get them to behave as a simple OR gated output, you can set the SYN and AC0 fuses to 1 and 0 respectively.  SYN is fuse number 2192 and AC0 is fuse number 2193 (the last two fuses in the file).  For the first OLMC you’ll need to set the AC1 mode bit to a “0”.  AC1 for the first OLMC is fuse 2120.

Finally, there is a fuse that defines if the output is active high or active low (inverted).  The fuse for the first OLMC is 2048.

The OLMC configuration for simple mode is on page 9 of the specification at the link.

The JEDEC File

The TL866 programmer uses JEDEC files to define the fuses that will be set in the GAL device (.JED extension).  The fuse map portion of this file looks like this:

*L00000 00000000000000000000000000000000

*L00032 01011111111111111111111111111111

*L00064 00000000000000000000000000000000

*L00096 00000000000000000000000000000000

*L00128 00000000000000000000000000000000

*L00160 00000000000000000000000000000000

*L00192 00000000000000000000000000000000

*L00224 00000000000000000000000000000000

*L00256 11110111111111111111111111111111

*L00288 11110111111111111111111111111111

*L02048 00001111111111111111111111111111

*L02080 11111111111111111111111111111111

*L02112 11111111000000000100000011000000

*L02176 111111111111111110

The *L is the starting address of the line of fuses.  You can skip addresses that are not defined and they will become the default value as defined by the *F line in the file (zero being the default in this case).  As you can see L0000 through L00224 line up with the diagram of the circuit above.  One thing you’ll notice is that a “0” represents a fuse and a “1” is no fuse (that caused me a lot of frustration, when trying to reverse engineer this).

L02048 is the line that begins the XOR outputs (to define active low or active high).  Fuse 2056 through 2119 is a signature, so you can ignore these fuses.  Fuses 2120 through 2128 define the AC1 config parameter for the OLMC modules.  As mentioned earlier fuses 2128 through 2191 are the PTD fuses to define which AND gates will be turned off.  Finally the last two fuses are SYN and AC0.  You can see in the JEDEC file above that SYN and AC0 are set to 10.  That means that this GAL is setup for simple mode (each OLMC will behave in the simple configuration).  Here’s a list of fuses and their purpose in the GAL16V8 device:

0 - 2047 matrix

2048 XOR for OLMC 0 (0=active low [led lights], 1=active high)
2049 XOR for OLMC 1
2050 XOR for OLMC 2
2051 XOR for OLMC 3
2052 XOR for OLMC 4
2053 XOR for OLMC 5
2054 XOR for OLMC 6
2055 XOR for OLMC 7

2056 - 2119 Signature

2120 AC1 for OLMC 0
2121 AC1 for OLMC 1
2122 AC1 for OLMC 2
2123 AC1 for OLMC 3
2124 AC1 for OLMC 4
2125 AC1 for OLMC 5
2126 AC1 for OLMC 6
2127 AC1 for OLMC 7

2128 - 2191 PTD

2192 SYN
2193 AC0

There are other fields used in the JEDEC file.  Some are not used by the TL866.  One field in particular is the *C field, which is the checksum field.  The TL866 will compute this number and save it correctly, which is good because other software might blow up if the field is not right.  However, I have changed fuse patterns and not updated the *C field and the TL866 ignores it.  In the sample JEDEC file above, I also have fuses setup for the third input (pin 3).  This circuit will cause the second OLMC to output a “1” when pin 3 is a “1”.  You can download the file by clicking here and unzipping the zip file.  The specifications for the JEDEC file can be found here: PLD File Formats.

Where to Find GAL Devices

If you go to the on-line Jameco catalog and navigate to the semiconductor section, you’ll see a section called “Logic, Programmable“.  You’ll see a list of programmable chips.  There are some 16V8 devices as well as 22V10 and 20V8 devices.  I’m starting small and simple.  These things can get complicated in a hurry and it took a lot of re-programming to get it down.  The devices are about $2.25 each (as of this blog post) and Amazon has the TL866 programmer for around $50.  If you own the devices I listed in my last blog post on “Digital Electronics for the Beginner” you should have enough hardware to experiment with GAL devices.

If you have any specific questions about the GAL16V8 and how it’s programmed or the JEDEC file format, or if you know something about this device and think it should be appended to this blog post, please feel free to leave a comment.

 

Digital Electronics for the Beginner

Let’s say you’re a programmer and your experience in digital electronics involves that one class you were required to take in college.  Or…you’re a young person who is interested in learning this cool stuff, because, well… it seems cool.  One option is to buy one of those learning kits and go through the tutorials.  If you’re on a budget, you can start with one of these:

electronic_snap_circuitsI’ve played with this kit myself and I would recommend any parent that wants to introduce their kid to electronics, this is a good buy.  It has a card for each project that explains the circuit as well as the parts used by the circuit.  There are troubleshooting instructions and warnings about how to build a circuit without burning up components.

Let’s pretend that we wanted to just focus on some digital circuits and jump right into integrated circuits.  Here’s a list of what you’ll need to get started:

  1. Breadboard
  2. Power supply
  3. Wire
  4. IC assortment
  5. LEDs
  6. Resistors

Let’s start with the breadboard.  This is a large plastic “board” that has a lot of holes in it.  You use it to plug your wires, IC’s, LEDs and resistors into.  Integrated circuits are rather tiny, so attempting to wire them with alligator clips or twisting wire to the leads is not a good solution.  Radio Shack used to be my go-to place for stuff like breadboards, but they don’t sell much electronic stuff these days (assuming you can find a Radio Shack).  Jameco Electronics is my current go-to place to find anything I need.  Here’s a typical breadboard from Jameco (and a good starter one):

breadboardIf you’re on a really tight budget you can get one of the really small ones for under $5.00:

cheap_breadboardThe small breadboard above will probably fit 3 or 4 integrated circuits.  The Jameco brand one above will hold about 20 ICs.

Next, you’ll need a power supply.  I would recommend sticking to TTL logic circuits since they are more durable than any other integrated circuits (I’ll get to the details of this soon).  So you’ll need a stable 5v power supply to power your circuits.  This is probably the most expensive part.  If you’re comfortable with wiring a plug to a power supply you can go cheap and get something like this (for around $20):

cheap_power_supplyDon’t let the picture fool ya, it has a cover (you can see it in the spec sheet).  For a young adult, I would recommend spending more money and obtain a safer power supply, like this one:

power_supplyThis power supply has an adjustable output and costs around $67 at Amazon (click here).

I’m going to ignore the fact that you might need a meter to troubleshoot.  Technically, if you’re building TTL circuits, all you really need is a resistor and an LED.  So you can get a variety pack of resistors at Jameco for around $5 (click here):

resistor_assortmentFor a pack of LEDs, I would just by 10 of these, which are about 12 cents each (click here):

ledThe last boring component you’ll need is wire.  Just buy a roll of 22-guage solid wire.  Jameco has several colors available in 100 foot rolls for $8 (click here).

Now for the reason you’re doing this, the integrated circuits.  Jameco has some Grab Bags that are cheap, but they contain random TTL circuits and most are not very useful for an experimenter.  They also have component kits that contain known quantities of each type of TTL circuit, but those are really expensive.  So I would recommend buying this variety (filter to the 74LS series, they’re cheaper):

  • 2 inverters (74LS04)
  • 4 NAND gates (74LS00)
  • 2 NOR gates (74LS02)
  • 2 AND gates (74LS08)
  • 2 OR gates (74LS32)

The total for those should be under $6.

Let’s Build a Circuit

OK, you’re first circuit.  Let’s make this as easy as possible.  Here’s a circuit diagram of what we will build:

and_gate_circuit

Basically, it’s just an AND gate with both inputs set to zero and an LED output.  We will be switching our input wires to simulate a 1 or a 0 for inputs and see what the LED does.

Your first step is to install an AND gate (74LS08) into your breadboard.  To do this, you’ll need to identify pin 1.  There is usually a marking at one end of the chip and sometimes a small dot in the upper left corner.  The dot represents pin 1 and you should orient this chip on your breadboard with the dot facing up.  Here’s an example:

chip_insertedNotice how the IC straddles the groove in the breadboard.  The groove is a break in the contacts formed by the breadboard circuit.  Each line of holes run horizontally.  The numbers you see are the row numbers of each set of holes.  For line 30 (above), there are 5 holes in a horizontal row on the left and 5 holes on the right of the groove that are connected together.  For an in-depth explanation of how breadboards work, I would recommend reading this: How to use a breadboard.  Armed with this knowledge, I’ll continue with the circuit.

Next, you’ll need to go to your favorite search engine and find a tech sheet for the 7408 TTL circuit.  TTL can come in L, S, LS or normal package types.  The circuit number will always be “74” followed by an optional letter or pair of letters and then 2 or 3 digits like “08”.  So a 2-input AND gate can come in packages marked as 74LS08, 74L08, 74S08 or just 7408 (there are other types as well).  The package type is meaningless to this exercise so you can ignore which type of package you own (if you bought from the list above, you’ll have all “LS” type TTL circuits).  You can also ignore anything that comes before the “74”.  These characters represent the manufacturer.  So search the Internet for “TTL 7408” and you’ll stumble onto a PDF like this:

Quadruple 2-input Positive AND Gates

Now that your chip is properly inserted into the breadboard and you have a spec sheet, you’ll need to wire your power.  To form a complete circuit, each chip needs +5 volts and ground (or zero volts).  The spec sheet has a package diagram showing the pins of the chip:

ttl7408specYou’ll connect your +5 volts to the VCC pin (pin 14) and your ground or zero volts to the GND pin (pin 7).  Your breadboard should have some power runs along the side.  The Jameco board has red and blue stripes next to these power runs.  Connect your positive power supply to the red run and the ground to the blue run.  Then you can connect your chip like this:

power_connected

Next, you can connect an LED to the output.  First, let’s look at the spec sheet again and identify one AND gate that we can use.  If you examine the logic diagram you’ll see how the inputs and outputs of each AND gate is marked:

and_gate_logic_diagramThere are 4 AND gates on this chip, but we only need one.  So we’ll use the first one.  The first AND gate uses inputs 1A and 1B.  The output to this gate is 1Y.  In the pin-out diagram shown earlier, the inputs correspond to pins 1 and 2.  The output is on pin 3.  So let’s insert an LED and connect pin 3 to one side of the LED:

output_connected

LEDs are one-way devices, so when you insert the LED, make sure the long lead is connected to your wire.  If the circuit doesn’t work you can pull out the LED and reverse it.  Inserting an LED in backwards will not hurt anything.

The next step is very important because LEDs are sensitive to too much current.  So we’ll need a resistor to limit how much current is drawn by the LED.  If you don’t use a resistor you’ll hear a popping sound and you might smell something burning.  That would be the end of your LED.  If this happens, just throw it away, turn off your power, correctly wire a resistor (as I’ll describe next) and install a new LED.  As my high-school electronics professor used to say “no-burn, no-learn!”

On the short lead to your LED, connect one side of a 100 ohm resistor and connect the other side of the resistor to the blue bus bar (or ground).  To identify a 100 ohm resistor the colored stripes should be brown-black-brown (ignore the gold or silver stripe):

100_ohm_resistorResistors come in a variety of sizes.  To identify resistor sizes, you can go to this excellent website and memorize your color code (and it also includes a color code calculator).  Now your circuit should look something like this:

resistor_wired

Next, connect pins 1 and 2 to ground (or the blue bus):

circuit_done

Now, connect your power supply (plus lead connects to both red buses and the ground lead connects to both blue buses).  Adjust the voltage to +5 volts (if your power supply is adjustable).  Then turn it on… and… nothing happens.  This is the expected output.  So let’s make the LED light.  In order to do that, we’ll need to make both inputs a 1 or +5 volts.  Or do we?

TTL logic is wired in such a way that most circuits will treat an open input as a 1 or high.  So just remove the two input wires.  You can pull those wires while the circuit is on.  Notice how the LED lights up:

circuit_active

If your LED does not light, then you’ll need to troubleshoot.

  • Double-check to make sure all your wires are connected to the right pins.
  • You can see in the picture above that my IC is inserted between rows 56 to 62.  Row 56 on the right side is the positive connection.  Make sure the red bus on the right side is connected to the positive power supply lead.
  • Check the blue bus on the right side to make sure it is connected to ground.  Then check both the blue and red buses on the left, they will also need to be connected to the power supply.
  • Disconnect the wire from pin 3 of your AND gate and connect it right to the red bus.  Did the LED light up?  If not, then you need to check that the LED and resistor are wired correctly.  Maybe the LED is in backwards?
  • Make sure pin 14 (upper right) of your chip is wired to positive power and it is +5 volts.
  • Make sure pin 7 (lower left) is wired to ground (or the blue bus).
  • If the LED lights, but your circuit still doesn’t work, the chip could be bad (not likely, but you never know).  Turn off your power supply, remove the chip from the breadboard and insert another 74LS08 chip.  Make sure the pins are lined up exactly as the previous chip was lined up.

If your circuit is working, then you should experiment with all the combinations of inputs for your AND gate.  There are 4 possible inputs to a digital circuit that has two inputs.  Here’s a truth table of what the 4 inputs are for an AND gate:

and_gate_truth_tableAs you can see the circuit will only light if both inputs are a 1 or open.  If either input is a zero, then the light will go off.

The 74LS00 NAND gate can be substituted for your AND gate.  Make sure you turn off your power supply before removing one chip and inserting a new one.  Also be careful to line up the pins the same.

If you successfully tried the NAND gate, the NOR and OR gates are also identically pinned.  The inverter, however, is not.  So don’t attempt to wire the inputs and outputs the same because the inverter only has one input.  So pin 1 is the input and pin 2 is an output.  Feel free to connect the output of your 7404 to the LED (pin 2) and try pin 1 with high and low inputs.

Review

So what did we learn?

  • LEDs will burn out if we don’t limit the current they draw with a resistor.
  • LEDs go one way and the long lead is wired to the positive supply.
  • TTL chips are marked to identify pin 1.
  • TTL logic treats an open input as a 1 or a high.
  • We learned the resistor color code scheme.
  • We learned how to find and read a TTL IC spec sheet.
  • We learned how a breadboard works.
  • We learned how to wire power to a TTL chip.
 

Website Security

Summary

In this post I’m going to talk about website security.  This is just a top-of-the-waves blog post.  Consider it a jumping off point for you to dive deeper into specific security subjects.  As a software developer, everyone should understand what precautions should be taken to ensure that your company’s website will not appear on the evening news.

Website Security

I’m not a security expert.  I’m also not an expert in the field of encryption.  My experience stems from the fact that I’ve been through a few “incidents” in my career involving a user or employee who has broken into the software that I maintain.  When your company gets hacked, it humbles you.  All your assumptions about how good you are at securing your software go right out the window.  The basic problem with security is that you must be conscious of all the tiny details.  The potential hacker only needs to find a very small opening.

Here’s is a video (on YouTube) that every developer should watch.  It’s very entertaining, but also informative.  This video shows a group of white hat hackers who were hired to hack into the U.S. power grid.  Their job is to perform the act and then report back to the company on what they need to do to secure their systems:

Watch Hackers Break into the US Power Grid

Notice how these guys obtained a tiny bit of information using a technique called social engineering.  This is normally the starting point. Their next step is to install some trojan horses (in their case they installed physical devices on the network of the main office as well as software on some of the laptops).

Most hackers are current or former employees.  These are people who already have inside knowledge to get them started.  The infamous hacker Edward Snowden was a contractor that worked for the NSA.  He was an IT person with enough privileges to get information out of the system, in bulk.  He also used social engineering to convince fellow co-workers to give him access to their data.

Other hacked sites involved really dumb programming mistakes.  Citi was hacked by a user who realized that the account number was a parameter in the website url.  They changed the number and refreshed their browser, allowing them access to over 200,000 accounts (How Hackers Stole 200,000+ Citi Accounts Just By Changing Numbers In The URL).

SQL injection is a very common mistake.  Here’s a rather long list of sites that contained injection vulnerabilities: The Code Curmudgeon SQLI Hall-of-Shame.

Hard-coded passwords… sigh.  So many devices, so many hacked systems: Hard-coded password exposes up to 46,000 video surveillance DVRs to hacking.  Here’s an article about the Internet of Things:These 60 dumb passwords can hijack over 500,000 IoT devices into the Mirai botnet.  If you read down the article you’ll stumble onto this quote: “To make matters even worse, the default credentials cannot be changed as they are hardcoded in the firmware and there are no options for disabling them. The telnet service is also difficult to disable.”  Never hard-code a password.  Always allow a method to change the user id’s and passwords.  There should also be a setup that forces the purchaser to change the admin password right away.

Custom encryption or hashing.  Don’t do it.  Use an existing algorithm and make sure you understand which hash algorithms are appropriate for saving passwords into your database.  Use a salt to prevent someone from using a lookup website to reverse a hash.  A salt is not optional.  There are many unsalted MD5 hash lookup websites.  Every developer should read this information on hashing passwords: Salted Password Hashing – Doing it Right.

Don’t Assume Anything

Building a secure piece of software requires the developer to be a bit paranoid.  I roll my eyes when a developer begins to spit out an excuse for taking the easy route.  Usually the excuse is along the lines of “nobody knows what the name of that database is..” or “how likely is it that someone will…”.  Hackers are very smart.  Don’t let cheesy Hollywood movies fool you into thinking that hackers are just clever 8-year old kids with some scripts they downloaded from the internet.  Hackers can be former developers with a copy of your database.  They may have run a bruite-force algorithm on your password hashes and have admin passwords to enter your system.  This is the reason for a password policy that forces users to change their passwords on a regular basis.  Here’s a really good system for finding all 8-character passwords: 25-GPU cluster cracks every standard Windows password in <6 hours.

Protect your backup files.  A backup file can be copied to a thumb drive and then restored to another machine.  A potential hacker can run a brute force attack on such a restored system until the cows come home.  Once a user-id and password has been found, then the hacker has what they need to enter the real system.

Keep tight firewall controls.  It’s sometimes easy to just open up a bunch of ports to make something work.  This is OK for testing purposes, but your production system should be as closed to the outside as possible.  Here’s an example of a vulnerability for Active Directory from the internet: Researchers show how to steal Windows Active Directory credentials from the Internet.

Finally, here’s a list of common programmer mistakes that can let a hacker into your system: Coding Horror – Top 25 Most Dangerous Programming Mistakes.

Security through Obscurity

There are two basic meanings for this saying.  In one instance, instead of securing something, just obscure the name of it (like an admin account with no password, or a linked server with elevated privileges).  Don’t fall for this trap.  This just means that only external hackers with no knowledge knows about this.  It doesn’t mean that they can’t figure it out or that a disgruntled employee won’t use it.  Using an obscure user name as the admin user name (instead of “admin”), and using a strong password is OK.  Obscuring the admin user name makes it more difficult for a brute force attacker to attack a site.  It isn’t going to slow down a laid-off software developer with a copy of your database.

Finally

Just for fun, here’s a list of the Worlds Biggest Data Breaches.  This list is arranged by year with relative sized circles based on the size of the breach.

 

Working on the Blog

I’m working on the blog today.  This is a bit different from actual “blogging.”  This task is a bit more like “installation and repair” and not so much “writing and publishing.”

I recently switched from Blogspot to WordPress.  Now I feel like a customer.  I know what it feels like to be a customer, because I’ve purchased and installed software and hardware for years.  I’ve been in the industry long enough to have upgraded products many times over and sometimes I go through the bad experience of trading one “problem” for another.  In the case of Blogger, the text editor is hideous.  The next irritation is the lack of built-in themes.  I’ve gone through the pain of attempting to install a 3rd-party theme into Blogger and that’s not always a successful endeavor.  Eventually, I decided that the pain of switching to another technology was less than the pain of staying and putting up with the problems.  Especially since Google has not upgraded their blog engine since I started using it (it has the feel of a dead or abandoned product).  I understand.  It’s free and it’s not Google’s core business.

I found a few blogging sites that were interesting, but they were expensive.  Then I realized that I could use WordPress on my own website host (GoDaddy .Net host if you’re wondering).  My hosting package is the unlimited plan so I can upload as many pictures as I want.  I figured, if I’m already paying for this, I should use more of it.  So I made the plunge.

I found a WordPress theme that was very clean and I found a plug-in that performs syntax highlighting.  The highlighting plug-in does not produce the correct colors for C#, but I think I can tweak the CSS when I get some time.  I also discovered that I can import Blogger formatted export files.  I imported all of my posts from Blogger.  I have been going through these and cleaning up the formatting snafus (like huge blank spaces, teeny-tiny text, etc.).  I’ll release these posts as I get time to clean them up.  My Blogspot site will remain active forever (unless Google gets frugal and decides to remove it).

Then the shininess started to wear off.  I like WordPress for my blog.  I’ll be staying right here, but I still have a few issues to resolve.  I have some minor issues like the syntax highlighting.  I finally found a plug-in to handle the email subscriptions.  For those who are looking for that feature, you’ll see it in the comments section (to see comments, click the blog header, scroll to the bottom, then put your cursor in the comment text box to see the subscription check boxes) or at the bottom of the page.  Next, I’ll need to install a backup package.  Then there’s Analytics…

I’ve used Google Analytics for years.  I’ve written APIs to pull massive amounts of data from Analytics, so I know how it’s all structured.  I just added another Analytics tracking property setting and obtained another ID from my current account.  Then I added the tracking JS to the header of my wordpress account.  That gets things started, but it’s not quite what I need.  At least I have an idea of the total traffic going to my url (which is blog.frankdecaire.com).  What I don’t have is the kind of tracking data that Blogspot has.  Not that Blogspot had a lot of data, because it was lacking as well.  One of my missing metrics is how many people are hitting each blog article, but there are WordPress plug-ins that I might try (though I’m not sure they are geared for a blog setup).  I can also tweak the JS to insert some meta-data into the Analytics tracking code so I can sort by blog post.

Added Features

So far today, I added a plug-in called Jetpack.  So far, this seems like a very nice plug-in.  Technically, I just installed it and have only looked at a few features.  There’s a feature to click a “like” button.  I use Facebook just like most people do, so I like that feature (no pun intended).  Please feel free to click the like button if you enjoyed reading one of my blog posts.  The number of likes on a post can drive the subjects that I steer towards and it’s a bit more relevant than the Google Analytics report of how many people landed on a subject from a search engine.  Plus, you might come to my blog from a saved link and scroll down to a subject you really like and I don’t get that information in Analytics.

The Jetpack plug-in also has the subscription check boxes.  I have been asked about my email subscription controls by people at my workplace and also a person who commented on this blog.  As I mentioned above, the comments only show up if you are in the article.  So click on the article title, then scroll to the bottom.  When you put your cursor in the text of the comment, two check boxes will appear just below the comment box.  One check box allows you to receive emails when posts are created or updated.  The other allows you to follow updates to the current comments (so you can leave a comment and get a notification when someone replies to you).  You’ll receive a confirmation email when you subscribe, so keep an eye out for that.  You need to leave a comment in order for the check-box to work.

There is also a subscribe section that appears at the very bottom where you can type in your email address and subscribe to the blog:

blog_subscribeNow I can check that task off my list!

I have provided sharing links.  Two sets of sharing links, to be exact: One is used by Jetpack and the other is from another plug-in called “Social” and it has more share sites available:

social_buttonsI have not tested either one of these plug-ins, so if you have issues, please leave me a comment or send me an email.  I’m not sure how important these are for my followers.

There’s a CSS link available.  I provide that primarily for myself.  My website uses the CSS link to display the top posts:

latest_blog_postsI wrote some C# code to look for the blog titles:

List latestBlogPosts = new List();

string url = "http://blog.frankdecaire.com/feed"; 
XDocument feed = XDocument.Load(url);

SyndicationFeed sf = SyndicationFeed.Load(feed.CreateReader());
if (sf != null)
{
    int totalPosts = 0;
    foreach (SyndicationItem si in sf.Items)
    {
	    latestBlogPosts.Add(new BlogPostModel
	    {
		    Title = si.Title.Text,
		    Url = si.Links[0].Uri.AbsoluteUri.Replace("#comment-form", "")
		});

		totalPosts++;

	    if (totalPosts > 8)
	    {
		    break;
	    }
    }
}

I pass the results in a viewbag variable and display on the view (in case you’re interested in the technical details of this “miraculous” piece of code… LOL).

Pros and Cons

One of the pros of maintaining a blog on Blogspot is that Google maintains the data forever.  I’m hosting this blog.  What that means is that “if” my financial situation goes South for any reason, or something happens to me (like I win the lottery and move to the beach), the information on Blogspot will remain.  My GoDaddy host would be expired if I don’t pay the annual fee (though technically, I pay for multiple years to save money).  I know that it is very annoying to find the right subject in a Google search only to arrive at a broken link.  So the minimum requirement is that I maintain my domain names.  This allows me to move to any other host and the search engine links will always be valid.

Another pro is that the using Blogspot means I don’t have to worry about backups, upgrades, installations, etc.  I currently have a WordPress update and a couple of plug-in updates that are bugging me.  I can’t do the WordPress update until I have my backup plug-in working (next on my list).

I have listed a few Cons of Blogspot above.  Many of the Cons are due to the fact that I have less control over the blog itself when I’m using Blogspot.  Let’s face it, Blogspot was created for the masses.  Individuals with little to no computer knowledge can use Blogspot right out of the box without knowing what the word “host” means (that was actually appealing to me too).  I, however, have no such excuse.  If I didn’t know how to setup a host, WordPress or any of this technology, then I would have no credibility in writing blog posts under the subjects that I write about.  I have maintained a website and host since the mid-90’s.

If you’re setting up a new WordPress blog and you’re a technical guru like me, then I would recommend the following blog article for customizing: How to Customize WordPress (Step-by-Step).  I found it to be very helpful.  There is a lot of information on the subject.

Purpose of my Blog

I’m sure I’ve talked about this before, but I’ll describe my purpose in blogging again.  Initially I intended to use the blog format to contain information that I learned about subjects that I struggled to find a solution.  I figured, if I did it before, then I can always look up the information in my own blog.  It’ll be on-line, so I don’t have to worry about hauling around a thumb-drive or notepad of my notes.  It took me a couple of years to overcome my fear of posting something that might not be “perfect.”  I finally took the plunge and it was a bit of a rocky start.  Getting acclimated to creating, editing and posting took a lot of practice.  Now I know what writers mean when they talk about writing a lot of short-stories just to get used to writing.  Blogging works the same way.

As of this post, I’ve been blogging since April of 2012, which is almost 5 years.  Some years have been better than others as you can tell if you look at the total posts for each month or year from my old blog:

blog_archiveI anticipate that this year will be a heavy posting year again (This will be my 5th post!).  My blog is still used by me to contain subjects that I might use as reference, but I also enjoy sharing information that is difficult to find on the web.  My most recent subject and resurrected hobby involves digital logic and home-brew computers.  In case you’ve never visited my website, I built a single-board computer from chips a long time ago:

8085_cpu_topThis hobby took a back-seat when I graduated from college and I recently stumbled across an article about a guy who built a computer out of tens of thousands of transistors.  Which brought my interest back.  That’s where my current cache of subjects are coming from… my hobby.

As I’m alluding to, it’s sometimes difficult to produce blog posts for this type of blog because I run into subject block.  This is similar to writer’s block, except it’s just a lack of interest in subjects that I am qualified to blog about.  Some of these subjects are technologies that I use at work.  Since I spend all day on these tasks at work, I’m ready to think about something else on my weekends.  I have a list of potential blog subjects that I use to jog my memory of what I should blog about.  That can be a good crutch in instances where I have time to blog, but can’t think of a specific subject.  Sometimes, I get into what my wife calls a blog funk.  That’s where I would like to blog, but I don’t want to spend time setting up the software to get the screenshots and code-snippets to create the blog post.  So I spend my time on something non-blog related.

The bottom line is that I’m blogging for me.  I don’t have any advertising on this site and I don’t intend to get paid to blog.  So don’t expect to see pop-ups or annoying animations along the sides of the blog.  I find those to be very distracting and I don’t expect anyone to have to suffer through that onslaught just to consume some technical information that I posted.

If you have a blog story you would like to share, feel free to post in the comments, or leave a link to your blog.

 

Digital Logic Simulator Progress

Summary

In this post I’m going to talk more about creating simulation software and the difficulties of inventing something new.

Writing Software is Like Working in a Sausage Factory

Writing new software is more of an art than a science.  Sure, we call ourselves scientists and we have methods and proven algorithms for getting things done “right.”  At the end of the day, it’s a bit of trial and error.  Sometimes a software development project contains a lot of unknowns.  As an advanced software engineer, my daily routine consists of mostly “unknowns.”  I’m the guy who has to “figure it out.”  That’s my job and that’s what I enjoy doing.  When I create software for my hobbies, I run into the same problem.

I start a project with all kinds of great ideas about how the software will work, what algorithms I’ll use and all I need to do is type in the code.  Then I have to troubleshoot.  First I’ll find some simple bugs.  Then I’ll dig into deeper bugs and hopefully, what I’ve built works as expected.  Otherwise, I might spend an enormous amount of time trying to find a bug that turns out to be a flaw in my initial assumptions.  This will be followed by a re-design and a lot of refactoring.  On really rare occasions, I’ll throw out my code and start over.  Actually, I don’t throw anything away these days.  There’s version control, unlimited cheap storage, etc.  No need to throw it out, just archive for future review (if I need to).

Once the program works, then I have to do some cleanup work.  There is usually some dead-code that needs to be removed.  Also, code formatting might take a back-seat when I’m trying to figure out an algorithm.  That needs to get cleaned up.  Then there are “TODO:” notes littered all over the place.  I’m really bad about getting back to those.  They can be handy, but they can multiply quickly.

My development process usually goes like this:

  1. Create a library to contain my code.
  2. Create a test project to unit test my library code.
  3. Create a shell of the first object and create one or more empty unit tests (with Assert.Fail() or something similar in the body of the test method) of features that I’ll need.
  4. Create code for the first feature, add code to the unit test that applies.
  5. Make the unit test pass.
  6. Repeat

Sometimes I create a console application so I can use logging to do my troubleshooting.  This occurs when things get more complicated and I need to integrate pieces together.  If I want web output, I’ll create a website project and if I want a windows graphical screen output, I’ll just create a Windows Application project (all in the same solution).  I can switch which project is the startup project, so I just keep all the projects together where I know they are related.

Of course, this is the Sausage Factory.  It get messy inside and it’s not for the faint of heart (aka, non-technical).  For those who have never written a program, it just appears that I’m a zombie at a keyboard typing in strange words and characters.  For those who have written more than an introduction-level program, they’ll just nod and smile.

The Digital Logic Simulator

One type of program that usually starts with the most unknowns is the simulator program.  A simulator program is an abstract representation of something in the real world.  The Digital Logic simulator just simulates physical logic circuits that can be built with TTL (Transistor-Transistor Logic) circuits.  This simulator is not intended to be electrically accurate, only accurate in the sense that I can simulate the timing of real circuits.  There are already software packages on the market that are electrically accurate and some are extremely good (and they have the price tag to go with them).  I’m doing this as a hobby, so I expect to gain some knowledge and I’m also doing this as a blogging subject so I can pass along my knowledge to anyone who wants to learn more about digital logic and simulators.

When I setup this simulator, I created arrays (or lists) of voltages that are applied to inputs and outputs.  Each array cell represents a voltage sample for 1 nanosecond of time.  So far I’ve kept the voltages to 5 volts and zero volts and assumed that there are no voltages in-between.  Will I exploit the capability of setting any sample to any voltage?  I’m not sure yet.  My current concern is the timing aspect of it all.

To simulate the operation of a circuit, I have to translate inputs into outputs.  So input voltages are copied to the outputs of simulated wires (since a wire just conducts the voltage to the other end).  Logic gates can require anywhere from 1 to dozens of inputs in order to determine what the output voltage is.  So I have written objects and methods to represent how a gate will handle inputs.  Then I have setup special connection objects that can translate from one gate output to other gate inputs.  In order to make it all work I have created a circuit object that begins with the input data and attempts to propagate the voltages from the inputs through all the wires and gates until the outputs are known.  This algorithm works…. to a point.

One of the first problems I ran into using the input to output algorithm is that there could be unknown inputs to gates.  This happens because two different input signals to a gate might travel through different numbers of other gates.  Like this:

sample_1

As you can see the signal from input “A” will arrive at gate 1 before the result of gate 0 arrives (because inputs B and C need to be processed through gate 0 first).  So if the circuit algorithm tries to process gate 1 before gate 0, then one of the inputs is still unknown.  My solution (for now) is to mark all outputs as “unknown”, then attempt to process each gate.  If the inputs to a gate are all known, then process the gate and translate the output.  Then I run through the circuit again to see if I can determine more gate solutions.  This can continue up to 10 times, in which I assume the circuit cannot be solved.

The next big problem was the flip-flop.  This was a very difficult problem because the flip-flop is a chicken-and-the-egg problem.  The outputs are fed back into the inputs of the opposite NAND gate.  So the inputs are always unknown.  As I mentioned in one of my earlier blog posts, I can get around this type of problem by being able to compute the output of a gate with some unknown inputs as long as I have one or more inputs that can determine the output.  In other words, if an AND gate contains one input that is a zero, then it doesn’t matter what the other inputs equal, the output will always be zero.  With this assumption, I can determine outputs with minimal inputs and get around the flip-flop issue.

Next, I discovered that one of my virtual circuits contained a missing input connection.  I decided to create some test methods that I can use in my unit tests to determine if the circuit is valid to start with.  First, I need to make sure there are no open inputs on any gates.  So I have a method to test this.  Then I needed to make sure there are no two or more outputs connected together.  That would be a short circuit.  Last, I needed to determine if, at the end of a circuit run, there were any wires that contained voltages at the source end that were different from the termination end.  This would be an invalid circuit configuration and cannot happen in the real world.  So after running a circuit, I check the wires and if that passes, then I’m on to unit testing the known inputs with the outputs to determine if the circuit is correct.

I can create very complicated circuits out of gates.  My next trick will be to create circuits of circuits.  I’ve tried a couple of algorithms to make this work.  I’m hoping to come up with a plan that would allow me to connect circuits together and treat the whole thing the same way I treat a circuit.  Unfortunately, this is not as easy as I had hoped.  One of the problems is that I have to run a circuit in order to get the outputs.  So I connected two Full Adder circuits together into a two-bit adder like this:two_bit_adderI know what the logic table looks like, so I created the unit test for this circuit before I built it.  Then I built the circuit and I ran into a problem.  The bottom adder requires the carry out from the top adder in order to perform its calculations.  In addition to the sequence of operations problem, there is also the fact that the output of the first adder has a connector object that must copy the voltage from one end of the wire to the other.  Before anything starts though, the inputs must all be copied to the circuit inputs.  Fun times.

The program is rather slow already.  I’m OK with the simulation running slow, I’m not looking to run this in real-time or to produce a lot of data in a short amount of time.  However, the slowness is going to compound when I get to the circuit of circuit level (and beyond).  So I’m re-thinking my algorithm.

New Circuit Algorithm Ideas

One algorithm I’ve been thinking about involves starting with an output and working backwards recursively to find enough inputs to satisfy a known signal.  In the case of the two-bit adder, I can start with the output S0.  This output will require Cin (which is hard-wired to zero volts), A0 and B0.  For S1, I’ll need Cin, which requires the result of Cout of the other adder circuit.  Then I’d need to find out that output first and so on.  This algorithm will work except for one tiny problem.  The timing of it all.

To obtain the timing, I’ll need to go forward through the circuit.  There are a few ways I can implement this.  First, I can just run my recursive backward seeking algorithm until I get to the inputs and just unroll my recursions and fill in the arrays as I go.

Another idea I have in my head involves the same algorithm, trace from output to input recursively, but just store the paths that the electrical signal must follow.  Then trace the signals from inputs to outputs using the order setup by the recorded paths from the recursive algorithm.  This would be a two-step algorithm.  Find the paths then translate the signals.

Some pitfalls to watch for:

  • These circuits could become really large and recursion can get slow.  If recursion becomes a problem, I’ll be forced to use a stack.
  • Another issue will involve infinite recursion.  This I know will happen in situations like the Flip-Flop. I’ll need to design in a safety cut-off before I start using recursion for anything.  I’ll also have to see what I can use for a cut-off in a Flip-Flop circuit.
  • Testing recursion can be difficult.  I’ll need to think about how I’m going to test this thing.

Fortunately, I already have a few circuits in the solution that I know work.  So I can setup my new algorithm and run some existing unit tests to verify that the new algorithm works properly.  I can also retain my circuit verification methods since that will not need to change.

One other assumption that my circuits make is that wires are perfect.  There is no delay calculated for wires.  Wires are represented by the wire object and the connection object so I can add delay time to these.  However, the delay time for a wire depends on it’s diameter and length.  Both of these are not normally known until a physical design is determined.  For now, I’m going to continue to assume a delay of zero, but anyone using this code to simulate a circuit should be aware of this limitation.

I guess it’s time for me to get to work…

 

The ALU

Summary

I’ve added the 74181 ALU TTL circuit to my logic simulator.  This blog post will discuss the differences between this ALU and the 74381 that I discussed about in a previous blog post.

The 74381

I added the 74381 ALU (Arithmetic Logic Unit) circuit to the logic simulator a few weeks ago and then I decided to build some real circuits to experiment with.  I mentioned in my previous blog post that the 74381 was not available for purchase (at least I haven’t found a supplier yet).  I decided to add the 74181 circuit to the emulator.  This circuit has a few quirks.  First, there are two truth tables in my logic book: Active High Data and Active Low Data.  The same circuit can be represented as though the outputs are inverted or not.  The difference is that the logic functions that are used are in a different order in the logic table.  For instance: In the active high version the A plus B function is activated by S0-S3 equal to H,L,L,H and the carry in must be H.  In the active low version, the s0-s3 are identical but the carry in must be L.  For the F = 0 function in active high, S0-S3 must equal L,L,H,H and M equals H.  For active low S0-S3 must equal H,H,L,L and M equals H.  Oh what fun.  So I chose the active high table and just setup my unit tests to assume that the outputs match that setup.  The fact that this chip can represent active high or active low means that there are 4 select bits or what seems like 16 functions.  However, there are functions in active high that are useless because the selector is used for active low functions.

The functions that are supported by the 74381 are also on the 74181:

  • Clear
  • B – A
  • A – B
  • A plus B
  • A + B (OR)
  • AB (AND)
  • A xor B
  • Preset (all 1’s)

The 74181 also supports not A, not B and A = B.
Here’s the circuit for the 74181 (click to see full sized image):

ttl_74181

I had a lot of fun creating that circuit in Visio.  I opted to create gate 57 as a special negated input OR gate instead of using two inverters on the input.  I’m only testing this circuit with the “perfect” TTL circuit.  I might have to do some fancy foot-work to make the timing come out right for the real circuit.  My point in mentioning this is that the reason why gates are represented with negated inputs instead of showing two inverters is that the circuit inside the chip is created with transistors and it was designed as a special negative input OR gate to cut the delay time.  If an additional transistor is used on each input as inverters, then the circuit path for gate 57 will be slower.  It appears that this circuit was designed to equalize the delay time from the inputs (a0-a3 and b0-b3) to the inputs (f0-f3) and to reduce any transients that can occur if one path is longer than another.  Although the inverter on b0-b3 probably causes a delay between the a and b inputs.  As you can see by the next diagram there are 7 levels of gates that a signal must pass through (no feed back paths):

ttl74181_critical_pathGates 34 through 36 appear to be behind the row of AND/NAND gates in zone 4, but they are at the same level of circuitry.  No signal goes from level 4 to level 5 without passing through a gate.  There is even a one-input NAND gate to ensure that the signal delay through gate 37 is equal to all other signals arriving at gate 53.

One thing I discovered while researching ALUs is that this circuit shows up in a lot of class exercises for electronic engineering classes.  I’ve found some pretty good power point slides showing the basics of half and full adders up to the 74181 circuit itself.

Here’s some history of the 74181 that explains why it’s so popular: http://apollo181.wixsite.com/apollo181/about.  The 74181 also has it’s own Wiki: https://en.wikipedia.org/wiki/74181.  One thing to note is that there are two circuits shown for this chip.  The TTL logic book has the circuit that I translated into Visio above and many of the on-line references, including the wiki page, show a slightly different circuit.  When you look at the circuit diagram in the Wiki article you’ll see an AND gate and an inverter instead of an XOR gate.  This is not a direct substitution as you can see from this:

xor_vs_and_inverter

I have not investigated the reason for this difference and it could be a correct circuit with a difference in the selection of the functions used by the chip.  I also stumbled across a data sheet for a Motorola brand 74181 and it had a wiring mistake on the circuit diagram:

motorola_datasheet_mistakeConnecting two inputs to the same wire would be a short-circuit.  If you go to the Wiki article you’ll notice that the M wire should be inverted and should connect to the other wire of the NAND gate at the bottom.  The Cn wire should connect directly to the NAND gate where it currently connects (after the inverter).

The circuit above came from my Logic Databook, which was published by National Semiconductor in 1981.  That circuit works correctly according to the unit tests that I setup (using the Active High Data truth table).

Where to get the Code

You can go to my GitHub account to get the latest and greatest code (click here).  This project is still in the research phase so there will be changes coming.  You can get the specific version of this code for this article by downloading this version: (click here).

 

Legacy Storage

Summary

In this post I’m going to talk about legacy storage and the pitfalls of not upgrading and moving your data to newer technology.

A Little History

This post comes from some of my own experience.  My first commercial computer was the Macintosh.  I’m talking about the 128k original Macintosh with a 400k single-sided floppy drive.  The floppy was a 3.5 inch format, but the method of storage was different from the later drives.  The first Mac drives used a variable speed rotation to store the same amount of information on the inner track as the outer track of the floppy disk.  When the PC began to use the 3.5 inch floppy, the spindle speed was fixed and they floppy disk stored 360k per side.  Later, the Fat Mac (512k memory) and then the Mac Plus (SCSI interface, memory slots up to 4 meg) upgrades were introduced.  Somewhere in those upgrades I ended up with an 800k double-sided floppy drive.  This is the drive that I currently have in my Mac Plus.  I transitioned to a PC between 1991 and 1995.  I finally went full-on PC in 1995 because of Windows 95, which allowed me to ween myself off of the superior graphical interface of the Mac IIsi (the Mac II was on loan to me from my brother who was overseas at the time).

Over the years of using my Mac (between 1984 and 1993ish) I built up a collection of floppies.  I also had a 40meg external SCSI drive that I had files on.  Over the past 4 years, I’ve been lamenting the fact that I did not copy all of my software off the Mac and onto a PC.  The dilemma came when I realized that I had no method to get from the early 1990 technology to today’s technology.  SCSI version 1 is obsolete and I couldn’t find a hard drive to work on the Macintosh.  The floppies cannot be read by any floppy disk hardware today because of the variable speed technology used at that time.  Also, floppies went obsolete right after the super disk came out (and died a quiet death due to the hope that CDs would become the new storage method).  Now the preferred external storage device is the USB thumb drive.  The old Mac doesn’t know what a thumb drive is!  Network transfer?  That version of the Macintosh was pre-Internet.  When I connected to the Internet in the early 90s with that machine, I had a 1,200-baud modem (ah, the good ole’ days).

I’ve scoured the Internet in the past and came across sites that would convert disks for a fee, but I wanted to scan my disks and determine if they were salvageable.  Also, my disks are more than 20 years old now and that means that many probably are not readable any more (I’m actually surprised at how many still worked).  Late last year I came across this device: http://www.bigmessowires.com/floppy-emu/.  This circuit is an emulator that attaches to the external floppy port on a Macintosh (it works on Apple II computers as well).  It has a Micro SD card that you can write 20 megabyte external hard disk images that the Mac recognizes and will boot from.  Then there is a program for the PC called the HFV Explorer: http://www.emaculation.com/doku.php/hfvexplorer that can mount the image files and navigate Macintosh files in a window.  Then the ability to drag and convert data files can be done from this application.

So I promptly converted as many files as I could and discarded my old floppies (since they’re just collecting dust in my closet).

I have all my files copied onto images and saved them on my PC hard drive.  These are backed up with my Internet backup tool so there’s no chance of losing anything.  I have also converted some of the text based files onto my PC.  I had a lot of pascal programs that I wrote and it’s nice to be able to look back and reference what I did back then.

One type of file that is frustrating to convert is the Mac Draw files.  I have schematics that I drew on the Mac and saved in that format.  I currently use Visio, but Mac Draw (or Claris Draw) is not convertible into anything current.  I have a working version of Mac Draw and I can boot up my Mac Plus with the emulator and a 20 meg hard drive and open a Mac Draw file.  Unfortunately, there is no format that it saves in that can be used on a PC.  So I was forced to take some screenshots of schematics with my camera (oh yeah, that turned out great!  No, not really) just so I don’t have to boot up the old Mac when I want to see the circuit.

How to Protect Your Files

As you’ve discovered from my story and if you’re old enough to have used many iterations of computer technology, there are two problems with computer storage.  First, the technology itself becomes obsolete.  Second the file formats become obsolete.  I’ve scoured the Internet looking for the binary format of Mac Draw.  This was a proprietary format so it’s not available.  Also, the format went obsolete before the Internet really took off, so it wasn’t archived.  I’m sure the format is saved someplace in Apples legacy files.  There are some file converters that can convert from Mac Draw onto newer software, but it’s for a newer Macintosh and I’d like to convert to MS Visio.  Maybe I’ll do my own hacking.

I’ve read articles where NASA has struggled with this issue in the past.  They have converted their space probe data from mainframe hard disks to laser discs and I’m sure they are now using some sort of cloud storage.  Fortunately mass storage is so cheap these days that if you can get your files there, then you have plenty of room to store it.  The cloud storage has the added benefit of never going obsolete because the hard drives used are constantly upgraded by the provider (Amazon, Google, Microsoft, etc.).  Looks like NASA has a web portal to dig up any data you would like: https://www.nasa.gov/open/data.html  Very nice.

If you’re a programmer, like me, you’ll want to make sure you keep your files transferred to a newer storage.  Converting from one technology to another can be a real challenge.  If you convert between Unix, Mac or PC, you’ll need to figure out how to convert your files early on.  If you can’t, then you might be able to get an emulator.  For DOS programs, I use DOSBox.  I can use the DOSBox emulator to play all my old DOS games (such as Doom, Heretic, Descent, etc.).  There is a lot of interest in resurrecting retro arcade games and retro consoles.  The Raspberry PI has hundreds of retro games that can be downloaded and played.  So keep your games.

I don’t see any future where the USB hard drive will become obsolete, but I thought the same about the 3.5 inch floppy.  So avoid keeping your files on external devices.  Most people have enough hard drive storage these days that external device storage seems foolish.  I currently only use SD cards, Flash cards or USB drives to transfer files to and from my hard disk.  My most valuable files are the files that I create myself.  Those are either backed up to the Internet or I check them into GitHub.  Everything else is replaceable.  Always think about what would happen if your computer were destroyed in a fire or natural disaster.  What have you lost?  Make sure you have some method to recover your files.

Another type of file that needs some thought is the photo.  Photographs used to be stored in albums and shoe boxes (at least that’s where I put ’em!).  A few years ago I scanned all my old 35mm photos and stored them on my computer.  I had photos from the early 80’s when I was in the Navy.  These photos were turning yellow and they were stored in shoe boxes where nobody could enjoy them.  After I scanned them in, I converted some with Photoshop to correct the color and brightness.  I forgot how good those photos used to look.  More importantly, they are backed up on my Internet storage.  I also borrowed my parents photo albums and scanned those photos.   Here’s a picture of the Mackinac bridge from 1963 (I was less than a year old at the time):

macinac_bridge

Organizing Your Files

The final problem you’ll run into is how to find your files.  This takes some organizational skills.  I have all of my digital photos stored by date and title.  When I come home from a hike and I copy files from my Cannon Rebel, I store the files in my photos directory (of course) in a new directory that starts with the year, month then date (so they sort right).  Then I put a title so I can scan down and see what the photos represent.  For example, my wife and I visited the Smithsonian annex in Virginia on August 8th of last year, so my directory is: “2016-08-13 Smithsonian Annex”.  All of my raw photos go into that directory.  If I crop a photo or fix the color, I give the photo a new name and I might even put it in another directory.  The photo above is a reduced size photo.  The original is over 2000 pixels by 2000.  In the future I see the need for a database to track photos, but I haven’t figured out how to get the data organized in a fast and easy way.  The ultimate database would have different key words that can be searched on, like the location of the photo, who is in the photo, the date of the photo, who took the photo, etc.  Then I can search for all the photos of my wife and I when we were on vacation in July.  Currently, I have to scan through all the thumbnails and look for our faces.

Over the years I’ve changed my methods of organizing files.  Some of those files are still in the same directories that they were in when I first created them.  I left them this way because I know where to find them.  I remember an old professor in college with piles of papers in his office claiming that he has a “system”.  He then proceeded to pull the exact paper out of the middle of what looked like a random pile.  Yeah, that’s me.  In fact I have a root sub-directory called “d_drive”.  Back in the day,  I owned a 1.9 Gig hard drive that I installed in my DOS machine.  Unfortunately, DOS at the time had a limit to the size of a partition on a disk, so I had to create 3 or 4 partitions on this hard drive and one of the drive letters was D:.  This is where I kept all my source files for games that I was working on.  When I upgraded that machine to an 8 Gig hard drive, I just copied the partitions to sub-directories on the new drive.  Of course, I just named the directories “d_drive”, “e_drive”, etc.  That directory has not changed much since.   That drive is currently on my new 4 terabyte drive.  Too many sub-directories and files inside there to try and re-organize it now.

Organize your files before you acquire too many files!  Eh, nobody does that.  I didn’t recognize that I needed a system until it got out of control.  Having files on floppies made things difficult as well.   I had a filing system back then, but it was still a bit painful to find a file.  Just be aware that you’ll fall into this trap eventually.

Obsolete Files

If you have files that you can’t read anymore because you don’t have the program that created them.  Save them.  Search the Internet for a solution.  Someone out there probably has those files and have experienced the same problem.  Maybe a device, program or emulator will come along and save your files.  Storage space is cheap.  There is no need to throw away files unless you really want to get rid of them.  Try to keep your programs as well.  Sometimes that’s not feasible due to licensing issues.  Sometimes you’ll need to use an emulator (like DOSBox) to run your old programs.  Make sure you keep your license numbers in digital format in a location you can find quickly.  I have a directory containing files of everything that I have installed on my PC.  I keep all my license information in this directory (which incidentally has sub-directories labelled as the name of the software installed).  Steam has made it easier to keep track of Games that I have purchased.  At least I can always get into my Steam account and re-install a game I previously purchased without digging around for the CD/DVD and the license number.  Other programs such as Photoshop need the license number to activate.

I will also download the install file and save those.  If I upgrade my computer hard drive and I need to re-install, the installation medium might not be available to download for the version that I have a license for.  I’ve run into that problem before and it’s quite annoying to be forced to purchase a new version just because I can’t obtain the old installation material.

One last way I avoid obsolete material is that I have signed up for annual contracts on a couple of programs I’ve used over the years.  Microsoft Office is one of them.  I recently analyzed how many times I have upgraded (I used to upgrade every two or three years) and for the $99 a year price, I can get 5 copies of Office 365 and not deal with the process of purchase and upgrade.  You’ll need to analyze the cost and usage to determine if it’s worth the price to go that route.

Finally…

If you have unique ideas on how you keep ahead of the legacy battle, feel free to send me an email or leave a comment.  I’ll be happy to share your information with anyone who stumbles onto this blog.