Tuesday, December 31, 2013 0 comments

Learning the Java Language, Part 58: Annotations

Annotations are not really code, because they don't affect the way the program runs, nor are they comments, which don't affect the program at all. What annotations affect are the way the compiler acts while processing the program.

In the following posts, I'll look at some of the different things you can tell the compiler to note about a program using annotations.

Next up: Annotations Basics
Friday, December 27, 2013 0 comments

Complex Programmable Logic Devices

Previous: Programmable Logic Devices

In the previous post I talked about Programmable Logic Arrays (PLAs) and Programmable Array Logic devices (PALs). These types of devices tend to have a total number of inputs and outputs of less than 30. For more complex Programmable Logic Devices (PLDs), there are the aptly-named Complex Programmable Logic Devices (CPLDs).

A typical CPLD architecture can be described as multiple PAL-like blocks interconnected to each other with configurable switches and also connected to I/O pins.

For CPLDs for which the number of I/O pins is very large, as in over 200, it can become impractical to program the device using a dedicated programmer, since the pins on the chips are quite thin when the number of pins is so great, making them susceptible to bending and breaking when inserted into and removed from a socket for programming. Also, custom sockets for chips with so many pins tend to be very expensive as well. For these reasons, instead of using dedicated programmer devices, there is an IEEE  standard for an onboard programming port that allows chips already soldered in their final destination to be programmed in situ. It is called a Joint Test Action Gropu, or JTAG, port. Users connect the proper cord to a computer and send the CPLDs the data necessary to program them which is generated by a CAD program.

Next: Field-Programmable Gate Arrays
Friday, November 1, 2013 0 comments

Learning the Java Language, Part 57: Q&E: Enum Types

Questions and Exercises. Here are my answers and solutions to their questions and exercises.

  1. True or false: an Enum type can be a subclass of java.lang.String.
    False. Enum types are already of type java.lang.Enum, which is a subclass of type java.lang.Object. Java doesn't support multiple inheritance.
  1. Rewrite the class Card from the exercise in Questions and Exercises: Classes so that it represents the rank and suit of a card with enum types.
    Here is my EnumCard.java.
  2. Rewrite the Deck class.
    Here is my EnumDeck.java.
Next up: Annotations
Thursday, September 5, 2013 0 comments

Programmable Logic Devices

Previous: Standard Chips

In the previous post I talked about chips with set logic functions burned into them that users could connect together to achieve more complex logic functions. There are also integrated circuits that can be programmed to implement user-specified logic functions.

Programmable Logic Arrays
PLAs which take n inputs \(x_1\) to \(x_n\) and have m outputs \(f_1\) to \(f_m\) usually have an architecture that enables the user to create a custom sum of products logic function by first feeding the n inputs into a buffer and inverter plane, giving 2n outputs being the input values \(x_1\) to \(x_n\) and their complements \(\overline{x_1}\) to \(\overline{x_n}\).

The buffer and inverter plane feeds into an \(\text{AND}\) plane in which there will be some predefined number l of \(\text{AND}\) gates, each having 2n programmable inputs that can act as either closed or open connections to the outputs of the buffer and inverter plane forming products of the inputs or their complements. What any of those l products is depends on which connections the user has programmed to be closed.

The \(\text{AND}\) plane then feeds into an \(\text{OR}\) plane in which there will be m \(\text{OR}\) gates, each having l programmable inputs that can act as either closed or open connections to the outputs of the \(\text{AND}\) plane forming sums of the products.

Here's a visual conception of a PLA that has three input pins \(x_0, x_1,\) and \(x_2\), three \(\text{AND}\)ing gates, and three \(\text{OR}\)ing gates. The chip manufacturer could just as easily have a different number of \(\text{AND}\) gates in the \(\text{AND}\) plane and a different number of \(\text{OR}\) gates in the \(\text{OR}\) plane, changing the allowable form of the resulting SOP functions programmable with the chip:
PLA Schematic
 To implement a specific SOP, you would fuse the desired complemented or uncomplemented inputs in the \(\text{AND}\) plane and you would fuse the desired products you want to sum in the \(\text{OR}\) plane. With a chip such as the one in the image above, you could create up to three SOP functions.

Programmable Array Logic
The PLA example in the previous section has 27 internal fusible switches that the hardware  of the chip can set to either open or short. A simpler design, though able to produce fewer logic functions, is to keep fusible switches in the \(\text{AND}\) plane but directly connect the output of the \(\text{AND}\) plane to the input of the \(\text{OR}\) plane in a predefined fashion. This type of device is called a programmable logic array (PLA). Whether all or some of the outputs of the product terms of the \(\text{AND}\) plane go to one or more summing gates in the \(\text{OR}\) plane is fixed at the time of manufacture.

