Tuesday 17 August 2010

Basic knowledge of Electronic parts

Resistors
The resistor's function is to reduce the flow of electric current.
There are two classes of resistors; fixed resistors and the variable resistors. They are also classified according to the material from which they are made. The typical resistor is made of either carbon film or metal film. There are other types as well, but these are the most common.
The resistance value of the resistor is not the only thing to consider when selecting a resistor for use in a circuit. The "tolerance" and the electric power ratings of the resistor are also important.
The tolerance of a resistor denotes how close it is to the actual rated resistence value. For example, a ±5% tolerance would indicate a resistor that is within ±5% of the specified resistance value.
The power rating indicates how much power the resistor can safely tolerate. Just like you wouldn't use a 6 volt flashlight lamp to replace a burned out light in your house, you wouldn't use a 1/8 watt resistor when you should be using a 1/2 watt resistor.

The maximum rated power of the resistor is specified in Watts.
Power is calculated using the square of the current ( I2 ) x the resistance value ( R ) of the resistor. If the maximum rating of the resistor is exceeded, it will become extremely hot, and even burn.
Resistors in electronic circuits are typicaly rated 1/8W, 1/4W, and 1/2W. 1/8W is almost always used in signal circuit applications.
When powering a light emitting diode, a comparatively large current flows through the resistor, so you need to consider the power rating of the resistor you choose.

Capacitors
The capacitor's function is to store electricity, or electrical energy.
The capacitor also functions as a filter, passing alternating current (AC), and blocking direct current (DC).
The capacitor is constructed with two electrode plates facing eachother, but separated by an insulator.

When DC voltage is applied to the capacitor, an electric charge is stored on each electrode. While the capacitor is charging up, current flows. The current will stop flowing when the capacitor has fully charged.

The value of a capacitor (the capacitance), is designated in units called the Farad ( F ).
The capacitance of a capacitor is generally very small, so units such as the microfarad ( 10-6F ), nanofarad ( 10-9F ), and picofarad (10-12F ) are used.

Breakdown voltage
When using a capacitor, you must pay attention to the maximum voltage which can be used. This is the "breakdown voltage." The breakdown voltage depends on the kind of capacitor being used. You must be especially careful with electrolytic capacitors because the breakdown voltage is comparatively low. The breakdown voltage of electrolytic capacitors is displayed as Working Voltage.
The breakdown voltage is the voltage that when exceeded will cause the dielectric (insulator) inside the capacitor to break down and conduct. When this happens, the failure can be catastrophic.

Diodes
A diode is a semiconductor device which allows current to flow through it in only one direction. Although a transistor is also a semiconductor device, it does not operate the way a diode does. A diode is specifically made to allow current to flow through it in only one direction.
Some ways in which the diode can be used are listed here.
A diode can be used as a rectifier that converts AC (Alternating Current) to DC (Direct Current) for a power supply device
Diodes can be used to separate the signal from radio frequencies.
Diodes can be used as an on/off switch that controls current.

Although all diodes operate with the same general principle, there are different types suited to different applications. For example, the following devices are best used for the applications noted.

Voltage regulation diode (zener diode)
It is used to regulate voltage, by taking advantage of the fact that Zener diodes tend to stabilize at a certain voltage when that voltage is applied in the opposite direction.

Light emitting diode
This type of diode emits light when current flows through it in the forward direction. (Forward biased.)Light emitting diodes must be choosen according to how they will be used, because there are various kinds.
The diodes are available in several colors. The most common colors are red and green, but there are even blue ones.
When an LED is new out of the package, the polarity of the device can be determined by looking at the leads. The longer lead is the Anode side, and the short one is the Cathode side.


Variable capacitance diode
The current does not flow when applying the voltage of the opposite direction to the diode. In this condition, the diode has a capacitance like the capacitor. It is a very small capacitance. The capacitance of the diode changes when changing voltage. With the change of this capacitance, the frequency of the oscillator can be changed.

Rectification diodes are made to handle relatively high currents.They are used to make DC from AC. It is possible to do only 'half wave rectification' using 1 diode. When 4 diodes are combined, 'full wave rectification' occurs.

