Académique Documents
Professionnel Documents
Culture Documents
Sensors
H-Bridge Motor Driver
AVR Microcotroller
Atmega 16
Features
Pin configuration
Interrupt
Timer clock
ADC
Codes
Image Processing
Related terms
Aspects of image processing
Types of images
Morphology
ELECTRONIC COMPONENT
An electronic component is a basic electronic element usually packaged in a discrete form with two or
more connecting leads or metallic pads. Components are intended to be connected together, usually by
soldering to a printed circuit board, to create an electronic circuit with a particular function (for example an
amplifier, radio receiver, or oscillator). Components may be packaged singly (resistor, capacitor, transistor,
diode etc.) or in more or less complex groups as integrated circuits (operational amplifier, resistor array,
logic gate etc.)
Components may be Passive or Active:
Passive components are those that do not have gain or directionality. [1] In the Electrical industry
they are called Electrical elements or electrical components
Active components are those that have gain or directionality, in contrast to passive components,
which have neither. They include semiconductor devices and vacuum tubes (valves).
RESISTOR
A resistor is a two-terminal electronic component that produces a voltage across its terminals that is
proportional to the electric current through it in accordance with
Ohm's law:
V = IR
CAPACITOR
A capacitor is a passive electronic component that stores energy in the
form of an electrostatic field. In its simplest form, a capacitor consists
of twoconducting plates separated by an insulating material called
thedielectric. The capacitance is directly proportional to the surface
areas of the plates, andi s inversely proportional to the separation
between the plates. Capacitance also depends on the dielectric
constant of the substance separating the plates.
C=
A/D
DIODE
a Diode is a two-terminal device have two active electrodes between which thesignal of interest may flow,
and most are used for their unidirectional electric current property.The unidirectionality most diodes
exhibit is sometimes generically called the rectifying property. The most common function of a diode is to
allow an electric current in one direction (called the forward biased condition) and to block the current in the
opposite direction (the reverse biased condition). Thus, the diode can be thought of as an electronic version
of a check valve.The mostcommon diodes are made from semiconductor materials such as silicon or
germanium.
TRANSISTOR
A Transistor is a semiconductor device commonly used to amplify or switch electronic signals. A transistor
is made of a solid piece of a semiconductor material, with at least three terminals for connection to an
external circuit. A voltage or current applied to one pair of the transistor's terminals changes the current
flowing through another pair of terminals. Because the controlled (output) power can be much larger than
the controlling (input) power, the transistor provides amplification of a signal.
The transistor is the fundamental building block of modern electronic devices, and is used in radio,
telephone, computer and other electronic systems.Some transistors are packaged individually but most are
found in integrated circuits.
Types of transistor
There are two types of standard transistors, NPN and PNP, with different
circuit symbols. The letters refer to the layers of semiconductor material used
to make the transistor. Most transistors used today are NPN because this is
Transistor circuit symbols
the easiest type to make from silicon. If you are new to electronics it is best to start by learning how to use
NPN transistors.
The leads are labelled base (B), collector (C) and emitter (E).
These terms refer to the internal operation of a transistor but they are not much help in understanding how
a transistor is used, so just treat them as labels!
Darlington pair is 2 transistors
connected together to give a very high current gain
Transistor as a switch
Transistors are commonly used as electronic switches, for both
high power applications including switched-mode power supplies
and low power applications such as logic gates.It can be seen from the
graph that once the base voltage reaches a certain level, shown at point
B, the current will no longer increase with increasing V BE and the output
will be held at a fixed voltage.The transistor is then said to be saturated.
Hence, values of input voltage can be chosen such that the output is
either completely off,[9] or completely on. The transistor is acting as a
switch, and this type of operation is common in digital circuits where only "on" and "off" values are
relevant.
OPERATIONAL AMPLIFIER
An operational amplifier, which is often called an op-amp, is a DC-coupled high-gain electronic voltage
amplifier with differential inputs and, usually, a single output.[1] Typically the output of the op-amp is
controlled either by negative feedback, which largely determines the magnitude of its output voltage gain,
or by positive feedback, which facilitates regenerative gain and oscillation. High input impedance at the
input terminals (ideally infinite) and low output impedance (ideally zero) are important typical
characteristics.
555 TIMER
DESCRIPTION
The 555 monolithic timing circuit is a highly stable
controller capable of producing accurate time delays, or
oscillation. In the time delay mode of operation, the time
is precisely controlled by one external resistor and
capacitor. For a stable operation as an oscillator, the free
running frequency and the duty cycle are both accurately
controlled with two external resistors and one capacitor.
The circuit may be triggered and reset on falling
waveforms, and the output structure can source or sink
up to 200 mA.
The 555 has three operating modes:
Monostable mode: in this mode, the 555 functions as a "oneshot". Applications include timers, missing pulse detection, 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, 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.
FEATURES
Turn-off time less than 2 ms
Max. operating frequency greater than 500 kHz
Timing from microseconds to hours
High output current
Adjustable duty cycle
TTL compatible
Temperature stability of
0.005% per C
APPLICATIONS
Precision timing
Pulse generation
Sequential timing
Time delay generation
Pulse width modulation
ACTUATOR
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. That motion can be anything from blocking to clamping to
ejecting. Actuators are typically used in manufacturing or industrial applications and may be used in
things like motors, pumps,switches,andvalves.
Actuators can create a linear motion, rotary motion, or oscillatory motion. That is, they can create motion in
one direction, in a circular motion, or in opposite directions at regular intervals.
SENSOR
Sensors are electrical or mechanical components that are used to measure a property or behavior of an
object or system. Sensors are used by scientists and engineers during research and testing activities, but
they can also be found in many household objects, such as temperature sensors in an oven to
accelerometers in an automobile airbag system. Sensors are generally categorized by the type of
phenomenon that they measure, rather than the functionality of the sensor itself.
Mechanical Sensors
Mechanical sensors measure a property through mechanical means, although the measurement itself may
be collected electronically.Types of mechanical sensors include:
Pressure sensors
Accelerometers
Potentiometers
Humidity sensors
Electrical
Electrical sensors measure electric and magnetic properties. An example of an electrical sensor is an
ohmmeter, which is used to measure electrical resistance between two points in a circuit.. ther electrical
sensors include:
Voltmeter/Ammeter
RADAR
Magnetometer
Thermal
Although all thermal sensors measure changes in temperature, there are a variety of types of thermal
sensors, each with specific uses, temperature ranges, and accuracies. Some types of thermal sensors
include:
Thermometers
Thermocouples
Thermistors
Chemical
Chemical sensors generally detect the concentration of a substance in the air or in a liquid. Types of
chemical sensors include:
Oxygen sensors
Redox electrodes
Optical
Optical sensors detect the presence of light waves. This could include light in the visible spectrum, or
outside the visible spectrum, in the case of infrared sensors. Some types of optical sensors include:
Photodetectors
Infrared sensors
Fiberoptic sensors
Interferometers
H-BRIDGE
An H-bridge is an electronic circuit which enables a voltage to be applied across a load in either direction.
These circuits are often used in robotics and other applications to allow DC motors to run forwards and
backwards. H-bridges are available as integrated circuits, or can be built from discrete components.
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
summarises operation.
S1 S2 S3 S4
Result
1 0
0 1
0 0
0 1
Motor brakes
1 0
Motor brakes
AVR MICROCONTROLLER
The AVR is a Modified Harvard architecture 8-bit RISC single chip microcontroller (C) which was
developed by Atmel in 1996. The AVR was one of the first microcontroller families to use on-chip flash
memory for program storage, as opposed to One-Time Programmable ROM, EPROM, or EEPROM used by
other microcontrollers at the time.
ATMEGA 16
FEATURES
High-performance, Low-power AVR 8-bit Microcontroller
Advanced RISC Architecture
131 Powerful Instructions Most Single-clock Cycle Execution
32 x 8 General Purpose Working Registers
Fully Static Operation
On-chip 2-cycle Multiplier
Nonvolatile Program and Data Memories
16K Bytes of In-System Self-Programmable Flash
In-System Programming by On-chip Boot Program
T rue Read-While-Write Operation
512 Bytes EEPROM
1K Byte Internal SRAM
Programming Lock for Software Security
JTAG (IEEE std. 1149.1 Compliant) Interface
Boundary-scan Capabilities According to the JTAG Standard
Extensive On-chip Debug Support
Programming of Flash, EEPROM, Fuses, and Lock Bits through the JTAG Interface
Peripheral Features
Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
Mode
Real Time Counter with Separate Oscillator
Four PWM Channels
8-channel, 10-bit ADC
8 Single-ended Channels
2 Differential Channels with Programmable Gain at 1x, 10x, or 200x
Byte-oriented Two-wire Serial Interface
Programmable Serial USART
Master/Slave SPI Serial Interface
Programmable Watchdog Timer with Separate On-chip Oscillator
On-chip Analog Comparator
Special Microcontroller Features
Internal Calibrated RC Oscillator
External and Internal Interrupt Sources
Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby
and Extended Standby
10
Pin Descriptions
VCC
GND
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, if the A/D Converter is not used.
Alternate Functions of Port A
Port Pin
Alternate Function
PA7
ADC7 (ADC input channel 7)
PA6
ADC6 (ADC input channel 6)
11
PA5
PA4
PA3
PA2
PA1
PA0
Port B (PB7..PB0)
Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each
bit). The Port B output buffers have symmetrical drive characteristics with both high sink
and source capability.
Alternate Functions of Port B
Port Pin
Alternate Functions
PB7
SCK (SPI Bus Serial Clock)
PB6
MISO (SPI Bus Master Input/Slave Output)
PB5
MOSI (SPI Bus Master Output/Slave Input)
PB4
SS (SPI Slave Select Input)
PB3
AIN1 (Analog Comparator Negative Input)
OC0 (Timer/Counter0 Output Compare Match Output)
PB2
AIN0 (Analog Comparator Positive Input)
INT2 (External Interrupt 2 Input)
PB1
T1 (Timer/Counter1 External Counter Input)
PB0
T0 (Timer/Counter0 External Counter Input)
XCK (USART External Clock Input/Output)
Port C (PC7..PC0)
Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each
bit). 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.
Alternate Functions of Port C
Port Pin
Alternate Function
PC7
TOSC2 (Timer Oscillator Pin 2)
PC6
TOSC1 (Timer Oscillator Pin 1)
PC5
TDI (JTAG Test Data In)
PC4
TDO (JTAG Test Data Out)
PC3
TMS (JTAG Test Mode Select)
PC2
TCK (JTAG Test Clock)
PC1
SDA (Two-wire Serial Bus Data Input/Output Line)
PC0
SCL (Two-wire Serial Bus Clock Line)
Port D (PD7..PD0)
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each
bit). The Port D output buffers have symmetrical drive characteristics with both high sink
and source capability.
Alternate Functions of PORT D
Port Pin
Alternate Function
12
PD7
PD6
PD5
PD4
PD3
PD2
PD1
PD0
RESET
A low level on this pin for longer than the minimum pulse length will generate
a reset, even if the clock is not running. Shorter pulses are not guaranteed to generate a reset.
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.
External Interrupts
The External Interrupts are triggered by the INT0, INT1, and INT2 pins. if enabled, the interrupts will
trigger even if the INT0..2 pins are configured as outputs. This feature provides a way of generating a
software interrupt. The external interrupts can be triggered by a falling or rising edge or a low level (INT2
is only an edge triggered interrupt).
MCU Control Register MCUCR
The MCU Control Register contains control bits for interrupt sense control and
general MCU functions.
Bit
7
SM2
6
SE
SM1
SM0
2
ISC11
1
ISC10
0
ISC01
ISC00
13
7
JTD
6
ISC2
5
--
4
JRTF
2
WDRF
1
BORF
0
EXTRF
PORF
7
INT1
6
INT0
5
INT2
3
--
2
--
1
--
0
IVSEL
IVCE
14
When the INT0 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), the external pin
interrupt is enabled.
Bit 5 INT2: External Interrupt Request 2 Enable
When the INT2 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), the external pin
interrupt is enabled. ISC2 in the MCUCSR defines whether the External Interrupt is activated on rising or
falling edge of the INT2 pin.
Bit 1 IVSEL: Interrupt Vector Select
When the IVSEL bit is cleared (zero), the Interrupt Vectors are placed at the start of the Flash memory.
When this bit is set (one), the interrupt vectors are moved to the beginning
of the Boot Loader section of the Flash.
Bit 0 IVCE: Interrupt Vector Change Enable
The IVCE bit must be written to logic one to enable change of the IVSEL bit. IVCE is cleared by hardware
four cycles after it is written or when IVSEL is written.
General Interrupt Flag Register GIFR
Bit
7
INTF1
6
INTF0
4
INTF2
3
--
2
--
1
--
0
--
--
TIMERS
8-bit Timer/Counter0 with PWM
Timer/Counter0 is a general purpose, single channel, 8-bit Timer/Counter module.
Registers
15
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).
Timer/Counter Control Register - TCCR0
Bit
FOC0
WGM00
COM01
COM00
WGM01
1
CS02
0
CS01
CS00
TCNT0[7:0]
16
The Timer/Counter Register gives direct access, both for read and write operations, to the Timer/Counter
unit 8-bit counter. Writing to the TCNT0 Register blocks (removes) the compare match on the following
timer clock. Modifying the counter (TCNT0) while the counter is running, introduces a risk of missing a
compare match between TCNT0 and the OCR0 Register.
3
2
1
0
OCR0[7:0]
The Output Compare Register contains an 8-bit value that is continuously compared with counter value
(TCNT0). A match can be used to generate an output compare interrupt,or to generate a waveform output
on the OC0 pin.
Timer/Counter Interrupt Mask Register TIMSK
Bit
7
OCIE2
6
TOIE2
5
TICIE1
4
3
OCIE1A OCIE1
B
2
TOIE1
1
0
OCIE0 TOIE0
7
OCF2
6
TOV2
5
ICF1
4
3
OCF1A OCF1B
2
1
0
TOV1
OCF0
TOV0
17
The bit TOV0 is set (one) when an overflow occurs in Timer/Counter0. TOV0 is cleared by hardware when
executing the corresponding interrupt handling vector. Alternatively, TOV0 is cleared by writing a logic
one to the flag.
16-bit Timer/Counter1
The 16-bit Timer/Counter unit allows accurate program execution timing (event management),
wave generation, and signal timing measurement.
REGISTER
The Timer/Counter (TCNT1), Output Compare Registers (OCR1A/B), and Input Capture
Register (ICR1) are all 16-bit registers. Special procedures must be followed when
accessing the 16-bit registers. The Timer/Counter Control Registers (TCCR1A/B) are
8-bit registers and have no CPU access restrictions. Interrupt requests (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).
The Timer/Counter can be clocked internally, via the prescaler, or by an external clock
source on the T1 pin. The output from the clock select logic is referred to as the timer clock (clkT1).
The double buffered Output Compare Registers (OCR1A/B) are compared with the
Timer/Counter value at all time. The result of the compare can be used by the Waveform
Generator to generate a PWM or variable frequency output on the Output Compare pin (OC1A/B). The
compare match event will also set the Compare Match Flag (OCF1A/B) which can be used to generate an
output compare interrupt request.
The Input Capture Register can capture the Timer/Counter value at a given external
(edge triggered) event on either the Input Capture Pin (ICP1) or on the Analog Comparator
pins
Analog to Digital Converter
The ATmega16 features a 10-bit successive approximation ADC. The ADC is connected
to an 8-channel Analog Multiplexer which allows 8 single-ended voltage inputs
constructed from the pins of Port A. The single-ended voltage inputs refer to 0V (GND).
The device also supports 16 differential voltage input combinations. Two of the differential
inputs (ADC1, ADC0 and ADC3, ADC2) are equipped with a programmable gain
stage. Seven differential analog input channels share a common negative terminal (ADC1), while any other
ADC input can be selected as the positive input terminal.
The ADC contains a Sample and Hold circuit which ensures that the input voltage to the
ADC is held at a constant level during conversion.
The ADC has a separate analog supply voltage pin, AVCC. AVCC must not differ more
than 0.3 V from VCC.
REGISTER
ADC Multiplexer Selection Register ADMUX
Bit
7
6
5
4
REFS01
REFS00
ADLAR
MUX4
2
MUX3
1
MUX2
0
MUX1
MUX0
18
3
ADIE
1
ADPS2
0
ADPS1
ADPS0
19
CODES
LINE FOLLOWER
//set your clock speed
#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
DDRA = 0x00; //input port
int left_sensor = 0;
int right_sensor = 0;
while(1)
//create an infinite loop
{
PORTD |=(1<<4); //motor enable
PORTD |=(1<<5); //motor enable
left_sensor = (PINA & 0b10000000); // define left sensor
right_sensor = (PINA & 0b00000001); // define right sensor
20
21
void main()
{ DDRC=0xFF;
DDRB=0x00;
PORTC=0xFF;
PORTB=0x00;
TCNT0=0x00;
TCCR0=0x05;
TIMSK=_BV(TOIE0);
sei();
while(1)
{ PORTC=0xAA;
_delay_ms(200); } }
IMAGE PROCESSING
RELATED TERMS
PIXEL : The pixel (a word invented from "picture element") is the basic unit of programmable color on a
computer display or in a computer image.
DIGITAL IMAGES : are electronic snapshots taken of a scene or scanned from documents, such as
photographs, manuscripts, printed texts, and artwork.
RESOLUTION is the ability to distinguish fine spatial detail. The spatial frequency at which a digital image
is sampled (the sampling frequency) is often a good indicator of resolution
QUANTIZATION refers to the number of available grayscale.
ASPECTS OF IMAGE PROCESSING
It is convenient to subdivide different image processing algorithms into broad subclasses. There
are dierent algorithms for different tasks and problems, and often we would like to distinguish the nature
of the task at hand.
Image enhancement.
This refers to processing an image so that the result is more suitable for a
particular application. Example include:
.. sharpening or de-blurring an out of focus image,
.. highlighting edges,
.. improving image contrast, or brightening an image
22
.. removing noise.
Image restoration.
This may be considered as reversing the damage done to an image by a
known cause, for example:
.. removing of blur caused by linear motion,
.. removal of optical distortions,
.. removing periodic interference.
Image segmentation.
This involves subdividing an image into constituent parts, or isolating
certain aspects of an image:
.. ending lines, circles, or particular shapes in an image,
.. in an aerial photograph, identifying cars, trees, buildings, or roads
23
colours. For convenience of storage and handling, the image has an associated colour map or colour
palette, which is simply a list of all the colours used in that image. Each pixel has a value which does not
give its colour (as for an RGB image), but an index to the colour in the map.
ARITHMATIC OPERATION
In this we can perform adding and subtracting task on an image
Matlab function imadd which is designed precisely for addition
>> b1=imadd(b,128);
Subtraction is similar;
>> b2=imsubtract(b,128);
And now we can view them:
>> imshow(b1),figure,imshow(b2)
HISTOGRAM
Histogram is a graph indicating the number of times gray level occur
in the image.
>> imshow(p),figure,imhist(p),axis tight
We can view the histogram of an image in Matlab by using
the imhist function:
>> p=imread('pout.tif');
NEIGHBOURHOOD PROCESSING
To change the grey level of a given pixel we need only know the value of the grey levels in a small
neighbourhood of pixels around the given pixel.
The combination of mask and function is called a filter. If the function by which the new grey value is
calculated is a linear function of all the grey values in the mask, then the filter is called a linear filter.
The filter2 function does the job of linear filtering for us; its use is
filter2(filter,image,shape)
and the result is a matrix of data type double. The parameter shape is optional, it describes
the
method for dealing with the edges
24
Thresholding
SINGLE THRESHOLDING
A pixel becomes
__
COMMANDS are
>> r=imread('rice.tif');
>> imshow(r),figure,imshow(r>110)
DOUBLE THRESHOLDING
A pixel becomes white if its grey level is between T1and T2 otherwise black if its grey level is
otherwise.
Command is
imshow(im2bw(x,map,0.45)&~{}im2bw(x,map,0.5))}
_
EDGE DETECTION
Edges contain some of the most useful information in an image.
We may use edges to measure
the size of objects in an image; to isolate particular objects from
their background; to recognize or
classify objects. The general Matlab command for finding edges is
edge(image,'method',parameters. . . )
some filters used are
sobel filter [ -1,-2,-1;0,0,0;1,2,1] and [-1,0,1;-2,0,2;-1,0,1]
edge detection
prewit filter [-1,-1,-1;0,0,0;-1,-1,-1] and [-1,0,-1;-1,0,-1;-1,0,-1]
A binary image
Dilation
Erosion
Edges
MORPHOLOGY
Morphology is a branch of image processing which is particularly useful for analyzing shapes in images.
25
Matlab has many tools for binary morphology in the image processing toolbox; most of which can be used
for greyscale morphology as well.
The morphological closing of an image, is the reverse: it consists of dilation followed by an erosion with the
same structuring element.
AND
c=imclose(A,B)
26
The following table lists all the standard two- and three-dimensional connectivities supported by the
toolbox.
Two-Dimensional Connectivitys
4-connected
8-connected
A parallel port is a type of interface found on computers (personal and otherwise) for
connecting various peripherals. It is also known as a printer port or Centronics port. The
IEEE 1284 standard defines the bi-directional version of the port.
This port will allow the input of up to 9 bits or the output of 12 bits at any one given time,
thus requiring minimal external circuitry to implement many simpler tasks.
The port is composed of 4 control lines, 5 status lines and 8 data lines. It's found commonly
on the back of your PC as a D-Type 25 Pin female connector
27
#include{stdio.h}
#include{conio.h}
#include{dos.h}
main()
{
outportb(0378,000); STOP MOTOR
sleep(2);
outportb(0378,001);MOVE MOTOR(CCW)
sleep(2);
outportb(0378,002);MOVE MOTOR(CW)
sleep(2);
outportb(0378,003);MOVE MOTOR(Break!)
sleep(2);
return 0;
}
SNAPSHOTS
Simple Line Follower (H-Bridge)
28
29