+ All Categories
Home > Documents > Robo Report for Robosapiens

Robo Report for Robosapiens

Date post: 07-Apr-2018
Category:
Upload: calvinnh
View: 219 times
Download: 1 times
Share this document with a friend

of 64

Transcript
  • 8/6/2019 Robo Report for Robosapiens

    1/64

    AND

    A REPORT

    ON

    ROBOTICS and Embedded C

    BY:-

    Jasmeet Singh

    SIP/09/20090527/094515

    Batch 3rd

  • 8/6/2019 Robo Report for Robosapiens

    2/64

    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.

  • 8/6/2019 Robo Report for Robosapiens

    3/64

    TABLE OF CONTENTS

    1. Basic Electronics

    1.1 Introduction to Transistors

    1.1.1 Construction1.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 Amplifier1.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 Motor1.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/Counter12.7 8-Bit Timer/Counter2

    2.8 Analog to Digital Converter

    2.9 Some Codes with ATmega16

  • 8/6/2019 Robo Report for Robosapiens

    4/64

    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

  • 8/6/2019 Robo Report for Robosapiens

    5/64

    Basic Electrical and Electronics

    Introduction To Transistors

    A Bipolar Junction Transistor (BJT) is widely used in discrete circuits as well as in IC

    design, both analog and digital. Its main applications are in amplification of small signals,

    and in switching digital logic signals. In a BJT both majority and minority carriers play a

    role in the operation of the transistor, hence the term bipolar.

    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.

  • 8/6/2019 Robo Report for Robosapiens

    6/64

    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.

    Connecting a BJT with External Circuit

    There are basically three possible ways to connect a Bipolar Transistor within an

    electronic circuit with each method of connection responding differently to its input

    signal as the static characteristics of the transistor vary with each circuit arrangement.

    1. Common Base Configuration - has Voltage Gain but no Current Gain.

    2. Common Emitter Configuration - has both Current and Voltage Gain.

    3. Common Collector Configuration - has Current Gain but no Voltage Gain.

    The Common Base Configuration

    As its name suggests, in the Common Base or Grounded Base configuration, the BASE

    connection is common to both the input signal AND the output signal with the input

    signal being applied between the base and the emitter terminals. The corresponding

    output signal is taken from between the base and the collector terminals as shown with

    the base terminal grounded or connected to a fixed reference voltage point. The input

    current flowing into the emitter is quite large as its the sum of both the base current and

    collector current respectively therefore, the collector current output is less than the

    emitter current input resulting in a Current Gain for this type of circuit of less than "1", or

    in other words it "Attenuates" the signal.

    The Common Base Amplifier Circuit

  • 8/6/2019 Robo Report for Robosapiens

    7/64

    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.

  • 8/6/2019 Robo Report for Robosapiens

    8/64

    The Common Emitter Amplifier Circuit

    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.

  • 8/6/2019 Robo Report for Robosapiens

    9/64

    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:

  • 8/6/2019 Robo Report for Robosapiens

    10/64

    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

  • 8/6/2019 Robo Report for Robosapiens

    11/64

    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

  • 8/6/2019 Robo Report for Robosapiens

    12/64

    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

  • 8/6/2019 Robo Report for Robosapiens

    13/64

    (-ve) voltage at their Collector terminal with the flow of current through the emitter-

    collector terminals being Holes as opposed to Electrons for the NPN types. Because the

    movement of holes across the depletion layertends 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.

    Connecting BJTs to make Logic Gates

    AND gate - Here you need to connect two transistors in a way that the output is high only

    when both inputs are high.1

  • 8/6/2019 Robo Report for Robosapiens

    14/64

    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.

  • 8/6/2019 Robo Report for Robosapiens

    15/64

    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.

    A circuit model of an operational amplifier (op amp) with gain and input and output

    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

  • 8/6/2019 Robo Report for Robosapiens

    16/64

    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 .

    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.

    +Vcc

  • 8/6/2019 Robo Report for Robosapiens

    17/64

    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.

  • 8/6/2019 Robo Report for Robosapiens

    18/64

    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.

  • 8/6/2019 Robo Report for Robosapiens

    19/64

    Instrumentation Amplifier

    An instrumentation (or instrumentational) amplifier is a type ofdifferential amplifierthat

    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

    The ideal common-mode gain of an instrumentation amplifier is zero.

    Vout =(1+ 2R1 ) R3

    V2-V1 Rgain R2

    http://en.wikipedia.org/wiki/Differential_amplifierhttp://en.wikipedia.org/w/index.php?title=Test_equipment&action=edit&redlink=1http://en.wikipedia.org/wiki/Differential_amplifierhttp://en.wikipedia.org/w/index.php?title=Test_equipment&action=edit&redlink=1
  • 8/6/2019 Robo Report for Robosapiens

    20/64

    555 Timer IC

    The 555 Timer IC is an integrated circuit (chip) implementing a variety of timer and

    multivibratorapplications. 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).

    The 555 has three operating modes:

    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.

    http://en.wikipedia.org/wiki/Integrated_circuithttp://en.wikipedia.org/wiki/Timerhttp://en.wikipedia.org/wiki/Multivibratorhttp://en.wikipedia.org/wiki/555_timer_IC#cite_note-0%23cite_note-0http://en.wikipedia.org/wiki/Ohmhttp://en.wikipedia.org/wiki/555_timer_IC#cite_note-1%23cite_note-1http://en.wikipedia.org/wiki/Transistorhttp://en.wikipedia.org/wiki/Diodehttp://en.wikipedia.org/wiki/Resistorhttp://en.wikipedia.org/wiki/DIP-8http://en.wikipedia.org/wiki/Monostablehttp://en.wikipedia.org/wiki/Astablehttp://en.wikipedia.org/wiki/Oscillatorhttp://en.wikipedia.org/wiki/LEDhttp://en.wikipedia.org/wiki/Pulse_position_modulationhttp://en.wikipedia.org/wiki/Integrated_circuithttp://en.wikipedia.org/wiki/Timerhttp://en.wikipedia.org/wiki/Multivibratorhttp://en.wikipedia.org/wiki/555_timer_IC#cite_note-0%23cite_note-0http://en.wikipedia.org/wiki/Ohmhttp://en.wikipedia.org/wiki/555_timer_IC#cite_note-1%23cite_note-1http://en.wikipedia.org/wiki/Transistorhttp://en.wikipedia.org/wiki/Diodehttp://en.wikipedia.org/wiki/Resistorhttp://en.wikipedia.org/wiki/DIP-8http://en.wikipedia.org/wiki/Monostablehttp://en.wikipedia.org/wiki/Astablehttp://en.wikipedia.org/wiki/Oscillatorhttp://en.wikipedia.org/wiki/LEDhttp://en.wikipedia.org/wiki/Pulse_position_modulation
  • 8/6/2019 Robo Report for Robosapiens

    21/64

    Bistable mode orSchmitt 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.

    Schematic symbol

    The connection of the pins is as follows:

    Nr. Name Purpose

    1 GND Ground, low level (0V)

    2 TRIG A short pulse high-to-low on the trigger starts the timer

    3 OUT During a timing interval, the output stays at +VCC

    4 RESET A timing interval can be interrupted by applying a reset pulse to low (0V)

    5 CTRL Control voltage allows access to the internal voltage divider (2/3 VCC)

    6 THR The threshold at which the interval ends (it ends if U.thr 2/3 VCC)

    7 DISConnected to a capacitor whose discharge time will influence the timing

    interval

    8 V+, VCC The positive supply voltage which must be between 3 and 15 V

    http://en.wikipedia.org/wiki/Bistablehttp://en.wikipedia.org/wiki/Schmitt_triggerhttp://en.wikipedia.org/wiki/Flip-flop_(electronics)http://en.wikipedia.org/wiki/Vcchttp://en.wikipedia.org/wiki/Vcchttp://en.wikipedia.org/wiki/Bistablehttp://en.wikipedia.org/wiki/Schmitt_triggerhttp://en.wikipedia.org/wiki/Flip-flop_(electronics)http://en.wikipedia.org/wiki/Vcc
  • 8/6/2019 Robo Report for Robosapiens

    22/64

    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 = 0.7 (R1 + 2R2) C1 and f =1.4

    (R1 + 2R2) C1

    T = time period in seconds (s)

    f = frequency in hertz (Hz)

    R1 = resistance in ohms ( )

    R2 = resistance in ohms ( )

    C1 = capacitance in farads (F)

    555 astable output, a square wave

    (Tm and Ts may be different)

    555 astable circuit

    http://www.kpsec.freeuk.com/acdc.htm#propshttp://www.kpsec.freeuk.com/acdc.htm#propshttp://www.kpsec.freeuk.com/acdc.htm#propshttp://www.kpsec.freeuk.com/acdc.htm#props
  • 8/6/2019 Robo Report for Robosapiens

    23/64

    The time period can be split into two parts: T = Tm + Ts

    Mark time (output high): Tm = 0.7 (R1 + R2) C1

    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

  • 8/6/2019 Robo Report for Robosapiens

    24/64

    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 a particularly loud sound.

    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%:

    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 (ignoring 0.7V across

    diode)

    Ts = 0.7 R2 C1 (unchanged)

    Duty cycle

    with diode =

    Tm=

    R1

    Tm + Ts R1 + R2

    555 astable circuit with diode across R2

  • 8/6/2019 Robo Report for Robosapiens

    25/64

    555 Monostable

    A monostable circuit produces a

    single output pulse when triggered. It

    is called a monostable because it is

    stable in just one state: 'output low'.

    The 'output high' state is temporary.

    The duration of the pulse is called the

    time period (T) and this is determined

    by resistor R1 and capacitor C1:

    time period, T = 1.1 R1 C1

    T = time period in seconds (s)

    R1 = resistance in ohms ( )

    C1 = capacitance in farads (F)

    The maximum reliable time period is about 10 minutes.

    Why 1.1? The capacitor charges to 2/3 = 67% so it is a bit longer than the time constant

    (R1 C1) which is the time taken to charge to 63%.

    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 to

    1M , so use a fixed resistor of at least 1k in series if R1 is variable.

    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!

    555 monostable output, a single pulse

    555 monostable circuit with manual trigger

    http://www.kpsec.freeuk.com/capacit.htm#timeconstanthttp://www.kpsec.freeuk.com/projects/timer.htmhttp://www.kpsec.freeuk.com/capacit.htm#timeconstanthttp://www.kpsec.freeuk.com/projects/timer.htm
  • 8/6/2019 Robo Report for Robosapiens

    26/64

    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.

    555 Bistable (flip-flop) - a

    memory circuit

    The circuit is called a bistable because

    it is stable in two states: output high

    and output low. It is also known as a

    'flip-flop'.

    It has two inputs:

    555 bistable circuit

  • 8/6/2019 Robo Report for Robosapiens

    27/64

    Trigger (555 pin 2) makes the output high.

    Trigger is 'active low', it functions when < 1/3 Vs.

    Reset (555 pin 4) makes the output 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 andS4 switches and closing S2 and S3 switches, this voltage is reversed, allowing reverse

    operation of the motor.

    http://www.kpsec.freeuk.com/555timer.htm#monostable%23monostablehttp://www.kpsec.freeuk.com/555timer.htm#monostable%23monostable
  • 8/6/2019 Robo Report for Robosapiens

    28/64

    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 Result

    1 0 0 1 Motor moves right

    0 1 1 0 Motor moves left

    0 0 0 0 Motor free runs

    0 1 0 1 Motor brakes

    1 0 1 0 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 motorthat runs on direct current (DC) electricity

    http://en.wikipedia.org/wiki/Electric_motorhttp://en.wikipedia.org/wiki/Direct_currenthttp://en.wikipedia.org/wiki/Electric_motorhttp://en.wikipedia.org/wiki/Direct_current
  • 8/6/2019 Robo Report for Robosapiens

    29/64

    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 curveproduced 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

    http://en.wikipedia.org/wiki/Electrical_energyhttp://en.wikipedia.org/wiki/Mechanical_workhttp://en.wikipedia.org/wiki/Magnetic_fieldhttp://en.wikipedia.org/wiki/Voltage_sourcehttp://en.wikipedia.org/wiki/Electrical_connectionhttp://en.wikipedia.org/wiki/Rotational_energyhttp://en.wikipedia.org/wiki/Torquehttp://en.wikipedia.org/wiki/Single_coilhttp://en.wikipedia.org/wiki/Electrical_energyhttp://en.wikipedia.org/wiki/Mechanical_workhttp://en.wikipedia.org/wiki/Magnetic_fieldhttp://en.wikipedia.org/wiki/Voltage_sourcehttp://en.wikipedia.org/wiki/Electrical_connectionhttp://en.wikipedia.org/wiki/Rotational_energyhttp://en.wikipedia.org/wiki/Torquehttp://en.wikipedia.org/wiki/Single_coil
  • 8/6/2019 Robo Report for Robosapiens

    30/64

    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 abrushless, synchronous electric motorthat 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-

    http://en.wikipedia.org/wiki/Rotational_speedhttp://en.wikipedia.org/wiki/Brushless_DC_electric_motorhttp://en.wikipedia.org/wiki/Electric_motorhttp://en.wikipedia.org/wiki/Open-loop_controllerhttp://en.wikipedia.org/wiki/Reluctance_motorhttp://en.wikipedia.org/wiki/Rotational_speedhttp://en.wikipedia.org/wiki/Brushless_DC_electric_motorhttp://en.wikipedia.org/wiki/Electric_motorhttp://en.wikipedia.org/wiki/Open-loop_controllerhttp://en.wikipedia.org/wiki/Reluctance_motor
  • 8/6/2019 Robo Report for Robosapiens

    31/64

    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 motorswith 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 afull 360 degrees or more. However, servos are unable to continually rotate, meaning they

    can't be used for driving wheels (unlessmodified), but their precision positioning makes

    them ideal forrobot 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

    http://www.societyofrobots.com/actuators_dcmotors.shtmlhttp://www.societyofrobots.com/actuators_dcmotors.shtmlhttp://www.societyofrobots.com/actuators_modifyservo.shtmlhttp://www.societyofrobots.com/actuators_modifyservo.shtmlhttp://www.societyofrobots.com/robot_arm_tutorial.shtmlhttp://www.societyofrobots.com/actuators_dcmotors.shtmlhttp://www.societyofrobots.com/actuators_modifyservo.shtmlhttp://www.societyofrobots.com/robot_arm_tutorial.shtml
  • 8/6/2019 Robo Report for Robosapiens

    32/64

    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 yourmicrocontroller). Vary the square wave pulse width from 1-

    2ms 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.

    ADC

    Successive Approximation

    Successive approximation ADC is a type of analog-to-digital converter that converts a

    continuous analog waveform into a discrete digital representation via a binary search

    through all possible quantization levels before finally converging upon a digital output

    for each conversion.

    http://www.societyofrobots.com/microcontroller_tutorial.shtmlhttp://en.wikipedia.org/wiki/Analog-to-digital_converterhttp://en.wikipedia.org/wiki/Analog_signalhttp://en.wikipedia.org/wiki/Digitalhttp://en.wikipedia.org/wiki/Binary_searchhttp://en.wikipedia.org/wiki/Quantization_(signal_processing)http://www.societyofrobots.com/microcontroller_tutorial.shtmlhttp://en.wikipedia.org/wiki/Analog-to-digital_converterhttp://en.wikipedia.org/wiki/Analog_signalhttp://en.wikipedia.org/wiki/Digitalhttp://en.wikipedia.org/wiki/Binary_searchhttp://en.wikipedia.org/wiki/Quantization_(signal_processing)
  • 8/6/2019 Robo Report for Robosapiens

    33/64

    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

  • 8/6/2019 Robo Report for Robosapiens

    34/64

    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

    Up to 16 MIPS Throughput at 16 MHz

    On-chip 2-cycle Multiplier

    Nonvolatile Program and Data Memories

    16K Bytes of In-System Self-Programmable Flash

    1K Byte Internal SRAM

    JTAG (IEEE std. 1149.1 Compliant) Interface

    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

    7 Differential Channels in TQFP Package Only

    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

    I/O and Packages

  • 8/6/2019 Robo Report for Robosapiens

    35/64

    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

  • 8/6/2019 Robo Report for Robosapiens

    36/64

    Pin DescriptionsVCC 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.

  • 8/6/2019 Robo Report for Robosapiens

    37/64

    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 OptionsClock Systems and their

    DistributionCPU 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

  • 8/6/2019 Robo Report for Robosapiens

    38/64

    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.

  • 8/6/2019 Robo Report for Robosapiens

    39/64

    I/O Ports

  • 8/6/2019 Robo Report for Robosapiens

    40/64

  • 8/6/2019 Robo Report for Robosapiens

    41/64

    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

  • 8/6/2019 Robo Report for Robosapiens

    42/64

    External Interrupts

    MCU Control Register(MCUCR)

    ISC11, ISC10: Interrupt Sense Control 1 Bit 1 and Bit 0

    ISC01, ISC00: Interrupt Sense Control 0 Bit 1 and Bit 0

    MCU Control and Status

    Register MCUCSR

    ISC2: Interrupt Sense Control 2

    8-bit Timer/Counter0Timer/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 UnitThe 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.

  • 8/6/2019 Robo Report for Robosapiens

    43/64

    8-bit Timer/Counter

    Register Description

    Timer/Counter Control

    Register TCCR0

    FOC0: Force Output Compare

    WGM01:0: Waveform Generation Mode

    COM01:0: Compare Match Output Mode

    CS02:0: Clock Select

    Timer/Counter Interrupt Mask

    Register TIMSK

    OCIE0: Timer/Counter0 Output Compare Match Interrupt Enable

    TOIE0: Timer/Counter0 Overflow Interrupt Enable

  • 8/6/2019 Robo Report for Robosapiens

    44/64

    16-bit Timer/Counter1The 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;

    16-bit Timer/Counter

    Register Description

    Timer/Counter1 Control

    Register A TCCR1A

    COM1A1:0: Compare Output Mode for Channel ACOM1B1:0: Compare Output Mode for Channel B

    FOC1A: Force Output Compare for Channel AFOC1B: Force Output Compare for Channel B

    WGM11:0: Waveform Generation Mode

  • 8/6/2019 Robo Report for Robosapiens

    45/64

    Timer/Counter1 Control

    Register B TCCR1B

    ICNC1: Input Capture Noise Canceler

    ICES1: Input Capture Edge Select

    WGM13:2: Waveform Generation ModeCS12:0: Clock Select

    Timer/Counter Interrupt Mask

    Register TIMSK

    TICIE1: Timer/Counter1, Input Capture Interrupt EnableOCIE1A: Timer/Counter1, Output Compare A Match Interrupt Enable

    OCIE1B: Timer/Counter1, Output Compare B Match Interrupt EnableTOIE1: Timer/Counter1, Overflow Interrupt Enable

  • 8/6/2019 Robo Report for Robosapiens

    46/64

    8-bit Timer/Counter2Timer/Counter2 is a general purpose, single channel, 8-bit Timer/Counter module .

    8-bit Timer/Counter

    Register DescriptionTimer/Counter Control

    Register TCCR2

    FOC2: Force Output Compare

    WGM21:0: Waveform Generation ModeCOM21: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

  • 8/6/2019 Robo Report for Robosapiens

    47/64

    Analog to Digital

    Converter

    ADC Multiplexer Selection

    Register ADMUX

    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 EnableADIF: ADC Interrupt Flag

    ADIE: ADC Interrupt Enable

    ADPS2:0: ADC Prescaler Select Bits

    The ADC Data Register ADCL and ADCH

  • 8/6/2019 Robo Report for Robosapiens

    48/64

    Some codes with ATmega16

    Code for Line Follower using 2 Sensors and 2 DC motors

    #define F_CPU 12000000UL //set your clock speed#include

    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

  • 8/6/2019 Robo Report for Robosapiens

    49/64

    PORTD |=(1

  • 8/6/2019 Robo Report for Robosapiens

    50/64

    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

  • 8/6/2019 Robo Report for Robosapiens

    51/64

    if(( left_sensor==left_sensor_on) & (right_sensor==right_sensor_on))

    {PORTD = move_forward;

    left_sensor = 0;

    right_sensor = 0;}

    }

    }

    Code for 7-segment display

    #define F_CPU 12000000UL

    #include

    #include#include

    #includevoid main()

    {

    DDRA=0x00;DDRB=0x00;

    DDRC=0xFF;

    while(1)

    {if(bit_is_set(PINA,0))

    PORTC = 0b00111111;else if(bit_is_set(PINA,1))

    PORTC = 0b00000110;

    else if(bit_is_set(PINA,2))

    PORTC = 0b01011011;else if(bit_is_set(PINA,3))

    PORTC = 0b01001111;

    else if(bit_is_set(PINA,4))PORTC = 0b01100110;

    else if(bit_is_set(PINA,5))

    PORTC = 0b01101101;

    else if(bit_is_set(PINA,6))PORTC = 0b01111101;

    else if(bit_is_set(PINA,7))

    PORTC = 0b000000111;else if(bit_is_set(PINB,0))

    PORTC = 0b01111111;

    else if(bit_is_set(PINB,1))PORTC = 0b01101111;

  • 8/6/2019 Robo Report for Robosapiens

    52/64

    }

    }

    Code for generation of PWM wave

    #define F_CPU 12000000UL#include

    #include

    #include#include

    void main()

    { DDRB=0x00;PORTB=oxFF;

    TCCR0=0b01110101;

    TIMSK=0x02;

    while(1)

    {for(int i=0;i=0;j--){

    OCR0=j;

    _delay_ms(250);_delay_ms(250);

    }

    }

    }

    Code for Timers in Compare and Overflow Mode

    Overflow Mode

    #define F_CPU 12000000UL

    #include

    #include#include

    #include

    int count=0;

    ISR(TIMER0_OVF_vect){

  • 8/6/2019 Robo Report for Robosapiens

    53/64

    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#include

    #include

    #include

    ISR(TIMER0_COMP_vect)

    {count++;

    if(count==4)

    {

    PORTC=~PORTC;count=0;

    }

    }

    int main()

    {DDRC=0xFF;DDRA=0xFF;

    PORTA=0x00;

    PORTC=0x00;

  • 8/6/2019 Robo Report for Robosapiens

    54/64

    TCNT0=0x00;

    OCR0=0xFF;

    TCCR0=0x15;TIMSK=0x02;

    sei();

    while(1){

    }

    }

    Code for Timer in Overflow mode

    #define F_CPU 12000000UL

    #include

    #include

    #include

    #include

    ISR(TIMER0_OVF_vect){

    _delay_ms(250);

    PORTC=0b10000000;}

    }

    int main()

    {DDRC=0xFF;

    PORTC=0x00;

    TCNT0=0x00;

    TCCR0=0x03; //prescalar set to 64

    TIMSK=0x01;sei();

    while(1)

    {_delay_ms(250);

    PORTC=0b00000001;

    }

    }

  • 8/6/2019 Robo Report for Robosapiens

    55/64

    Code for External Interrupts in Overflow Mode

    #define F_CPU 12000000UL#define time 0x00

    #include

    #include#include

    #include

    ISR(int0)

    {

    time=0x80;

    }

    ISR(int0)

    {

    time=0x40;}

    int main()

    {

    DDRA=0xFF;PORTA=0x00;

    TCNT0=time;

    TCCR0=0x03;

    TIMSK=0x01;MCUCR=0x0E;

    sei();

    while(1)

    {_delay_ms(250);PORTA=0xFF:

    }

    }

    Code for ADC

    #include#include

    int call_ADC(){

    while(ADCSRA & 00010000) // waiting till adif flag is set

    {return(ADC); // ADC=(vin/vout)*1024

  • 8/6/2019 Robo Report for Robosapiens

    56/64

    }

    }

    void main()

    {

    DDRA=0x00;PORTA=0x01;

    ADMUX=ob00000001 //read analog frm channel 0ADCSRA=0b11001111; // prescaler=128 and ADIE is set

    int adc=call_ADC();

    if(adc>0x000&&adc

  • 8/6/2019 Robo Report for Robosapiens

    57/64

    IMAGE PROCESSING

    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.

    Some Common Formats JPEG

    BMP GIF

    PNG

    TIFF

    SamplingSampling 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

    Acquisition

    of Image

    Image

    Processor

    Image

    Analysis

    Machine vision

  • 8/6/2019 Robo Report for Robosapiens

    58/64

    QuantizationQuantization 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.

    Functions in MATLAB for Image Processing1. imread()- Read image from graphics file. A = imread(filename,fmt) reads a

    greyscale or color image from the file specified by the string filename, where the

    string fmt specifies the format of the file. If the file is not in the current directory

    or in a directory in the MATLAB path, specify the full pathname of the location

    on your system. imread returns the image data in the array A.

    2. imshow()- Display image. imshow(I) displays the grayscale image I.

    imshow(RGB) displays the truecolor image RGB. imshow(BW) displays the

    binary image BW. imshow(I/4) or (I*4) or (I+4) or (I-4) is used to vary the

    grayscale of an image.

    3. rgb2gray()- Convert an RGB image or colormap to grayscale. I =

    rgb2gray(RGB) converts the truecolor image RGB to the grayscale intensity

    image I.

    4. imfinfo()- information about graphics file. info = imfinfo(filename,fmt) returns a

    structure, info, whose fields contain information about an image in a graphics file.

    5. imwrite()- Write image to graphics file. imwrite(A,filename,fmt) writes the

    image A to the file specified by filename in the format specified by fmt.

    6. imhist()- Display histogram of image data. imhist(I) displays a histogram for the

    intensity image I above a grayscale colorbar.

    7. histeq()- Enhance contrast using histogram equalization. histeq enhances the

    contrast of images by transforming the values in an intensity image, or the values

    in the colormap of an indexed image, so that the histogram of the output image

    approximately matches a specified histogram.

    8. imadjust()- Adjust image intensity values or colormap. J = imadjust(I,[low_in;

    high_in],[low_out; high_out],gamma) maps the values in intensity image I to new

  • 8/6/2019 Robo Report for Robosapiens

    59/64

    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.

  • 8/6/2019 Robo Report for Robosapiens

    60/64

    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 ratioK=imfinfo('F:\ROBOSAPIENS\Image database\saturn.png');Imgbytes=K.Height*K.Width*K.BitDepth/8;

    Compbytes=K.FileSize;

    Ratio=Imgbytes/Compbytes;

    Code for detecting lines in an imagea=imread('F:\ROBOSAPIENS\Image database\saturn.png');img2=im2bw(a);

    i=edge(double(img2),'sobel',[]);

    imshow(i);

    Code for acquiring a videovid=videoinput('winvideo',1);triggerconfig(vid,'manual');

    set(vid,'FramesPerTrigger',1 );

    set(vid,'TriggerRepeat', Inf);

    start(vid);

  • 8/6/2019 Robo Report for Robosapiens

    61/64

    for i=1:1:5

    trigger(vid);

    im= getdata(vid,1);figure,imshow(im);

    end

    stop(vid),delete(vid),clear vid;

    Code for finding the number of balls in an imageI=imread(ball.jpg);im=rgb2gray(I);

    level= graythresh(im);

    ib=im2bw(im,level);[labeled,numObjects]=bwlabel(ib,8);

    x=regionprops(labeled,'basic');

    k=0;

    for j=1:20

    if x(j).Area>2500k=k+1;

    endend

    Code for finding the location of objectvid=videoinput('winvideo',1);

    im=getsnapshot(vid);

    for i=1:5trigger(vid);

    im= getsnapshot(vid);

    figure,imshow(im);s=size(im);

    level= graythresh(im);

    ib=im2bw(im,level);[labeled,numObjects]=bwlabel(ib,8);

    x=regionprops(labeled,'basic');

    maxar=max([x.Area]);v=find([x.Area]==maxar);

    centroid=x(v).Centroid;

    if(centroid(1)s(2)/2)disp('second');

    end

    if (centroid(1)s(2)/2)disp('fourth');

  • 8/6/2019 Robo Report for Robosapiens

    62/64

    end

    if(centroid(1)>s(1)/2 && centroid(2)>s(2)/2)

    disp('first');end

    end

    Code for Erosion and Dilation of an imagea=imread('F:\ROBOSAPIENS\Image database\saturn.png');

    img=rgb2gray(a);img2=im2bw(img,0.5);

    B=strel('diamond',5);

    img3=imerode(img2,B);imshow(img3),figure;

    img4=imdilate(img2,B);

    imshow(img4),figure;

    Code for counting Frames per Secondtic;

    vid = videoinput('winvideo');

    k=0;

    while(k

  • 8/6/2019 Robo Report for Robosapiens

    63/64

    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]

    Code for parallel port data transfer using MATLABparport = digitalio('parallel','LPT1'); % define a parallel port

    hwlines = addline(parport,0:7,'out'); % define 8 output lines on parallel port

    bvdata = [1 1 1 1 1 1 1 1]; % Parallel port sequence for clockwise rotation

    bvdata0 = [1 1 0 0 0 0 0 0]; % parallel port sequence for stopping the motorputvalue(bvdata);

  • 8/6/2019 Robo Report for Robosapiens

    64/64

    --------------------------------X------------------------------------X-----------------------------------


Recommended