sensing.pdf

Upload: ratna-kommoji

Post on 02-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 sensing.pdf

    1/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    Paper 143.478Paper 143.478

    MechatronicsMechatronics

    Sensors, Interfacing & Software DriverSensors, Interfacing & Software Driver

    Dr. Peter XuDr. Peter Xu

    Senior LecturerSenior LecturerInstitute of Technology & EngineeringInstitute of Technology & Engineering

    Massey UniversityMassey University

  • 7/27/2019 sensing.pdf

    2/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    ! Introduction - Sensing, Interfacing and Programming

    !

    Photoresistor! IR Proximity Sensor

    ! Pyroelectric Sensor

    !

    Ultrasonic Ranging Sensor! Shaft Encoders

    ! Microswitch

    Sensors, Interfacing and SoftwareSensors, Interfacing and SoftwareDriverDriver

  • 7/27/2019 sensing.pdf

    3/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    ! Interface Between Sensors and Micro

    Sensor-interface electronics

    Sensor-driver routines

    ! Software Drivers

    Once a set of sensors has been selected and the properinterface circuitry has been designed to connect your sensorsto a microprocessor, the microprocessor has to be

    programmed to read the sensors. These pieces of code areoften written in assembly language and are known assoftware drivers.

    Software drivers provide a well-defined interface between ahardware device (intelligent machine) and a program that

    needs to use the device. Software drivers deal with the hardware-software interface

  • 7/27/2019 sensing.pdf

    4/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    RS 276-1657 Photoresistor and Interfacing to a MC6811

  • 7/27/2019 sensing.pdf

    5/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    Total resistance: RT=R+R

    LCurrent : I=V/RTThe voltage on PE1: VPE1=I RL => VRL/(R+RL)

    MC6811 8-bit A/D converter maps the variable voltage, VPE1, into

    the range 0 to 255.

    A good compromise between sensitivity and range will be achievedif the resistance R is set to the same value as the resistance exhibited

    by the photoresistor when exposed to the light level in the middle ofthe range of light level in which the machine must operate.

    Photoresistors

    I. Principle and Interfacing

  • 7/27/2019 sensing.pdf

    6/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    II. Software Driver

    MC6811 port E

    - 8-bit input port or 8-channel analog-to-digital converter.

    - Internally only A/D circuit for entire port, only four registers tostore results from the eight channels.- Voltage reference pins VRH, VRL- Two control registers ADCTL, OPTION, are used to configurethe mode of conversion.

    Conversion sequences can be chosen that repeat on a single channelfor four times or on four channels, once each. For later mode, twobanks of four PE0-PE3 and PE4-PE7. Conversions are complete 34-clock cycles after the ADCTL register is written. After each conversion,results are posted in registers ADR1, ADR2, ADR3, ADR4.

  • 7/27/2019 sensing.pdf

    7/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    Configuring ADCTL

    When SCAN=0, four conversions are performed, once eachWhen SCAN=1, conversions continue in a round-robin fashion.When MULT=0, four conversions are repeated on a single

    channel. The selected channel is set by the lower four bits ofADCTL.When MULT=1, one bank of four channels is converted.(if bits 2 and 3 are set 0, channels PE0-PE3 are converted. If bits 2 and 3are set 1, channels PE4-PE7 are converted.)

  • 7/27/2019 sensing.pdf

    8/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    Assembly Code

    ph-right equ $10ph-left equ $11option equ $1039adctl equ $1030adr1 equ $1031adr2 equ $1032

    update-photobset option #%10000000

    bset adctl #%00010000check-result

    brclr adctl #%10000000 check-resultldaa adr1staa ph-rightldaa adr2

    staa ph-leftrts

  • 7/27/2019 sensing.pdf

    9/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    C Code

    int ph_right=0;int ph_left=0;

    void update_photo(){

    poke(option, 0b10000000);

    poke(adctl, 0b00010000);while ( (peek(adctl) & 0b10000000)==0){}ph_left=peek(adr1);ph_right=peek(adr2);}

  • 7/27/2019 sensing.pdf

    10/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    - The sensor uses an infrared LED and infrared phototransistor.

    - Near-infrared proximity detectors are often called IRs for short.- They are sensitive in the range just below visible light (around 880nm wavelength)- The output of the transistor interfaced to a control circuit producing

    a go/no-go output.- Sensitivity can be adjusted by changing the value of R2; reducethe value to increase sensitivity.

    Near-Infrared Proximity Detectors

    I. Principle and Interfacing

  • 7/27/2019 sensing.pdf

    11/43

  • 7/27/2019 sensing.pdf

    12/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    13/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    Sharp G1U52X IR Proximity Detector

  • 7/27/2019 sensing.pdf

    14/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    15/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    Hamamatsu S3599 IR Proximity Detector

  • 7/27/2019 sensing.pdf

    16/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    - The detector responds to a carrier frequency of 40 kHz. Afrequency 40 kHz means the LED is blinked on and off with aperiod of 25 us. This signal is then modulated at a lowerfrequency so that the blinking is on for 600us and then off for600us.

    - The LEDs blink only when pins PD2 and PD3 of port D areasserted, which can be done by writing a program.- The detector is a digital signal, either 0 or 5V. Pin PE4 ofMC6811 can be used in the normal digital input mode. The A/Dconverter capacity is not necessary here.

  • 7/27/2019 sensing.pdf

    17/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    C Code

    int ir_status=0;

    void ir_detect(){ int val_off, val_on;

    bit_set(port_D,0b00000100);sleep(0.000600);

    val_on=peek(port_E);bit_clear(port_D,0b00000100);sleep(0.000600);val_off=peek(port_E);if ((val_off & ~val_on & 0b00000100 ==0b00000100)

    ir_status=1;

    elseir_status=0;

    }

    II. Software Driver

  • 7/27/2019 sensing.pdf

    18/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    Pyroelectric Sensors

    I. Principle and Interfacing

    - Essential component in certain types of motion detecting burglaralarms. A lithium tantalate crystal.

    - The output changes when small changes in the temperature of thesensor occur over time.- Charge is induced as the crystal is heated. Detect radiation in the 8-10um range (the range of infrared energy emitted by humans).

    - The Eltec 442-3 sensor incorporates two lithium tantalate crystals.The amplified difference of the voltage across the crystals is the outputof the sensor. In the case that both crystals are at the sametemperature, the sensor produces an output signal that remains steadyat about 2.5V (assuming a 5 V power supply). If a person walks in

    front of the sensor moving from left to right, the signal will arise above2.5V by about one volt and then fall below it, finally returning to thesteady-state value. Should a person walk in front of the sensor mvoingfrom right to left, the reverse will happen.

  • 7/27/2019 sensing.pdf

    19/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    20/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    21/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    22/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    23/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    II. Software Driver

    - By taking advantage of the MC6811s A/D port, we can implement theinterface with a minimum of components. The same software driver used

    before can gather pyroelectric data.

    - A program to notice when the readings go above or below a preset thresholdcan trigger some machine behavior. More sophisticated software could look fortrends and try to determine which way the person is moving and attempt to

    follow.

  • 7/27/2019 sensing.pdf

    24/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    Microswitches

  • 7/27/2019 sensing.pdf

    25/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    Path Following Using Infrared Sensors

  • 7/27/2019 sensing.pdf

    26/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    27/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    28/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    29/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    30/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    31/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    Ultrasonic Ranging Sensors

    I. Principle and Interfacing

    - A sonar transducer can provide distance information. It measures

    the time of flight between the initiation of a ping and the return of itsecho.

    - Polaroid 6500 ranging module

    The ranging board begins by sending a brief 400 volt signal to thetransducer, creating an ultrasonic chirp. After transmitting the chirp,the ranging board monitors the transducer for a returning echo.When an echo is detected, the range boards asserts (sets to high)

    its output line. By measuring the time between initiation of the chirpand return of the echo, the microprocessor determines the distanceto the object responsible for the echo.

  • 7/27/2019 sensing.pdf

    32/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    33/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    34/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    - MC6811 Interfacing

    Two input capture registers to record the time when the sonar pingbegins its flight and the time when the echo is detected.The input lines PA1 and PA2 are associated with the timer.PD2 and PD3 used to control its infrared emitters. Using the logicalAND (HC08 chip) of signals from PD2 and PD3 to initiate a sonarping.

    When PD2 and PD3 are asserted, INIT and PA2 are forced high,the former initiates a sonar ping. Upon detection of a returning echo,the ranging board asserts Echo, driving PA1 high.

    The gate AND acts as a buffer to drive the LED, when Echo goeshigh, the LED lights, giving a visual indication that an echo has beendetected.

  • 7/27/2019 sensing.pdf

    35/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    II. Software Driver

    /* Enable input capture on rising edge on lines PA1 and PA2void init_sonar(){ bit_set(tctl2, 0b010100);

    bit_clear(tctl2,0b101000);}

    /* Initiate a sonar ping */void ping(){ poke(tflg1,0b10);

    bit_set(portd,0b001100);sleep(0.030);

    bit_clear(portd,0b001100);}

    /*Determine if an echo was received, if so compute the range */float range(){ if ( (peek(tflg1) & 0b10)==0)

    return -1.0;else

    return((float) ((peekword(tic2)-peeword(tic1)) >>1 0*0.000569);

    }

  • 7/27/2019 sensing.pdf

    36/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    Shaft Encoders

    I. Principle & Interfacing

    The disk attaches to the motor shaft and spins with it. A near-infrared LED is placed on one side of the disks slots and a

    phototransistor on the other.

    As the disk spins, the light passing through the disk is interruptedby the moving slots, and a signal in the form of a pulse train isproduced at the output of the phototransistor. By using amicroprocessor to count these pulses, the robot can tell how far itswheels have rotated.

    The interface between shaft encoders and MC6811 port A pins PA7and PA0. Shaft encoder data from the left wheel are counted by thepulse accumulator hardware associated with PA7. For the rightwheel, interrupts are triggered by the input capture hardwarre (IC3)connected to PA0. Shaft-encoder pulses are counted in software inan interrup-handler routine.

  • 7/27/2019 sensing.pdf

    37/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    38/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

  • 7/27/2019 sensing.pdf

    39/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    8-bit counter register (pulse accumulator)

    pulse accumulator control register

  • 7/27/2019 sensing.pdf

    40/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    TFLG1 register

    TMSK1 register

    TCTL2 register

  • 7/27/2019 sensing.pdf

    41/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    III. Shaft-Encoder Input Capture Software Driver

    TFLG1 EQU $1023ORG MAIN_START

    subroutine_initialize_moduleldd #IC3_interrupt_handlerstd $FFEAclirts

    variable_right_clicksfdb 0

    IC3_interrupt_handlerldd variable_right_clicks

    addd #1std variable_right_clicksldaa #%00000001staa TFLG1rti

    Interrupt-Handler Routine for IC3

  • 7/27/2019 sensing.pdf

    42/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    int TCTL2= 0x1021;int TMSK1=0x1022;int TFLG1=0x1023;int PACTL=0x1026;

    int PACNT=0x1027;

    void init_velocity(){ poke(PACTL, 0b01010000);

    poke(PANCT,0);bit_clear(TCTL2, 0b00000010);

    bit_set(TCTL2, 0b00000001);bit_set(TMSK1, 0b00000001); }

    float get_left_vel(){ float vel;

    vel = (float) peek(PACNT);poke(PACNT,0);return (vel); }

    Supervising Program

    float get_right_vel(){ float vel;

    vel = (float) right_clicks;right_clicks=0;return (vel); }

  • 7/27/2019 sensing.pdf

    43/43

    Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand

    II. Shaft-Encoder Pulse-Accumulator Software Driver

    int PACTL=0x1026;int PACNT=0x1027;

    void init_velocity()

    { poke(PACTK, 0b01010000);poke(PACNT, 0);

    }

    float get_left_vel()

    { float vel;vel=(float) peek(PACNT);poke(PACNT,0);return(vel);

    }