20 Apr 2013

Microprocessors part 1 - Introduction

The microprocessor has evolved a lot in the past 40 years since its debut in November 1971, with the Intel 4004 chip. Nowadays, we have a huge amount of different processing units to do electronics, control systems, robotics, etc...

The microprocessor can be seen has a large electrical circuit that can be serve a lot of different purposes and that needs to be supplied with a "binary file" of instructions to execute. The piece of silicon that doesn't change (microprocessor) is called hardware. The supplied binary code is called the software. By definition, hardware is fixed and software can be modified (with programming). I want to emphasize that point because I'll come back to that when discussing soft-core and hard-core in a FPGA. Throughout this article, I'll give practical examples with the PicoBlaze processor, which is a very simple soft processor core.

Computer bus

A bus in computing can be seen as a kind of highway for data. This highway can have several lanes (parallel bus) or the cars can line up one after the other (serial bus). This highway connects the different sub-systems of the computer. To show you the importance of device interconnect/communication here are some examples of common wired interface:

Peripheral

  • USB (Universal Serial Bus)
  • RS-232
  • FireWire
  • Thunderbolt

Printed circuit board

  • I²C (Inter-Integrated Circuit)
  • SPI (Serial Peripheral Interface)
  • 1-Wire
  • PCI (Peripheral Component Interconnect)
  • AGP (Accelerated Graphics Port)

Network

  • Ethernet
  • CAN (Controller Area Network)
  • RS-485

Video

  • VGA (Video Graphics Array)
  • HDMI (High-Definition Multimedia Interface)
  • DVI (Digital Visual Interface)

Hard drive

  • SATA (Serial Advanced Technology Attachment) 
  • IDE (Integrated Drive Electronics)

Internal IC buses

Even more important for today discussion, there is a lot of different buses inside integrated circuits to connect the different memories/caches to the processing unit and the inputs/outputs.

Program memory

The program memory is where the microprocessor program instructions are stored. This memory has a fixed width that matches the computer instruction width. It is sometimes considered as a ROM (Read-only Memory) because the program storage don't change while the processor is running. Here is an excerpt of the 18-bit PicoBlaze instruction set; that is, available instructions opcode understood by the processing unit.


Data memory

The data memory is used to store temporary data/variables. This kind of memory is also called the RAM (Random-Access Memory). You can see it like a kind of scratchpad area, where you can make some calculations on it and retrieve it later for other uses. Some CPU can process RAM directly, some others using the Load/Store Architecture have to switch this data back and forth in their internal registers to process it.

Harvard versus Von Neumann architecture

There is basically two kind of architecture to access memories. The Harvard architecture can access the program and data memory independently because it has two distinct buses to access them. In the Von Neumann architecture, the program and data memories share a single datapath. With a single memory bus, the processor will be less complex, but will also be slower than with separate buses. The Harvard architecture is mainstream now because of the Von Neumann Bottleneck.

CPU

The CPU (Central Processing Unit) is where everything is processed in a computer. Let's take a look at the internals schematics of the 8-bit PicoBlaze core:


At the top-left corner, there is the program memory. In this case, it's limited to 1024 18-bit instructions. The next block at the right is a small 10-bit pointer register called the PC (Program Counter). It is used to store the address of the next instruction to be executed. It can address all the 1024 instruction because it is 10 bits wide (2^10=1024). In the PicoBlaze, there's a quite small amount of RAM, only 64 bytes. There is however 16 registers that you can use for general purposes.

The CPU specific components in this schematics are the registers, PC, instruction decoder, buses and the ALU (Arithmetic Logic Unit). The ALU is the heart of the CPU, it's used to process the data that are brought to it by the different buses. You can see that it has 2 input buses and one output bus that work in conjunction with the registers. Everything that has to be processed has to be in the registers and is stored back in the registers. That it why it's a Load/Store Architecture core, there is no direct access between the ALU and the RAM. By the way, that PicoBlaze has a separate bus for instructions and data (as you can see above), so it's an Harvard processor.

The big arrows at the far left and right of the schematic is the interrupt line and the IO. It is what allow the PicoBlaze to talk and interact with the external world, like sensors and actuators.

MCU (µC)

A last thing I would like to discuss about is MCUs (Microcontroller Unit). A microcontroller contains all we've talked about previously on a single chip. They are mostly used in embedded systems, where they do  repetitive tasks in a reliable way.

In contrast, personal computers have a motherboard with separate components : CPU, GPU, RAM, hard drives, etc. They have much larger memories and faster clock frequencies.

The advantages of µC are their low cost and small power consumption. They're all around and you don't even see them; watches, Bluetooth headset, keyboard/mouse, microwave oven, remote control, digital photo frame, radio...

Conclusion

In the next part of this article, I'll write a little tutorial on PicoBlaze ASM programming and you will be able to simulate it on your computer!

14 Apr 2013

Digital Systems Part 4 - Decoder for 7-segment display

In one of my latest post about digital systems, I talked about the different types of combinational circuits. Let's take some time to discuss about the decoder and one of it's most widely known utilization: driving a seven segment display.

The seven-segment display




It is likely that you've already seen a 7-segment in a numeric watch or clock. This device contain 7 LEDs (hence 7-segment) enclosed in a small plastic case. It is generally used to display decimal digits from 0 to 9 (and display hexadecimal digit A to F). There are also some version of the 7-segment that contain a decimal point LED.

