a tutorial on robotics part iv

Upload: vipul-jain

Post on 14-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 A Tutorial on Robotics Part IV

    1/38

    Copyright Robotix Team, IIT Kharagpur

    February 3rd-5th, 2006

  • 7/29/2019 A Tutorial on Robotics Part IV

    2/38

    Copyright Robotix Team, IIT Kharagpur

    A Tutorial on Robotics

    Part IV : Microcontrollers & ComputerControl

  • 7/29/2019 A Tutorial on Robotics Part IV

    3/38

    Copyright Robotix Team, IIT Kharagpur

    AVR Family of Microcontrollers

    8-bit RISC Architecture, single cycleinstructions

    Principle features include

    Internal oscillators, timers, UART, SPI, PWMgeneration, ADC, analog comparator andmore

    Amenability to C programming

    In-System-Programmable (ISP) FlashMemory

    http://www.atmel.com/products/AVR/

  • 7/29/2019 A Tutorial on Robotics Part IV

    4/38

    Copyright Robotix Team, IIT Kharagpur

    ATmega8 AVR Family Member

    Up to 16 MIPS throughput

    8KB ISP Flash Memory, 1KB SRAM,

    512Byte EEPROM 8bit / 16bit timers / counters

    Three PWM channels

    8 Channel 10 bit ADC, AnalogComparator

    Programmable UART, SPI, TWI

  • 7/29/2019 A Tutorial on Robotics Part IV

    5/38

    Copyright Robotix Team, IIT Kharagpur

    ATmega8 PDIP Package

  • 7/29/2019 A Tutorial on Robotics Part IV

    6/38

    Copyright Robotix Team, IIT Kharagpur

    ATmega8 TQFP Package

  • 7/29/2019 A Tutorial on Robotics Part IV

    7/38

    Copyright Robotix Team, IIT Kharagpur

    ISP Flash Memory

    ISP : In-System-Programmable FlashROM

    No need of specialized programmerhardware

    No need to remove processor fromcircuit for reprogramming

  • 7/29/2019 A Tutorial on Robotics Part IV

    8/38

    Copyright Robotix Team, IIT Kharagpur

    STK200 ISP Dongle

    PonyProg Programming Softwarehttp://www.lancos.com/prog.html

  • 7/29/2019 A Tutorial on Robotics Part IV

    9/38

    Copyright Robotix Team, IIT Kharagpur

    WinAVR

    WinAVR is a open source softwaredevelopment suite for Atmel AVRseries of RISC microcontrollers

    GUI Integrated DevelopmentEnvironment

    Includes the GNU GCC compiler for C

    and C++.

    http://winavr.sourceforge.net/

  • 7/29/2019 A Tutorial on Robotics Part IV

    10/38

    Copyright Robotix Team, IIT Kharagpur

    WinAVR IDE Screenshot

  • 7/29/2019 A Tutorial on Robotics Part IV

    11/38

    Copyright Robotix Team, IIT Kharagpur

    Procyon AVRlib

    AVRlib is a library of easy-to-use Cfunctions for AVR controllers

    AVRlib aims to allow programmers towork quickly towards their end goalby reducing the time needed to writebasic support functions and code

    http://www.procyonengineering.com/avr/avrlib/

  • 7/29/2019 A Tutorial on Robotics Part IV

    12/38

    Copyright Robotix Team, IIT Kharagpur

    PWM DC Motor Control

    //Dual 8-bit PWM mode setup of timer 1

    timer1PWMInit (8);

    // Frequency Prescaling to F_CPU_CLOCK / 256

    timer1SetPrescaler (4);

    // Left and right motor speed settimer1PWMASet (lSpeed); // Pin 15 (OC1A)

    timer1PWMBSet (rSpeed); // Pin 16 (OC1B)

    // Start on the PWM generation

    timer1PWMAOn ();

    timer1PWMBOn ();

  • 7/29/2019 A Tutorial on Robotics Part IV

    13/38

    Copyright Robotix Team, IIT Kharagpur

    ADCs & Analog Comparator

    DDRA = 0x00; // Configure Port A (ADC) as Input

    PORTA = 0x00;// Disable internal pull up resistors

    // Initialize Analog to Digital Converter

    a2dInit();

    // Set conversion speed

    a2dSetPrescaler(ADC_PRESCALE_DIV32);

    // Set analog voltage reference

    a2dSetReference(ADC_REFERENCE_AVCC);

    // Acquire analog data into digital formatfor (i = 0; i < 8; i ++)

    adcData [i] = a2dConvert8bit(i);

  • 7/29/2019 A Tutorial on Robotics Part IV

    14/38

    Copyright Robotix Team, IIT Kharagpur

    UART - Serial Communication

    // Initialize UART at 2400 bps

    uartInit();

    uartSetBaudRate (2400);

    // Check is data received

    if (!uartReceiveBufferIsEmpty ()){

    // if data received then get it in a variable

    uartReceiveByte (&dataIn);

    // do whatever u wish with dataIn

    }

  • 7/29/2019 A Tutorial on Robotics Part IV

    15/38

    Copyright Robotix Team, IIT Kharagpur

    Crystal Oscillator Clock Source

  • 7/29/2019 A Tutorial on Robotics Part IV

    16/38

    Copyright Robotix Team, IIT Kharagpur

    AVR Fuse settings

    CKOPT CKSEL3:0 Frequency(MHz)

    C1 & C2

    1 1010 0.4 0.9 -

    1 1101 0.9 3.0 12 22 pf

    1 1111 3.0 8.0 12 22 pf

    0 1011, 1101,1111

    >= 1.0 12 22 pf

    SUT 1:0 = 11

  • 7/29/2019 A Tutorial on Robotics Part IV

    17/38

    Copyright Robotix Team, IIT Kharagpur

    Computer Control

    Parallel & Serial Port Communication

  • 7/29/2019 A Tutorial on Robotics Part IV

    18/38

    Copyright Robotix Team, IIT Kharagpur

    PC Parallel Port - Features

    Commonly known as the printer port

    25 pin D-Type connector

    It has 12 digital output pins, 5 digitalinput pins

    Pins operate at the TTL voltage leveli.e. 0 5V

    Port identified by a base address inthe computer I/O memory space

  • 7/29/2019 A Tutorial on Robotics Part IV

    19/38

    Copyright Robotix Team, IIT Kharagpur

    PC Parallel Port Pin Layout

  • 7/29/2019 A Tutorial on Robotics Part IV

    20/38

    Copyright Robotix Team, IIT Kharagpur

    PC Parallel Port I/O Registers

    Most PCs have 378 Hex base address

    8 output pins are accessed via the

    DATA port (Base address) 4 output pins are accessed via the

    CONTROL port (Base address + 2)

    5 input pins are accessed via theSTATUS port (Base address + 1)

  • 7/29/2019 A Tutorial on Robotics Part IV

    21/38

    Copyright Robotix Team, IIT Kharagpur

    PC Parallel Port I/O Registers

    - marked bits in register byte are unused

  • 7/29/2019 A Tutorial on Robotics Part IV

    22/38

    Copyright Robotix Team, IIT Kharagpur

    Accessing Parallel Port VC ++

    #include

    #define Data 0x378 // Base address#define Status 0x379 // Base address + 1

    #define Control 0x37a // Base address + 2

    int main () {unsigned char Bits;Bits = 0b11001010;

    _outp(Data, Bits); /* output data */Bits = _inp(Status);/* input data */return (0);}

  • 7/29/2019 A Tutorial on Robotics Part IV

    23/38

    Copyright Robotix Team, IIT Kharagpur

    PC Serial Port - Features

    Most commonly 9 pin D-Typeconnector. 25 pin D-Type is rare

    Pins operate at -25 to + 25 voltagelevels

    Data transmitted as a bit sequence

    Known as the EIA RS232C port orsimply RS232

  • 7/29/2019 A Tutorial on Robotics Part IV

    24/38

    Copyright Robotix Team, IIT Kharagpur

    EIA RS232C Specifications

    Logic 0 is between +3 to +25 volts

    Logic 1 is between -3 to -25 volts

    -3 to +3 volts region is undefined Maximum data rate of 19,600 bps

  • 7/29/2019 A Tutorial on Robotics Part IV

    25/38

    Copyright Robotix Team, IIT Kharagpur

    Serial Port vs. Parallel Port

    Serial cables can be much longer thatParallel cables 50V swing compared to 5V swing

    Null Modem Configuration just needs3 core cable compared to 19 coreparallel port cable

    Serial suited for wireless transmission Microcontrollers just need two pins

    (RXD & TXD) for communication

  • 7/29/2019 A Tutorial on Robotics Part IV

    26/38

    Copyright Robotix Team, IIT Kharagpur

    Null Modem Configuration

    Pin 3 Transmit Data

    Pin 2 Receive Data

    Pin 5 Signal Ground Pin 4, 6, 1 shorted together

    Pin 7, 8 shorted together

  • 7/29/2019 A Tutorial on Robotics Part IV

    27/38

    Copyright Robotix Team, IIT Kharagpur

    RS-232 Waveforms

    Asynchronous Communication i.e. separateclock at both ends

    Frame synchronization done by the start /stop bit

    Line is kept logic 1 when idle. Start bit islogic 0

    Bit order from LSB to MSB

  • 7/29/2019 A Tutorial on Robotics Part IV

    28/38

    Copyright Robotix Team, IIT Kharagpur

    RS-232 Level Converters

    For using theRS232 data, digitaldevices need

    TTL/CMOS voltagelevels

    Level conversion isdone using IC

    MAX232 / DS232

  • 7/29/2019 A Tutorial on Robotics Part IV

    29/38

    Copyright Robotix Team, IIT Kharagpur

    RS-232 frame decoding

    The decoding of the bit sequenceframe is done by computer hardware

    When communicating with robots,decoding done by onboardmicrocontroller

    Microcontroller Serial communication

    interface is known as UART (UniversalAsynchronous Receiver Transmitter)

  • 7/29/2019 A Tutorial on Robotics Part IV

    30/38

    Copyright Robotix Team, IIT Kharagpur

    Accessing Serial Port - VB

    MSComm Control 6.0 is used forserial port communication

  • 7/29/2019 A Tutorial on Robotics Part IV

    31/38

    Copyright Robotix Team, IIT Kharagpur

    MSComm Control Properties

  • 7/29/2019 A Tutorial on Robotics Part IV

    32/38

    Copyright Robotix Team, IIT Kharagpur

    MSComm Control Properties

    Com Port identification number

    Settings: Baud Rate, Parity Check,Data Bits, Stop Bits

    Hand Shaking Method : Xon/Xoff fornull-modem configuration

  • 7/29/2019 A Tutorial on Robotics Part IV

    33/38

    Copyright Robotix Team, IIT Kharagpur

    MSComm Control Properties

  • 7/29/2019 A Tutorial on Robotics Part IV

    34/38

    Copyright Robotix Team, IIT Kharagpur

    MSComm Control Properties

    InBufferSize : Input buffer size

    OutBufferSize : Output buffer size

    RThreshhold : Receive size forinterrupt generation

    SThreshhold : Min. transmit size

    InputLen : Number of bytes to bepicked up from the input buffer

    EOFEnable : Search for EOF character

  • 7/29/2019 A Tutorial on Robotics Part IV

    35/38

    Copyright Robotix Team, IIT Kharagpur

    MSComm Control Properties

  • 7/29/2019 A Tutorial on Robotics Part IV

    36/38

    Copyright Robotix Team, IIT Kharagpur

    MSComm Control Properties

    ParityReplace : Parity Errorreplacement character

    NullDiscard : Null characters sent tothe receive buffer or not

    RTSEnable : Request to Send enable

    DTREnable : Data Terminal Ready

  • 7/29/2019 A Tutorial on Robotics Part IV

    37/38

    Copyright Robotix Team, IIT Kharagpur

    Example Code

    Receive Data

    Private Sub CommunicationTerminal_OnComm()

    Dim InputBuffer As String

    If CommunicationTerminal.CommEvent = comEvReceive Then

    InputBuffer = CommunicationTerminal.Input

    End If

    Use InputBuffer as per requirement

    End Sub

    Transmit Data

    If CommunicationTerminal.PortOpen = True ThenCommunicationTerminal.Output = Hello

    End If

  • 7/29/2019 A Tutorial on Robotics Part IV

    38/38

    Copyright Robotix Team, IIT Kharagpur

    Thank You

    End of presentation