Diodes are used to rectify alternating current into direct current. However, rectification will not occur when the frequency of the alternating current is too high. This is due to what is known as the "reverse recovery characteristic."
The reverse recovery characteristic can be explained as follows:
IF the opposite voltage is suddenly applied to a forward-biased diode, current will continue to flow in the forward direction for a brief moment. This time until the current stops flowing is called the Reverse Recovery Time. The current is considered to be stopped when it falls to about 10% of the value of the peak reverse current.
The Shottky barrier diode has a short reverse recovery time, which makes it ideally suited to use in high frequency rectification.

The shottky barrier diode has the following characteristics.

The voltage drop in the forward direction is low.
The reverse recovery time is short.

However, it has the following disadvantages.

The diode can have relatively high leakage current.
The surge resistance is low.

Because the reverse recovery time is short, this diode is often used for the switching regulator in a high frequency circuit.


Devices that combine 4 diodes in one package are called diode bridges. They are used for full-wave rectification.


Switching diodes can switch on and off at very high speed. However, the maximum current it can handle is 120 mA(???please find out).
Regulation diodes: when this type of diode is reverse biased, it will resist changes in voltage. If the input voltage is increased, the output voltage will not change. (Or any change will be an insignificant amount.) While the output voltage does not increase with an increase in input voltage, the output current will.
This requires some thought for a protection circuit so that too much current does not flow.

Transistors
The transistor's finction is to amplify an electric current.
Many different kinds of transistors are used in analog circuits, for different reasons. This is not the case for digital circuits. In a digital circuit, only two values matter; on or off. The amplification ability of a transistor is not relevant in a digital circuit. In many cases, a circuit is built with integrated circuits(ICs).
Transistors are often used in digital circuits as buffers to protect ICs. For example, when powering an electromagnetic switch (called a 'relay'), or when controlling a light emitting diode.

Integrated circuits
An integrated circuit contains transistors, capacitors, resistors and other parts packed in high density on one chip.
Although the function is similar to a circuit made with separate components, the internal structure of the components are different in an integrated circuit.
The transistors, resistors, and capacitors are formed very small, and in high density on a foundation of silicon. They are formed by a variation of printing technology.
There are many kind of ICs, including special use ICs.

Coils
A coil is nothing more than copper wire wound in a spiral.
Coils are sometimes called "inductors." Inductance is the measure of the strength of a coil. Capacitors have capacitance, resistors have resistance, and Inductors (coils) have inductance. When alternating current flows through a coil, the magnetic flux that occurs in the coil changes with the current. When a second coil is put close to the first coil (with the changing flux), alternating voltage is caused to flow in the second coil by an effect known as "mutual induction." Mutual inductance (inductance) is measured in units of the Henry. The changing magnetic flux in a coil affects itself as well as other coils. This is called self induction, the degree of this self induction is called Self Inductance. Self inductance is a measure of a coil's ability to establish an induced voltage as a result of a change in its current. Self inductance is commonly referred to as simply "inductance," and is symbolized by "L". The unit of inductance is the Henry (H).

Inductance value is designated in units called the Henry(H). The more wire the coil contains, the stronger its characteristics become. The inductance value can become quite large. If a coil is wound around an iron rod, or ferrite core (strengthened with iron powder), the inductance of the coil will be greatly increased. Coils used in typical electric circuits varely widely in values, ranging from a few micro-henry (µH) to many henry (H).

Relays
The relay takes advantage of the fact that when electricity flows through a coil, it becomes an electromagnet.
The electromagnetic coil attracts a steel plate, which is attached to a switch. So the switch's motion (ON and OFF) is controled by the current flowing to the coil, or not, respectively.

A very useful feature of a relay is that it can be used to electrically isolate different parts of a circuit.
It will allow a low voltage circuit (e.g. 5VDC) to switch the power in a high voltage circuit (e.g. 100 VAC or more).

The relay operates mechanically, so it can not operate at high speed.
There are many kind of relays. You can select one according to your needs.
The various things to consider when selecting a relay are its size, voltage and current capacity of the contact points, drive voltage, impedance, number of contacts, resistance of the contacts, etc.
The resistance voltage of the contacts is the maximum voltage that can be conducted at the point of contact in the switch. When the maximum is exceeded, the contacts will spark and melt, sometimes fusing together. The relay will fail. The value is printed on the relay.

Wednesday 28 July 2010

Design with microcontrollers: The Attiny2313

Figure 1. Parallel target board