Take a look at the following image. A slightly different schematic notation is being used. Each \(\text{AND}\) gate still has six separate inputs—not one, but to make the drawing less busy, only one line is drawn at the input. Those inputs that are actually connected to the outputs of the inverter plane are drawn with an '\(\text{X}\)' at the intersection with the drawn input line. The user can configure which outputs of the inverter plane connect to the inputs of the \(\text{AND}\) plane.
PAL Example
As stated, with PAL devices, the configuration of the \(\text{OR}\) plane of a PAL device is fixed. So in the image above, output \(f_0\) implements the logic function \((x_0 \overline{x_1}\, \overline{x_2}) + ( \overline{x_0} \, \overline{x_1} x_2 )\), and \(f_1\) implements the logic function \((x_0 x_1 x_2) + ( \overline{x_0} \, \overline{x_1} \, \overline{x_2} ) \)

Programming PLAs and PALs
So how, in practice, does a user, using the interface of the device's pins, specify the short circuit/open circuit configuration of each of the internal fuses at the gate level in order to implement the desired logic function? Originally, the maker of a given chip also was the one to go to in order to purchase a device programmer, but now there are device programmers that can take as input a file that is the result of a user using a computer application to design the desired logic function. The user designs the desired function on the computer, selects the target chip from the list of available targets, and sends the machine-level instructions to the device programmer, which generates the necessary low-level voltage/current levels at the pins of the chip to program the desired function in.

Next: Complex Programmable Logic Devices
Tuesday, July 23, 2013 0 comments

Learning the Java Language, Part 56: Enum Types

Enumerated types are used to define a type that can take as a value one of a specified set of constant (in Java terminology, final) values.

In Java, in fact, enum types are classes in that they can have constructors, member fields, and methods.

But first, here's a simple example: say you are writing code to model a playing card and you want it to have a field called suit for the card's suit. If you chose to use an int to represent the suit value and stick to a standard like 0 = diamonds, 1 = hearts, 2 = spades, 3 = clubs, it would still be possible for a given card's suit field to get a garbage value like -453. Every time you wrote some code to set or use a card's suit field, you'd have to validate. The same thing would happen if suit were a String.

For something as simple as this, it's probably more practical to declare the enumerated type Suit inside the class it is going to be used (e.g. a class called Card). But an enumerated type called Suit could just as easily be in a file of its own called Suit.java.

Here's class Card with enumerated type Suit, and here's a class with a main method that creates an int rank and a Suit suit and creates a Card with the Card constructor and calls its toString() method and displays the String returned.

So notice that the syntax of an enumerated type that only has the constant values it can take (no constructors, fields, or methods) is public enum followed by the name of the enumerated type followed by an open curly brace { followed by a comma-separated list of the constant values the type can take (convention is to make these all caps) followed by a close curly brace } (note no semicolon after the comma-separated list in this case).

One thing you get for free whether or not your new enumerated type has any constructors, fields, or methods is the ability to get a  static method values() that returns an array of all the values your enum type can have. This is useful if you want to iterate a variable over all the values of your type in a for loop.

Say you had deck, an array of Card objects and you wanted to put a new Card in each slot so that each index in deck had one of the 52 possible values (1-13 of diamonds, hearts, spades, and clubs). You could use a nested for loop structure with the outer loop iterating through all possible Suit types and for each Suit type an inner for loop iterating from one to 13 for each possible value of ace, 2-10, jack, queen, and king of the current suit.

Card[] deck = new Card[52];

