Beruflich Dokumente
Kultur Dokumente
ACKNOWLEDGEMENT
At the outset, I would like to thank Indian Institute of Technology, Guwahati and Robosapiens India for giving me an opportunity to successfully complete my training through their Summer Internship Program. I am grateful to Coordinator, Mr. Pradeep Sharma for allowing me to pursue my Training. I would also like to express my heartfelt gratitude towards Mr. Shailabh Suman and Mr. Sunil Kumar for their technical suggestions, constant inspiration, guidance and criticism during the course of my training. I will be failing in my duty if I dont thank Mr. Aman Sethi for his support and guidance.
TABLE OF CONTENTS
1. Basic Electronics 1.1 Introduction to Transistors 1.1.1 Construction 1.1.2 Connecting a BJT with External Circuit 1.1.3 NPN Transistor 1.1.4 PNP Transistor 1.1.5 Connecting BJTs to make Logic Gates 1.2 Operational Amplifiers 1.2.1 Non-Inverting Amplifier 1.2.2 Inverting Amplifier 1.2.3 Buffer 1.2.4 Differential Amplifier 1.2.5 Instrumentation Amplifier 1.3 555 Timer IC 1.3.1 Astable 1.3.2 Monostable 1.3.3 Bistable 1.4 H-Bridge 1.5 Actuators 1.5.1 DC Motor 1.5.2 Stepper Motor 1.5.3 Servo Motor 1.6 Digital to Analog Converter 1.7 Analog to Digital Converter 2. ATmega16 2.1 Features 2.2 Pin Descriptions 2.3 System Clock and Clock Options 2.4 I/O Ports 2.5 External Interrupts 2.6 8-Bit Timer/Counter0 2.7 16-Bit Timer/Counter1 2.7 8-Bit Timer/Counter2 2.8 Analog to Digital Converter 2.9 Some Codes with ATmega16
3. Image Processing 3.1Some Common Formats 3.2Sampling 3.3Quantization 3.4Functions in MATLAB for Image Processing 3.5Some Codes for Image Processing in MATLAB 4. Parallel Port
Construction
The principle of operation of the two transistor types, NPN and PNP, is exactly the same. The only difference being in the biasing (base current) and the polarity of the power supply for each type.
The construction and circuit symbols for both the NPN and PNP bipolar transistor are shown above with the arrow in the circuit symbol always showing the direction of conventional current flow between the base and emitter terminals.
This type of amplifier configuration is a non-inverting voltage amplifier circuit, in that the signal voltages Vin and Vout are In-Phase. This type of arrangement is not very common due to its unusually high voltage gain characteristics. Its Output characteristics represent that of a forward biased diode while the Input characteristics represent that of an illuminated photo-diode. Also this type of configuration has a high ratio of Output to Input resistance or more importantly "Load" resistance (RL) to "Input" resistance (Rin) giving it a value of "Resistance Gain". Then the Voltage Gain for a common base can therefore be given as: Common Base Voltage Gain
The Common Base circuit is generally only used in single stage amplifier circuits such as microphone pre-amplifier or RF radio amplifiers due to its very good high frequency response. The Common Emitter Configuration In the Common Emitter or Grounded Emitter configuration, the input signal is applied between the base, while the output is taken from between the collector and the emitter as shown. This type of configuration is the most commonly used circuit for transistor based amplifiers and which represents the "normal" method of connection. The common emitter amplifier configuration produces the highest voltage, current and power gain of all the three bipolar transistor configurations. This is mainly because the input impedance is LOW as it is connected to a forward-biased junction, while the output impedance is HIGH as it is taken from a reverse-biased junction.
In this type of configuration, the current flowing out of the transistor must be equal to the currents flowing into the transistor as the emitter current is given as Ie = Ic + Ib. Also, as the load resistance (RL) is connected in series with the collector, the Current gain of the Common Emitter Transistor Amplifier is quite large as it is the ratio of Ic/Ib and is given the symbol of Beta, (). Since the relationship between these three currents is determined by the transistor itself, any small change in the base current will result in a large change in the collector current. Then, small changes in base current will thus control the current in the Emitter/Collector circuit. By combining the expressions for both Alpha, and Beta, the mathematical relationship between these parameters and therefore the current gain of the amplifier can be given as:
Where: "Ic" is the current flowing into the collector terminal, "Ib" is the current flowing into the base terminal and "Ie" is the current flowing out of the emitter terminal.
Then to summarize, this type of bipolar transistor configuration has a greater input impedance, Current gain and Power gain than that of the common base configuration but its Voltage gain is much lower. The common emitter is an inverting amplifier circuit resulting in the output signal being 180o out of phase with the input voltage signal. The Common Collector Configuration In the Common Collector or Grounded Collector configuration, the collector is now common and the input signal is connected to the base, while the output is taken from the emitter load as shown. This type of configuration is commonly known as a Voltage Follower or Emitter Follower circuit. The emitter follower configuration is very useful for impedance matching applications because of the very high input impedance, in the region of hundreds of thousands of Ohms, and it has relatively low output impedance. The Common Collector Amplifier Circuit
The common emitter configuration has a current gain equal to the value of the transistor itself. In the common collector configuration the load resistance is situated in series with the emitter so its current is equal to that of the emitter current. As the emitter current is the combination of the collector AND base currents combined, the load resistance in this type of amplifier configuration also has both the collector current and the input current of the base flowing through it. Then the current gain of the circuit is given as:
This type of bipolar transistor configuration is a non-inverting amplifier circuit in that the signal voltages of Vin and Vout are "In-Phase". It has a voltage gain that is always less than "1" (unity). The load resistance of the common collector amplifier configuration receives both the base and collector currents giving a large current gain (as with the Common Emitter configuration) therefore, providing good current amplification with very little voltage gain.
NPN Transistors
We know that the transistor is a "CURRENT" operated device and that a large current (Ic) flows freely through the device between the collector and the emitter terminals. However, this only happens when a small biasing current (Ib) is flowing into the base
terminal of the transistor thus allowing the base to act as a sort of current control input. The ratio of these two currents (Ic/Ib) is called the DC Current Gain of the device and is given the symbol of hfe or nowadays Beta, (). Beta has no units as it is a ratio. Also, the current gain from the emitter to the collector terminal, Ic/Ie, is called Alpha, (), and is a function of the transistor itself. As the emitter current Ie is the product of a very small base current to a very large collector current the value of this parameter is very close to unity, and for a typical low-power signal transistor this value ranges from about 0.950 to 0.999. and Relationships
By combining the two parameters and we can produce two mathematical expressions that gives the relationship between the different currents flowing in the transistor.
The values of Beta vary from about 20 for high current power transistors to well over 1000 for high frequency low power type bipolar transistors. The equation for Beta can also be re-arranged to make Ic as the subject, and with zero base current (Ib = 0) the resultant collector current Ic will also be zero, ( x 0). Also when the base current is high
the corresponding collector current will also be high resulting in the base current controlling the collector current. One of the most important properties of the Bipolar Junction Transistor is that a small base current can control a much larger collector current.
PNP Transistors
PNP Transistors are the exact opposite to the NPN Transistors device we looked at previously. Basically, in this type of transistor construction the two diodes are reversed with respect to the NPN type, with the arrow, which also defines the Emitter terminal this time pointing inwards in the transistor symbol. Also, all the polarities are reversed which means that PNP Transistors "sink" current as opposed to the NPN transistor which "sources" current. Then, PNP Transistors use a small output base current and a negative base voltage to control a much larger emitter-collector current. The construction of a PNP transistor consists of two P-type semiconductor materials either side of the N-type material as shown below. PNP Transistor Configuration
PNP Transistors have very similar characteristics to their NPN bipolar cousins, except that the polarities (or biasing) of the current and voltage directions are reversed for any one of the possible three configurations looked at in the first tutorial, Common Base, Common Emitter and Common Collector. Generally, PNP Transistors require a negative
(-ve) voltage at their Collector terminal with the flow of current through the emittercollector terminals being Holes as opposed to Electrons for the NPN types. Because the movement of holes across the depletion layer tends to be slower than for electrons, PNP transistors are generally more slower than their equivalent NPN counterparts when operating. To cause the Base current to flow in a PNP transistor the Base needs to be more negative than the Emitter (current must leave the base) by approx 0.7 volts for a silicon device or 0.3 volts for a germanium device with the formulas used to calculate the Base resistor, Base current or Collector current are the same as those used for an equivalent NPN transistor and is given as.
OR gate - This is simpler, you connect them in a way that when either input is high the output will be high.
NOT gate - This is the simplest one to build, as mentioned in the introduction, you only need one transistor for this one.
OPERATIONAL AMPLIFIERS
We have built voltage and current amplifiers using transistors. Circuits of this kind with nice properties (high gain and high input impedance, for example), packaged as integrated circuits (ICs), are called operational amplifiers or op amps. They are called ``operational'' amplifiers, because they can be used to perform arithmetic operations (addition, subtraction, multiplication) with signals. In fact, op amps can also be used to integrate (calculate the areas under) and differentiate (calculate the slopes of) signals.
resistances Rin and Rout is shown above. A circuit model of an operational amplifier is shown in figure above. The output voltage of the op amp is linearly proportional to the voltage difference between the input terminals v+-v- by a factor of the gain . However, the output voltage is limited to the range Vcc < v <Vcc, where Vcc is the supply voltage specified by the designer of the op amp. The range Vcc< v <Vcc is often called the linear region of the amplifier, and when the output swings to Vcc or -Vcc, the op amp is said to be saturated. An ideal op amp has infinite gain ( ), infinite input resistance ( ), and
zero output resistance (Rout=0). You should use these two assumptions to analyze the op amp circuits covered in the assignments below. A consequence of the assumption of
infinite gain is that, if the output voltage is within the finite linear region, we must have v+=v-. A real op amp has a gain on the range 103-105 (depending on the type), and hence actually maintains a very small difference in input terminal voltages when operating in its linear region. For most applications, we can get away with assuming .
+Vcc
Non-Inverting Amplifier
Circuit
Voltage Gain Like the inverting amplifier, the op-amp device simplifies the design of an amplifier stage. How? The gain of the stage depends on external resistors, not the internal gain of the op amp itself. The output voltage is determined by the input voltage and the ratio of the feedback resistors plus one.
Inverting Amplifier
Circuit
Voltage Gain How does an op-amp device simplify the design of an amplifier? The voltage gain for the inverting configuration is set by the ratio of the feedback resistors R1 and R2, not the internal gain of the op-amp itself.
Buffer
The buffer has an output that exactly mirrors the input (assuming it's within range of the voltage rails), so it looks kind of useless at first. However, the buffer is an extremely useful circuit, since it helps to solve many impedance issues. The input impedance of the op-amp buffer is very high: close to infinity. And the output impedance is very low: just a few ohms.
This means we can use buffers to help chain together sub-circuits in stages without worrying about impedance problems. The buffer gives benefits similar to those of the emitter follower we looked at with transistors, but tends to work more ideally.
Differential Amplifier
Circuit
The differential amplifier has a unique feature that many circuits dont have - two inputs. This circuit amplifies the difference between its input terminals. Other circuits with one input actually have another input the ground potential. But, in cases where a signal source (like a sensor) has both of its terminals biased at several volts above ground, you need to amplify the difference between the terminals. What about noise that adds an unwanted voltage equally to both terminals of a sensor? The differential amp rejects the noise and rescues the signal. Voltage Gain If you keep the following resistor ratios equal, R2/R1 = R4/R3, the voltage gain looks like
What about signals common (or equal) at both inputs Vin+ and Vin-? The equation above tells you the output Vo should be zero! This Common Mode Rejection (CMR) is useful but not perfect! It depends on the op amp device itself and matching of the resistor values.
Instrumentation Amplifier
An instrumentation (or instrumentational) amplifier is a type of differential amplifier that has been outfitted with input buffers, which eliminate the need for input impedance matching and thus make the amplifier particularly suitable for use in measurement and test equipment.
The most commonly used instrumentation amplifier circuit is shown in the figure. The gain of the circuit is
555 Timer IC
The 555 Timer IC is an integrated circuit (chip) implementing a variety of timer and multivibrator applications. original name was the SE555/NE555 and was called "The IC Time Machine".[1] The 555 gets its name from the three 5-kohm resistors used in typical early implementations.[2] It is still in wide use, thanks to its ease of use, low price and good stability. Depending on the manufacturer, it includes over 20 transistors, 2 diodes and 15 resistors on a silicon chip installed in an 8-pin mini dual-in-line package (DIP-8).
Monostable mode: in this mode, the 555 functions as a "one-shot". Applications include timers, missing pulse detection, bouncefree switches, touch switches, frequency divider, capacitance measurement, pulse-width modulation (PWM) etc
Astable - free running mode: the 555 can operate as an oscillator. Uses include LED and lamp flashers, pulse generation, logic clocks, tone generation, security alarms, pulse position modulation, etc.
Bistable mode or Schmitt trigger: the 555 can operate as a flip-flop, if the DIS pin is not connected and no capacitor is used. Uses include bouncefree latched switches, etc.
Nr. 1 2 3 4 5 6
Name GND TRIG OUT RESET CTRL THR Ground, low level (0V)
Purpose
A short pulse high-to-low on the trigger starts the timer During a timing interval, the output stays at +VCC A timing interval can be interrupted by applying a reset pulse to low (0V) Control voltage allows access to the internal voltage divider (2/3 VCC) The threshold at which the interval ends (it ends if U.thr 2/3 VCC) Connected to a capacitor whose discharge time will influence the timing interval The positive supply voltage which must be between 3 and 15 V
DIS
V+, VCC
555 Astable
An astable circuit produces a 'square wave', this is a digital waveform with sharp transitions between low (0V) and high (+Vs). Note that the durations of the low and high states may be different. The circuit is called an astable because it is not stable in any state: the output is continually changing between 'low' and 'high'. The time period (T) of the square wave is the time for one complete cycle, but it is usually better to consider frequency (f) which is the number of cycles per second.
T = time period in seconds (s) f = frequency in hertz (Hz) R1 = resistance in ohms ( ) R2 = resistance in ohms ( ) C1 = capacitance in farads (F)
The Mark
time time
period
can
be high):
split Tm
into =
two 0.7
parts: (R1
T +
Tm R2)
Ts C1
(output
Space time (output low): Ts = 0.7 R2 C1 Many circuits require Tm and Ts to be almost equal; this is achieved if R2 is much larger than R1. For a standard astable circuit Tm cannot be less than Ts, but this is not too restricting because the output can both sink and source current. Astable operation
With the output high (+Vs) the capacitor C1 is charged by current flowing through R1 and R2. The threshold and trigger inputs monitor the capacitor voltage and when it reaches 2/3Vs (threshold voltage) the output becomes low and the discharge pin is connected to 0V. The capacitor now discharges with current flowing through R2 into the discharge pin. When the voltage falls to 1/3Vs (trigger voltage) the output becomes high again and the discharge pin is disconnected, allowing the capacitor to start charging again. This cycle repeats continuously unless the reset input is connected to 0V which forces the output low while reset is 0V. An astable can be used to provide the clock signal for circuits such as counters. A low frequency astable (< 10Hz) can be used to flash an LED on and off, higher frequency flashes are too fast to be seen clearly. Driving a loudspeaker or piezo
transducer with a low frequency of less than 20Hz will produce a series of 'clicks' (one for each low/high transition) and this can be used to make a simple metronome. An audio frequency astable (20Hz to 20kHz) can be used to produce a sound from a loudspeaker or piezo transducer. The sound is suitable for buzzes and beeps. The natural (resonant) frequency of most piezo transducers is about 3kHz and this will make them produce Duty cycle The duty cycle of an astable circuit is the proportion of the complete cycle for which the output is high (the mark time). It is usually given as a percentage. For a standard 555/556 astable circuit the mark time (Tm) must be greater than the space time (Ts), so the duty cycle must be at least 50%: a particularly loud sound.
Duty cycle =
Tm R1 + R2 = Tm + Ts R1 + 2R2
To achieve a duty cycle of less than 50% a diode can be added in parallel with R2 as shown in the diagram. This bypasses R2 during the charging (mark) part of the cycle so that Tm depends only on R1 and C1: Tm = 0.7 R1 C1 diode) Ts = 0.7 R2 C1 (unchanged) (ignoring 0.7V across
Choose C1 first (there are relatively few values available). Choose R1 to give the time period you need. R1 should be in the range 1k 1M , so use a fixed resistor of at least 1k in series if R1 is variable. to
Beware that electrolytic capacitor values are not accurate, errors of at least 20% are common. Beware that electrolytic capacitors leak charge which substantially increases the time period if you are using a high value resistor - use the formula as only a very rough guide! For example the Timer Project should have a maximum time period of 266s (about 4 minutes), but many electrolytic capacitors extend this to about 10 minutes!
Monostable operation
The timing period is triggered (started) when the trigger input (555 pin 2) is less than
1
/3 Vs, this makes the output high (+Vs) and the capacitor C1 starts to charge through
resistor R1. Once the time period has started further trigger pulses are ignored. The threshold input (555 pin 6) monitors the voltage across C1 and when this reaches
2
/3 Vs the time period is over and the output becomes low. At the same time discharge
(555 pin 7) is connected to 0V, discharging the capacitor ready for the next trigger. The reset input (555 pin 4) overrides all other inputs and the timing may be cancelled at any time by connecting reset to 0V, this instantly makes the output low and discharges the capacitor. If the reset function is not required the reset pin should be connected to +Vs.
Trigger Reset
(555 (555
pin pin
2) 4)
makes makes
the the
output output
high. low.
Reset is 'active low', it resets when < 0.7V. The power-on reset, power-on trigger and edge-triggering circuits can all be used as described above for the monostable.
H-Bridge
The term "H-bridge" is derived from the typical graphical representation of such a circuit. An H-bridge is built with four switches. When the switches S1 and S4 are closed (and S2 and S3 are open) a positive voltage will be applied across the motor. By opening S1 and S4 switches and closing S2 and S3 switches, this voltage is reversed, allowing reverse operation of the motor.
Operation
The H-Bridge arrangement is generally used to reverse the polarity of the motor, but can also be used to 'brake' the motor, where the motor comes to a sudden stop, as the motor's terminals are shorted, or to let the motor 'free run' to a stop, as the motor is effectively disconnected from the circuit. The following table summarizes operation.
S1 S2 S3 S4 1 0 0 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0
Result Motor moves right Motor moves left Motor free runs Motor brakes Motor brakes
Actuators
An actuator is a mechanical device for moving or controlling a mechanism or system. An actuator typically is a mechanical device that takes energy, usually created by air, electricity, or liquid, and converts that into some kind of motion.
DC Motor
A DC motor is an electric motor that runs on direct current (DC) electricity
How a DC motor works A DC motor works by converting electrical energy into mechanical work. This is accomplished by forcing current through a coil and producing a magnetic field that spins the motor. The simplest DC motor is a single coil apparatus, used here to discuss the DC motor theory. The voltage source forces current through the coil via sliding contacts or brushes that are connected to the DC source. These brushes are found on the end of the coil wires and make a temporary electrical connection with the voltage source. In this motor, the brushes will make a connection every 180 degrees and current will then flow through the coil wires. At 0 degrees, the brushes are in contact with the voltage source and current is flowing. The current that flows through wire segment C-D interacts with the magnetic field that is present and the result is an upward force on the segment. The current that flows through segment A-B has the same interaction, but the force is in the downward direction. Both forces are of equal magnitude, but in opposing directions since the direction of current flow in the segments is reversed with respect to the magnetic field. At 180 degrees, the same phenomenon occurs, but segment A-B is forced up and C-D is forced down. At 90 and 270-degrees, the brushes are not in contact with the voltage source and no force is produced. In these two positions, the rotational kinetic energy of the motor keeps it spinning until the brushes regain contact. One drawback to the motor is the large amount of torque ripple that it has. The reason for this excessive ripple is because of the fact that the coil has a maximum force pushing on it only at the 90 and 270 degree positions. The rest of the time the coil spins on its own and the torque drops to zero. The torque curve produced by this single coil, as more coils are added to the motor, the torque curve is smoothed out. The resulting torque curve never reaches the zero point and the average torque for the motor is greatly increased. As more and more coils are added, the torque curve
approaches a straight line and has very little torque ripple and the motor runs much more smoothly. Another method of increasing the torque and rotational speed of the motor is to increase the current supplied to the coils. This is accomplished by increasing the voltage that is sent to the motor, thus increasing the current at the same time.
Stepper Motor
A stepper motor (or step motor) is a brushless, synchronous electric motor that can divide a full rotation into a large number of steps. The motor's position can be controlled precisely, without any feedback mechanism (see Open-loop controller). Stepper motors are similar to switched reluctance motors (which are very large stepping motors with a reduced pole count, and generally are closed-loop commutated.). Stepper motors utilize a doubly-salient topology, which means they have "teeth" on both the rotor and stator. Torque is generated by alternately magnetizing the stator teeth electrically, and the permanent magnet rotor teeth try to line up with the stator teeth. There are many different configurations of stepper motors, and even more diverse ways to drive them. The most common stator configuration consists of two coils (A and B). These coils are arranged around the circumference of the stator in such a way that if they are driven with square waves which have a quadrature phase relationship between them, the motor will rotate. To make the motor rotate in the opposite direction, simply reverse the phase relationship between the A and B signals. A transition of either square wave causes the rotor to move by a small amount, or a "STEP". Thus, the name "stepper motor". The size of this step is dependent on the teeth arrangement of the motor, but a common value is 1.8 degrees, or 200 steps per revolution. Speed control is achieved by simply varying the frequency of the squarewaves. Because stepper motors can be driven with square waves, they are easily controlled by inexpensive digital circuitry and do not even require PWM. For this reason, stepper motors have often been inappropriately referred to as "digital motors". However, by utilizing power modulation techniques to change the quadrature squarewaves into sine and cosine waveforms, even MORE step resolution is possible. This is called "micro-
stepping", where each discrete change in the sine and cosine levels constitutes one microstep. Theoretically, there is no limit to the position resolution achievable with micro-stepping, but in reality, it is limited by the motor mechanical and electrical tolerances. Some stepper motors are designed specifically for micro-stepping, and consist of tightly matched impedances between the A and B coils, and tighter machining tolerances on the teeth, at the expense of higher cost.
Servo Motor
Servos are DC motors with built in gearing and feedback control loop circuitry. And no motor drivers required! Servos are extremely popular with robot, RC plane, and RC boat builders. Most servo motors can rotate about 90 to 180 degrees. Some rotate through a full 360 degrees or more. However, servos are unable to continually rotate, meaning they can't be used for driving wheels (unless modified), but their precision positioning makes them ideal for robot arms and legs, rack and pinion steering, and sensor scanners to name a few. Since servos are fully self contained, the velocity and angle control loops are very easy to impliment, while prices remain very affordable. To use a servo, simply connect
the black wire to ground, the red to a 4.8-6V source, and the yellow/white wire to a signal generator (such as from your microcontroller). Vary the square wave pulse width from 12ms and your servo is now position/velocity controlled.
DAC R-2R
The below diagram is an 8-bit digital-to-analog converter that utilizes a resister ladder network to divide current with equal current sources, and an operational amplifier to sum these currents and convert them into an output voltage.
DAC = digital-to-analog converter EOC = end of conversion SAR = successive approximation register S/H = sample and hold circuit Vin = input voltage Vref = reference voltage
32 Programmable I/O Lines 40-pin PDIP, 44-lead TQFP, and 44-pad MLF Operating Voltages 4.5 - 5.5V Speed Grades 0 - 16 MHz
Pin Descriptions
VCC Digital supply voltage. GND Ground. Port A (PA7..PA0) Port A serves as the analog inputs to the A/D Converter. Port A also serves as an 8-bit bi-directional I/O port. Port B (PB7..PB0) Port B is an 8-bit bi-directional I/O port. Port C (PC7..PC0) Port C is an 8-bit bi-directional I/O port. If the JTAG interface is enabled, the pull-up resistors on pins PC5(TDI), PC3(TMS) and PC2(TCK) will be activated even if a reset occurs. Port D (PD7..PD0) Port D is an 8-bit bi-directional I/O port. RESET Reset Input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running.
XTAL1 Input to the inverting Oscillator amplifier and input to the internal clock operating circuit. XTAL2 Output from the inverting Oscillator amplifier. AVCC AVCC is the supply voltage pin for Port A and the A/D Converter. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. AREF AREF is the analog reference pin for the A/D Converter.
System Clock and Clock Options Clock Systems and their Distribution
CPU Clock clkCPU The CPU clock is routed to parts of the system concerned with operation of the AVR core. Examples of such modules are the General Purpose Register File, the Status Register and the data memory holding the Stack Pointer. Halting the CPU clock inhibits the core from performing general operations and calculations. I/O Clock clkI/O The I/O clock is used by the majority of the I/O modules, like Timer/Counters, SPI, and USART. The I/O clock is also used by the External Interrupt module, but note that some external interrupts are detected by asynchronous logic, allowing such interrupts to be detected even if the I/O clock is halted. Also note that address recognition in the TWI module is carried out asynchronously when clkI/O is halted, enabling TWI address reception in all sleep modes. Flash Clock clkFLASH The Flash clock controls operation of the Flash interface. The Flash clock is usually active simultaneously with the CPU clock. Asynchronous Timer Clock
clkASY The Asynchronous Timer clock allows the Asynchronous Timer/Counter to be clocked directly from an external 32 kHz clock crystal. The dedicated clock domain allows using this Timer/Counter as a real-time counter even when the device is in sleep mode. ADC Clock clkADC The ADC is provided with a dedicated clock domain. This allows halting the CPU and I/O clocks in order to reduce noise generated by digital circuitry. This gives more accurate ADC conversion results.
I/O Ports
The following code example shows how to set port B pins 0 and 1 high, 2 and 3 low, and define the port pins from 4 to 7 as input with pull-ups assigned to port pins 6 and 7. C Code Example(1) unsigned char i; ... /* Define pull-ups and set outputs high */ /* Define directions for port pins */ PORTB = (1<<PB7)|(1<<PB6)|(1<<PB1)|(1<<PB0); DDRB = (1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0); /* Read port pins */ i = PINB;
The following code examples show how to access the 16-bit timer registers assuming that no interrupts updates the temporary register. The same principle can be used directly for accessing the OCR1A/B and ICR1 registers. C Code Example(1) unsigned int i; ... /* Set TCNT1 to 0x01FF */ TCNT1 = 0x1FF; /* Read TCNT1 into i */ i = TCNT1;
ISC11, ISC10: Interrupt Sense Control 1 Bit 1 and Bit 0 ISC01, ISC00: Interrupt Sense Control 0 Bit 1 and Bit 0
8-bit Timer/Counter0
Timer/Counter0 is a general purpose, single channel, 8-bit Timer/Counter module. The Timer/Counter (TCNT0) and Output Compare Register (OCR0) are 8-bit registers. Interrupt request (abbreviated to Int.Req. in the figure) signals are all visible in the Timer Interrupt Flag Register (TIFR). All interrupts are individually masked with the Timer Interrupt Mask register (TIMSK). Output Compare Unit The 8-bit comparator continuously compares TCNT0 with the Output Compare Register (OCR0). Whenever TCNT0 equals OCR0, the comparator signals a match. A match will set the Output Compare Flag (OCF0) at the next timer clock cycle. If enabled (OCIE0 = 1 and Global Interrupt Flag in SREG is set), the Output Compare Flag generates an output compare interrupt. The OCF0 flag is automatically cleared when the interrupt is executed. Alternatively, the OCF0 flag can be cleared by software by writing a logical one to its I/O bit location.
FOC0: Force Output Compare WGM01:0: Waveform Generation Mode COM01:0: Compare Match Output Mode CS02:0: Clock Select
OCIE0: Timer/Counter0 Output Compare Match Interrupt Enable TOIE0: Timer/Counter0 Overflow Interrupt Enable
16-bit Timer/Counter1
The 16-bit Timer/Counter unit allows accurate program execution timing (event management), wave generation, and signal timing measurement. The following code examples show how to access the 16-bit timer registers assuming that no interrupts updates the temporary register. C Code Example(1) unsigned int i; ... /* Set TCNT1 to 0x01FF */ TCNT1 = 0x1FF; /* Read TCNT1 into i */ i = TCNT1;
COM1A1:0: Compare Output Mode for Channel A COM1B1:0: Compare Output Mode for Channel B FOC1A: Force Output Compare for Channel A FOC1B: Force Output Compare for Channel B WGM11:0: Waveform Generation Mode
ICNC1: Input Capture Noise Canceler ICES1: Input Capture Edge Select WGM13:2: Waveform Generation Mode CS12:0: Clock Select
TICIE1: Timer/Counter1, Input Capture Interrupt Enable OCIE1A: Timer/Counter1, Output Compare A Match Interrupt Enable OCIE1B: Timer/Counter1, Output Compare B Match Interrupt Enable TOIE1: Timer/Counter1, Overflow Interrupt Enable
8-bit Timer/Counter2
Timer/Counter2 is a general purpose, single channel, 8-bit Timer/Counter module.
FOC2: Force Output Compare WGM21:0: Waveform Generation Mode COM21:0: Compare Match Output Mode CS22:0: Clock Select Timer/Counter Interrupt Mask Register TIMSK
OCIE2: Timer/Counter2 Output Compare Match Interrupt Enable TOIE2: Timer/Counter2 Overflow Interrupt Enable
REFS1:0: Reference Selection Bits ADLAR: ADC Left Adjust Result MUX4:0: Analog Channel and Gain Selection Bits ADC Control and Status Register A ADCSRA
ADEN: ADC Enable ADSC: ADC Start Conversion ADATE: ADC Auto Trigger Enable ADIF: ADC Interrupt Flag ADIE: ADC Interrupt Enable ADPS2:0: ADC Prescaler Select Bits
Some codes with ATmega16 Code for Line Follower using 2 Sensors and 2 DC motors
#define F_CPU 12000000UL //set your clock speed #include <avr/io.h> int move_forward= 0b10111000; int move_left= 0b00111000; int move_right= 0b10110000; int left_sensor_on= 0b10000000; int left_sensor_off= 0b00000000; int right_sensor_on= 0b00000001; int right_sensor_off= 0b00000000; int stop = 0b00110000; int main (void) { DDRD = 0xFF; //Output port connected to motors DDRA = 0x00; //Input port connected to sensors int left_sensor = 0; int right_sensor = 0; while(1) //create an infinite loop { PORTD |=(1<<4); //Right motor enable
PORTD |=(1<<5); //Left motor enable left_sensor = (PINA & 0b10000000); // define left sensor right_sensor = (PINA & 0b00000001); // define right sensor if(( left_sensor==left_sensor_off) & right_sensor==right_sensor_off)) { PORTD = stop; right_sensor = 0; left_sensor = 0; } if((left_sensor==left_sensor_on) & (right_sensor==right_sensor_on)) { PORTD = move_forward; //Robot move forward; left_sensor = 0; right_sensor = 0; } if(( left_sensor==left_sensor_on) & (right_sensor==right_sensor_off)) { PORTD = move_right; left_sensor = 0; right_sensor = 0; } if(( left_sensor==left_sensor_off) & (right_sensor==right_sensor_on)) { PORTD = move_left; left_sensor = 0; right_sensor = 0; } } }
int center_rotate_right= 0b10110100; int move_back=0b01110100; int left_sensor_on= 0b10000000; int left_sensor_off= 0b00000000; int right_sensor_on= 0b00000001; int right_sensor_off= 0b00000000; int stop = 0b00110000; int main(void) { DDRD=0xFF; //Output port connected to motors DDRA=0x00; //Input port connected to sensors int left_sensor=0; int right_sensor=0; while(1) { PORTD|=(1<<4); //Right motor enable PORTD|=(1<<5); //Left motor enable left_sensor=(PINA & 0b10000000); right_sensor=(PINA & 0b00000001); if(( left_sensor==left_sensor_off) & right_sensor==right_sensor_off)) { PORTD = stop; _delay_ms(255); PORTD=move_back; right_sensor = 0; left_sensor = 0; } if((left_sensor==left_sensor_off) & (right_sensor==right_sensor_on)) { PORTD = center_rotate_right; left_sensor = 0; right_sensor = 0; } if(( left_sensor==left_sensor_on) & (right_sensor==right_sensor_off)) { PORTD = center_rotate_left; left_sensor = 0; right_sensor = 0; }
} }
count++; if(count==4) { PORTC=~PORTC; count=0; } } int main() {DDRC=0xFF; DDRA=0xFF; PORTA=0x00; PORTC=0x00; TCNT0=0x00; TCCR0=0x05; TIMSK=0x01; sei(); while(1) { } } Compare Mode #define F_CPU 12000000UL #include<avr/io.h> #include<avr/interrupt.h> #include<compat/deprecated.h> #include<util/delay.h> ISR(TIMER0_COMP_vect) { count++; if(count==4) { PORTC=~PORTC; count=0; } } int main() {DDRC=0xFF; DDRA=0xFF; PORTA=0x00; PORTC=0x00;
} } void main() { DDRA=0x00; PORTA=0x01; ADMUX=ob00000001 ADCSRA=0b11001111; int adc=call_ADC(); if(adc>0x000&&adc<0x3E8) { PORTC=0xFF; } for(;;) { } } //read analog frm channel 0 // prescaler=128 and ADIE is set
IMAGE PROCESSING
Acquisition of Image
Image Processor
Image Analysis
Machine vision
Image processing involves changing the nature of an image in order to either 1. improve its pictorial information for human interpretation, 2. render it more suitable for autonomous machine perception. 3. Enhancing the edges of an image.
Sampling
Sampling refers to the process of digitizing a continuous function. Nyquist criterion can be stated as the sampling theorem, which says, in effect, that a continuous function can be reconstructed from its samples provided that the sampling frequency is at least twice the maximum frequency in the function. Fs > 2Fmax
Quantization
Quantization refers to the number of available gray values. Again, the more values, the better the image will appear; the fewer values will result in a less natural looking image. Allied to quantization is thresholding, where an image is turned into black and white by the application of a simple rule.
values in J, where gamma specifies the shape of the curve describing the relationship between the values in I and J. If gamma is less than 1, the mapping is weighted toward higher (brighter) output values. If gamma is greater than 1, the mapping is weighted toward lower (darker) output values. If you omit the argument, gamma defaults to 1 (linear mapping). 9. img(i,j)- This is used to access the (i,j)th pixel of image img. 10. filter2()-Two-dimensional digital filtering = filter2(h,X,shape) returns the part of Y specified by the shape parameter. shape is a string with one of these values: 'full' Returns the full two-dimensional correlation. In this case, Y is larger than X. 'same'(default) Returns the central part of the correlation. In this case, Y is the same size as X. 'valid' Returns only those parts of the correlation that are computed without zero-padded edges. In this case, Y is smaller than X. 11. medfilt2()- Perform two-dimensional median filtering. B = medfilt2(A) performs median filtering of the matrix A using the default 3-by-3 neighborhood. 12. imerode()- Erode image. IM2 = imerode(IM,SE) erodes the grayscale, binary, or packed binary image IM, returning the eroded image IM2. The argument SE is a structuring element object or array of structuring element objects returned by the strel function. 13. imdilate()- Dilate image. IM2 = imdilate(IM,SE) dilates the grayscale, binary, or packed binary image IM, returning the dilated image, IM2. The argument SE is a structuring element object, or array of structuring element objects, returned by the strel function. 14. strel()- Create morphological structuring element. E = strel(shape,parameters) creates a structuring element, SE, of the type specified by shape. Shapes can be: diamond, disk, line, octagon, etc. 15. imopen()- Open an image. IM2 = imopen(IM,SE) performs morphological opening on the grayscale or binary image IM with the structuring element SE. The argument SE must be a single structuring element object, as opposed to an array of objects. 16. imclose()- Close an image. IM2 = imclose(IM,SE) performs morphological closing on the grayscale or binary image IM, returning the closed image, IM2.
17. imsubtract()- Subtract one image from another, or subtract a constant from an image. Z = imsubtract(X,Y) subtracts each element in array Y from the corresponding element in array X and returns the difference in the corresponding element of the output array Z. 18. edge()- Find edges in an intensity image. BW = edge(I,'sobel) takes an intensity image I as its input, and returns a binary image BW of the same size as I, with 1's where the function finds edges in I and 0's elsewhere. 19. bwlabel()- Label connected components in a binary image. L = bwlabel(BW,n) returns a matrix L, of the same size as BW, containing labels for the connected objects in BW. n can have a value of either 4 or 8, where 4 specifies 4-connected objects and 8 specifies 8-connected objects; if the argument is omitted, it defaults to 8. 20. guide()- Start the GUI Layout Editor. guide('filename.fig') opens the FIG-file named filename.fig. You can specify the path to a file not on your MATLAB path.
Some codes for Image Processing in MATLAB Code for finding the compression ratio
K=imfinfo('F:\ROBOSAPIENS\Image database\saturn.png'); Imgbytes=K.Height*K.Width*K.BitDepth/8; Compbytes=K.FileSize; Ratio=Imgbytes/Compbytes;
PARALLEL PORT
A parallel port has 8 Output pins [D0 to D7] 5 Status pins [S4 to S7 and S3] 4 Control pins [C0 to C3] 8 ground pins [18 to 25]
--------------------------------X------------------------------------X-----------------------------------