Being a 7-bit device, the 7-segment can display 128 (2^7) different "symbols". Take a look at this chart that shows all the possible combinations :



Driving the display with a decoder

The fact is that we don't really need all these combinations. We can then cut down 3 bits and have 16 (2^4) possible patterns, enough to hold the numbers 0 to 9. This is the goal of the 4 bit in, 7 bin out decoder as shown below :


In the picture, you can read the term BCD (Binary Coded Decimal) that means a 4-bit code representing the decimal digit coded in binary (as the name imply). The BCD to seven-segment decoder can be implemented with simple logic gates (see picture below).



The CD4511 to the rescue

I already implemented a 7-segment display decoder with 74 series logic gates when I was in college and it was quite a challenge to get it working (without doing any wiring mistakes)! Integrated circuits like the CD4511 does the same thing, but in a tiny DIP package. Here is the basic schematic of a circuit using the decoder :



The "Lamp test" pin is used to light all the LED on the seven-segment to check if it's working properly. The "Blanking" pin does the opposite, it blanks the display. These two pins can be tied to the positive power rail as they are rarely used. The "Latch enable" pin, when pulled down to the ground, refresh the display with the current input (A0 to A3). The wiring is pretty straightforward, below is two pictures of what it looks like on a breadboard :




The CD4511 in action

There is multiple way to drive a decoder. It can be with simple DIP switches, or driven by a microcontroller. In the second video, I use 4 outputs of the Parallax Propeller to drive the chip. In the program I made, the delay between the counts is randomized between 150-1000 ms so the result is a bit more interesting...



13 Apr 2013

The op-amp as a comparator : temperature change detection circuit

In this post, we're going to take a brief look at one way of using an operational amplifier. To test the op-amp as a comparator, we will build a small and simple working circuit. Before diving in, let's take a moment to discuss about the operational amplifier.

Operational amplifier theory

The operational amplifier is a type of amplifier that can be use in a lot of different arrangements to create filters, comparators, integrators, inverting/non-inverting amplifiers etc... In the picture below, you can see the schematic representation of an op-amp and it's different terminals.


As you can see, it needs a positive and negative power supply. The op-amp has an electrical caracteristic called the open-loop gain. This gain is really high and usually range from 100,000@1,000,000. In open-loop, the relation between the output and inputs is dictated by this formula :


It is important to remember that the voltage on the output pin can only swing between the positive and negative supply voltage.

Op-amps are packaged into chips. It's possible that there are multiple op-amps in the same chip. Here is the pinout of the CA3140 IC :



Comparator mode

The principle of operation of the comparator mode is quite simple. In the equation, if the result of the substraction in the parenthesis is positive, the output will equal the positive supply (because of the high open-loop gain). If it's negative, the output will be limited to the negative supply, ground in most of applications. Briefly said (with a LED connected at the output) if V+ is at an higher voltage than V- the LED will be on.

Single supply (rail-to-rail) vs. dual supply

Most op-amp cannot drive it's output signal to their supply, only close to. If you want the output to go completely from a supply to the other, you need to order a rail-to-rail op-amp. These ones can be a little bit pricier. Let's take a look at the internal of a cheap dual supply op-amp that I purchased from Tayda Electronics.



I highlighted in red the components that limit the output pin from going all the way to the supply pins voltage. In the upper part, you have a diode (D7) with a forward drop of 0.7 volt and a transistor (Q18) that will saturate at 0.2-0.3 volt. This means that we cannot go higher than about 1 volt below the positive supply rail. For the negative supply, the transistors (Q15&Q16) will limit the voltage from going lower than 0.2-0.3 volt if the negative pin is tied to ground. By example, if we connect an op-amp to a 12 volt supply source, it's outuput will swing from 0.3 to 11 volts.

The temperature detect circuit




To demonstrate the comparator mode of an operational amplifier, I made a little circuit that use a thermistor. It detects a change of temperature above the ambient room temperature. Take a look at the schematic :


The thermistor is a resistance that is varying with the temperature. At the room temperature, the measured resistance is about 10kΩ, but when I touch it with my finger, it rapidly drop to 7kΩ. The 10kΩ fixed resistor in series with the thermistor make a voltage divider.

At ambient temperature, there is 6 volts at the voltage divider but when I touch the thermistor, the voltage goes a little bit below 5 volts. The output of the voltage divider is brought to the inverting input (-) of the op-amp. I want to compare this to 5 volts, so I used a 5V voltage regulator at the non-inverting input (+) (I was too lazy to make a 5V voltage divider from resistors). When I touch the thermistor with my finger, the (+) pin voltage is above the (-) pin voltage so the output goes almost to the positive supply. This cause the LED to light. (I changed the LED for a green one because the other one was too bright for the camera)



Conclusion

The principle of operation of this circuit can be transposed to a lot of different sensors or output device. It could have been a photoresistor (light detector) in place of the thermistor. We also could have replaced the LED by a fan so it could cool a hot device. Except for using an operational amplifier as a comparator, we rarely use it in open-loop (without any feedback). In a few articles, we'll take a look at other useful examples of circuits that uses an op-amp.