int j = 0;
for( Suit current : Suit.values() ) {
   for( int i = 0; i < 13; i++ ) {
      deck[ (j * 13) + i ] = new Card( i + 1, current );

Note the use of an int variable j to keep track of how many 13-long blocks we are into the deck array (the index of the jth block's beginning plus the ith index into that block gives the current deck position). Note also that the inner loop iterates from 0 to 12, while the values go from 1 to 13, which is why i + 1 is used in the Card constructor.

For enumerated types with fields, constructors, and methods,  place a semicolon at the comma-separated list of predefined constants. We could rewrite the Suit enumerated type so that each suit has an associated integer field so we don't have to create and manage a counter variable like j in the example above. If we added a private int field cardinality, a constructor that set cardinality, gave the enum constants constructor arguments, and added a getter method so we could access the field, Suit would look like this:

public enum Suit {
    HEARTS( 0 ),
    DIAMONDS( 1 ),
    SPADES( 2 ),
    CLUBS( 3 );
    // integer assigned to suit
    private final int cardinality;

    // constructor for suit objects
    Suit( int cardinality ) {
        this.cardinality = cardinality;

    // method for accessing cardinality of suit
    public int getCardinality() {
        return this.cardinality;


So if this were the type of Suit we had, the nested for loop in the snippet above would look like this:

Card[] deck = new Card[52];

for( Suit current : Suit.values() ) {
   for( int i = 0; i < 13; i++ ) {
      deck[ (current.getCardinality() * 13) + i ] = new Card( i + 1, current );


The enhanced for loop iterates over each enum constant exactly once without needing our cardinality integer, but cardinality helps us find the right position in the deck array.

Next up: Questions and Exercises: Enum Types
Monday, July 15, 2013 0 comments

Standard Chips

Previous: CMOS Logic Gates

If logic gates are the building blocks of digital logic circuits, standard chips are the commercially available LEGO versions of those blocks you can buy at the store and easily interconnect as desired.

There are many kinds of standard chips available, like the 7400, which has four NAND gates inside, or the 744002, which has two 4-input NOR gates inside. There are very many standard chips in the 7400 series, which is just one of a number of series of integrated circuit chips. There isn't one single company that makes, for instance, the 7400 quad NAND gate; if your piece of hardware had a Texas Instruments 7400 chip in it and something happened to it, you could drop-in replace a 7400 chip made by Fairchild without having to redesign your circuit board because there is a standardization as far as the pinouts and numbering of the 74xxx chips. In other words, 74 followed by two 0s is very sure to mean quad NAND gate chip and regardless of what company made the chip, you can reliably count on pin n of one chip to be the same input or output from chip to chip.
Image Credit: Wikipedia
So to use the image above as an example, knowing the pinout of a SN7400N made by TI (the 'SN' indicates manufacturer TI and the 'N' suffix indicates the plastic dual inline package (DIP) physical form factor), if your circuit depended on pins 1 and 2 being the input to a NAND gate and pin 3 being the output, you could replace it with a National Semiconductor DM7400N (the 'DM' indicates National Semiconductor, and the 'N' means the same as described above) and count on the pinout and voltage characteristics to be the same.

There are variations that can be indicated by letters between the 74 and the numbers that really tell what kind of chip it is. For instance, if you see a 'C' between the 74 and the 00 of the 7400 chip, that tells you that the chip uses CMOS transistors inside to implement the NAND gates, while the 7400 without the 'C' is implemented with bipolar junction transistors, a different kind of technology than CMOS.

There are other codes that can go between the 74 and the type-identifying numbers, like 'L' indicating lower power requirements, 'F' indicating faster performance, and more. Of course, Wikipedia has a good article on the 7400 series. From that article, it is mentioned that the '74' indicates the temperature range the chips can handle. 74xx chips have a "commercial" temperature range, and 54xx chips would have the same type numbering scheme but have a wider "military" temperature range. So a 5400 chip would be a quad NAND chip, but be able to handle lower cold operating temperatures and higher hot operating temperatures than a 7400 chip.

There's also the 4000 series of standard chips, which doesn't have the same type numbering as the 7400 series. These standard chips have lower power consumption, but are slower than their (differently numbered) 7400 series counterparts.

When prototyping the early stages of your design (and maybe even when implementing your final design), using standard chips is often an acceptable solution in terms of cost and flexibility.

Next: Programmable Logic Devices
Friday, July 12, 2013 0 comments

Learning the Java Language, Part 55: Q&E: Nested Classes

Questions and Exercises. Here are my answers and solutions to their questions and exercises.

  1. The program Problem.java doesn't compile. What do you need to do to make it compile? Why?
  2. Inner is a nested class in Problem and is static, but its method testMethod() tries to access Problem's non-static String s. To make this code compile, you can make s static by switching the line

    String s;

    with the line

    static String s;

  3. Use the Java API documentation for the  Box class (in the javax.swing package) to help you answer the following questions.
    1. What static nested class does Box define?
    2. What inner class does Box define?
    3. Box.AccessibleBox
    4. What is the superclass of Box's inner class?
    5. Container.AccessibleAWTContainer
    6. Which of Box's nested classes can you use from any class?
    7. Box.Filler
    8. How do you create an instance of Box's Filler class?
    9. Box.Filler filler = new Box.Filler(minDimension, prefDimension, maxDimension);
  1. Get the file Class1.java. Compile and run Class1. What is the output?
  2. InnerClass1: getString invoked.
    InnerClass1: getAnotherString invoked.
Next up: Enum Types