Below (Figure 2) is a sample serial target board for programming the 8 bit 20 pin attiny2313, a derivative of the AVR microcontroller family.


Figure 2. Serial target board


What you see in Figure 1 is a sample parallel target board. I built these two and another one (shall post it soon) during my university days while i was experimenting with the 8 bit 20 pin attiny2313. I preferred the connection in figure one because it was easy to use with isp_prog 2007 programming software to read/write/erase data from either the flash memory or eeprom memory of the chip. i learnt it was easier to write the flash memory than it was to write the eeprom memory. All one needed to do is to write their codes in C (a hardware friendly programming language) or whichever language they preferred, compile it to generate the hex codes using avr studio or any other preferred compiler, then it is this hex codes that one needed to write to the chip.
The third target board was also easy to use and more interesting to me since i would address the chip directly through the command prompt. I used avrdude, a command line program and so i had to type in all commands. An instruction like avrdude -c dapa -P lpt1 -p attiny2313 -U (flash/eeprom):(r/w):(name of hex file).(hex/eep) would be reflected in the form of status bars in the command window.

Monday 19 July 2010

Using avrdude

You have to install avrdude first before being able to enjoy using it. Winavr usually comes packaged with avrdude. Then under windows ,open the command window and type in avrdude, you should get the following list of what avrdude can do.
















To get a list of supported programmers e.g. dasa, dapa, stk500 e.t.c., type in avrdude -c asdf
To get a list of parts supported by avrdude, type in avrdude -c avrisp. Thats the list of chips that avrdude knows about. Almost all of them are ISP programmable.

-P <port> tells avrdude where to look for your programmer
-U <memtype>:r/w/v:<filename>[:format]: tells avrdude how to put data on the chip
<memtype> can be flash, eeprom, hfuse(high fuse), lfuse (lowfuse), efuse (extended fuse).
r/w/v can be read, write or verify
<filename> the input (writing or verifying) or output file (reading)
[:format] optional, the format of the file. You can leave this off for writing, but for reading use i for Intel Hex (the prevailing standard)

e.g to read the low fuse into a file use the command -U lfuse:r:lfusefile.hex:i
to write a file called bobo.hex to the flash use the command -U flash:w:bobo.hex
to verify a file called mystuff.eep from the eeprom use the command
-U eeprom:v:mystuff.eep

Example:
In the command window type in avrdude -c usbtiny -p attiny2313 -U flash:w:test_leds.hex
avrdude should go through the following steps:
1. initializing the programmer (you won't see this if it works)
2. initializing the AVR device and making sure it is ready for instructions
3. reading the device signature (0x1e910a) which confirms that the chip you specified in the command line (attiny2313) is in fact the chip the programmer is connected to
4. erasing the chip
5. reading the file and verifying it is a valid file
6. writing the flash
7. verifying the flash

















Burning fuses
Fuse is a separate chunk of flash that is not written to when you update the firmware. They define things like clock speed, crystal type, whether JTAG is enabled, what the brownout (minimum voltage) level is, e.t.c. Setting the fuses incorrectly may 'brick' the chip e.g. you may disable future programming or make it so the chip is expecting an external crystal when there isn't one.
To program the fuses use:
-U lfuse:w:<0xhh>:m
-U hfuse:w:<0xhh>:m
-U efuse:w:<0xhh>:m
where <0xhh> is the desired fuse value in hex. But first you will want to calculate the fuse values using the very convenient AVR fuse calculator.
Triple check the fuse values, check again to make sure you aren't disabling ISP programming or the reset pin or setting the clock speed to 32kHz, then verify again that you have the correct chip for calculation. Finally you can try writing them to the chip.
If the programmer is not connected properly to the chip you will get the following message:










This simply means that the programmer could not 'talk' to the chip. 99% of the time it is a problem with wiring. Check that the chip is powered, plugged properly to the programmer, the programming cables are plugged in properly e.t.c. If you are using a 'simple' programmer such as a serial or parallel port bitbang programmer it could mean the programmer is at fault.

For most microcontrollers, the .hex files are not cross-compatible. This causes a signature failure. Once the signature is different from the expected one it stops. For example try to run this command avrdude -c usbtiny -p atmega8 -U flash:w:test_leds.hex









It stops at step 2. This is because code that is compiled for an attiny2313 wont run on an atmega8.