Hardware Requirements: Machine Vision Using Labview
Hardware Requirements: Machine Vision Using Labview
Hardware Requirements: Machine Vision Using Labview
CHAPTER 3
HARDWARE REQUIREMENTS
Page 1
Machine Vision using LabVIEW Meeting the computing needs of the task efficiently and cost effectively. Speed, the amount of ROM and RAM, the number of I/O ports and timers, size, packaging, power consumption. Cost per unit. Availability of software development tools assemblers, debuggers, C compilers, emulator, simulator, technical support. Wide availability and reliable sources of the microcontrollers.
8051 4K 128 2 32 1 6 8K 256 3 32 1 8 8052 10K 128 2 32 1 6 8031
Features ROM
RAM Timers I/O PINS Serial Port Interrupt Sources
3.1.5 Features
Compatible with MCS-51 Products 4K Bytes of In-System Reprogrammable Flash Memory Endurance: 1,000 Write/Erase Cycles Fully Static Operation: 0 Hz to 24 MHz Three-level Program Memory Lock 128 x 8-bit Internal RAM 32 Programmable I/O Lines Two 16-bit Timer/Counters Six Interrupt Sources Programmable Serial Channel Low-power Idle and Power-down Modes
3.1.6. Architecture
8051 is based on CISC architecture. It is based on Harvard architecture. So, it has separate program and data memory
Page 3
The 8051 is a 40 pin device, but out of these 40 pins, 32 are used for I/O. 24 of these are dual purpose, i.e. they can operate as I/O or a control line or as part of address or date bus.
Page 4
provided as an immediate value. These various ways of accessing data are called addressing modes. There are five addressing modes: 1. Immediate 2. Register 3. Direct 4. Register indirect 5. Indexed
Page 5
3.1.8 Timers/Counters
The 8051 has 2 timers/counters: Timer/Counter 0 Timer/Counter 1 They can be used as 1. The Timer : used as a time delay generator. The clock source is the internal crystal frequency of the 8051. 2. An event counter. External input from input pins to count the number of events on registers. These clock pulses cold represent the number of people passing through an entrance, or the number of wheel rotations, or any other event that can be converted to pulses.
Machine Vision using LabVIEW 8051 has two 16-bit Timer registers, Timer 0 & Timer 1, TH0, TL0, TH1, TL1. As 8051 has 8-bit architecture , each Timer register is treated as two 8-bit registers namely One 8-bit mode register -TMOD. One 8-bit control register-TCON. TMOD Register
Fig 3.4 TMOD Register Both Timer 0 &Timer 1 use the same Mode register TMOD. It is an-8-bit register .The lower 4-bits are meant for Timer 0 &the upper 4-bits are meant for Timer 1. It is not bit addressable. It is used similar to any other register of 8051. For ex: MOV TMOD, #21H GATE=0 Internal control The start and stop of the timer are controlled by way of software.
C/T: Timer or counter selected cleared for timer operation (input from internal system clock). Set for counter operation (input from Tx input pin). M1, M0: Used for mode selection. Because the Timers of 8051 can be set in 4-different modes.
M1 0 0 1
M0 0 1 0
Mode 0 1 2
Operation 13-bit timer mode 8-bit THx + 5-bit TLx (x= 0 or 1) 16-bit timer mode 8-bit THx + 8-bit TLx 8-bit auto reload 8-bit auto reload timer/counter;
THx hold a value which is to be reloaded into TLx
Page 7
TCON Register
Fig 3.5 TCON Register Timer control register TMOD is a 8-bit register which is bit addressable and in which Upper nibble is for timer/counter, lower nibble is for interrupts. TR (Timer run control bit) TR0 for Timer/counter 0; TR1 for Timer/counter 1. TR is set by programmer to turn timer/counter on/off. TR=0 : off (stop) TR=1 : on (start)
TF (timer flag, control flag) TF0 for timer/counter 0; TF1 for timer/counter 1. TF is like a carry. Originally, TF=0. When TH-TL roll over to 0000 from FFFFH, the TF is set to 1. TF=0 : not reach TF=1: reach If we enable interrupt, TF=1 will trigger ISR.
3.2 CAMERA
Page 8
Page 9
3.3 DC MOTOR
Direct current (DC) motors are widely used to generate motion in a variety of products. Permanent magnet DC (direct current) motors are enjoying increasing popularity in applications requiring compact size, high torque, high efficiency, and low power consumption.
The direct current (DC) motor is one of the first machines devised to convert electrical power into mechanical power. Permanent magnet (PM) direct current convert electrical energy into mechanical energy through the interaction of two magnetic fields. One field is produced by a permanent magnet assembly, the other field is produced by an electrical current flowing in the motor windings. These two fields result in a torque which tends to rotate the rotor. As the rotor turns, the current in the windings is commutated to produce a continuous torque output. The stationary electromagnetic field of the motor can also be wirewound like the armature (called a wound-field motor) or can be made up of permanent magnets (called a permanent magnet motor). In either style (wound-field or permanent magnet) the commutator. acts as half of a mechanical switch and rotates with the armature as it turns. The commutator is composed of conductive segments (called bars), usually made of copper, which represent the termination of individual coils of wire distributed around the armature. The second half of the mechanical switch is completed by the brushes. These brushes typically remain stationary with the motor's housing but ride (or brush) on the rotating commutator. As electrical energy is passed through the brushes and consequently through the armature a tensional force is generated as a reaction between the motor's field and the armature causing the motor's armature to turn. As the armature turns, the brushes switch to adjacent bars on the commutator. This switching action transfers the electrical energy to an adjacent winding on the armature which in turn perpetuates the tensional motion of the armature. Dept. of ECE, MVJCE Bangalore. Page 10
Machine Vision using LabVIEW Permanent magnet (PM) motors are probably the most commonly used DC motors, but there are also some other type of DC motors(types which use coils to make the permanent magnetic field also) .DC motors operate from a direct current power source. Movement of the magnetic field is achieved by switching current between coils within the motor. This action is called "commutation". Very many DC motors (brush-type) have built-in commutation, meaning that as the motor rotates, mechanical brushes automatically commutate coils on the rotor. You can use dc-brush motors in a variety of applications. A simple, permanent-magnet dc motor is an essential element in a variety of products, such as toys, servo mechanisms, valve actuators, robots, and automotive electronics. There are several typical advantages of a PM motor. When compared to AC or wound field DC motors, PM motors are usually physically smaller in overall size and lighter for a given power rating. Furthermore, since the motor's field, created by the permanent magnet, is constant, the relationship between torque and speed is very linear. A PM motor can provide relatively high torque at low speeds and PM field provides some inherent self-braking when power to the motor is shutoff. There are several disadvantages through, those being mostly being high current during a stall condition and during instantaneous reversal. Those can damage some motors or be problematic to control circuitry. Furthermore, some magnet materials can be damaged when subjected to excessive heat and some loose field strength if the motor is disassembled. .
High-volume everyday items, such as hand drills and kitchen appliances, use a dc servomotor known as a universal motor. Those universal motors are series-wound DC motors, where the stationary and rotating coils are wires in series. Those motors can work well on both AC and DC power. One of the drawbacks/precautions about series-wound DC motors is that if they are unloaded, the only thing limiting their speed is the wind age and friction losses. Some can literally tear themselves apart if run unloaded. A brushless motor operates much in the same way as a traditional brush motor. However, as the name implies there are no brushes (and no commutator). The mechanical switching function, implemented by the brush and commutator combination in a brush-type motor, is replaced by electronic switching in a brushless motor. In a typical brushless motor the electromagnetic field, created by permanent magnets, is the rotating member of the motor and is called a rotor. The rotating magnetic field is generated with a number of electromagnets commutatated with electronics switches (typically transistors or FETs) in a right order at right speed. In a brushless motor, the trick becomes to know when to switch the electrical energy in the windings to perpetuate the rotating motion. This is typically accomplished in a brushless-type motor by some feedback means designed to provide an indication of the position of the magnet poles on the rotor relative to the windings. A hall effect device (HED) is a commonly used means for providing this positional feedback. In some applications brushless motors are commutated without sensors or with the use of an encoder for positional feedback. A brushless motor is often used when high reliability, long life and high speeds are required. The bearings in a brushless motor usually become the only parts to wear out. In applications where Dept. of ECE, MVJCE Bangalore. Page 11
Machine Vision using LabVIEW high speeds are required (usually above 30,000 RPM) a brushless motor is considered a better choice (because as motor speed increases so does the wear of the brushes on traditional motors). A brushless motor's commutation control can easily be separated and integrated into other required electronics, thereby improving the effective power-to-weight and/or power-to-volume ratio. A brushless motor package (motor and commutation controller) will usually cost more than a brush-type, yet the cost can often be made up in other advantages. For example, in applications where sophisticated control of the motor's operation is required. Brushless motors are seen nowadays in very much computer application, they for example rotate normal PC fans, hard disks and disk drives. Sometimes the rotation direction needs to be changed. In normal permanent magnet motors, this rotation is changed by changing the polarity of operating power (for example by switching from negative power supply to positive or by inter-changing the power terminals going to power supply). This direction changing is typically implemented using relay or a circuit called an H bridge. There are some typical characteristics on "brush-type" DC motors. When a DC motor is straight to a battery (with no controller), it draws a large surge current when connected up. The surge is caused because the motor, when it is turning, acts as a generator. The generated voltage is directly proportional to the speed of the motor. The current through the motor is controlled by the difference between the battery voltage and the motor's generated voltage (otherwise called back EMF). When the motor is first connected up to the battery (with no motor speed controller) there is no back EMF. So the current is controlled only by the battery voltage, motor resistance (and inductance) and the battery leads. Without any back emf the motor, before it starts to turn, therefore draws the large surge current. When a motor speed controller is used, it varies the voltage fed to the motor. Initially, at zero speed, the controller will feed no voltage to the motor, so no current flows. As the motor speed controller's output voltage increases, the motor will start to turn. At first the voltage fed to the motor is small, so the current is also small, and as the motor speed controller's voltage rises, so too does the motor's back EMF. The result is that the initial current surge is removed, acceleration is smooth and fully under control.
Motor speed control of DC motor is nothing new. A simplest method to control the rotation speed of a DC motor is to control it's driving voltage. The higher the voltage is, the higher speed the motor tries to reach. In many applications a simple voltage regulation would cause lots of power loss on control circuit, so a pulse width modulation method (PWM)is used in many DC motor controlling applications. In the basic Pulse Width Modulation (PWM) method, the operating power to the motors is turned on and off to modulate the current to the motor. The ratio of "on" time to "off" time is what determines the speed of the motor. When doing PWM controlling, keep in mind that a motor is a low pass device. The reason is that a motor is mainly a large inductor. It is not capable of passing high frequency energy, and hence will not perform well using Dept. of ECE, MVJCE Bangalore. Page 12
Machine Vision using LabVIEW high frequencies. Reasonably low frequencies are required, and then PWM techniques will work. Lower frequencies are generally better than higher frequencies, but PWM stops being effective at too low a frequency. The idea that a lower frequency PWM works better simply reflects that the "on" cycle needs to be pretty wide before the motor will draw any current (because of motor inductance). A higher PWM frequency will work fine if you hang a large capacitor across the motor or short the motor out on the "off" cycle (e.g. power/brake pwm) The reason for this is that short pulses will not allow much current to flow before being cut off. Then the current that did flow is dissipated as an inductive kick - probably as heat through the flyback diodes. The capacitor integrates the pulse and provides a longer, but lower, current flow through the motor after the driver is cut off. There is not inductive kick either, since the current flow isn't being cut off. Knowing the low pass roll-off frequency of the motor helps to determine an optimum frequency for operating PWM. Try testing your motor with a square duty cycle using a variable frequency, and then observe the drop in torque as the frequency is increased. This technique can help determine the roll off point as far as power efficiency is concer Besides "brush-type" DC motors, there is another DC motor type: brushless DC motor. Brushless DC motors rely on the external power drive to perform the commutation of stationary copper winding on the stator. This changing stator field makes the permanent magner rotor to rotate.A brushless permanent magnet motor is the highest performing motor in terms of torque / vs. weight or efficiency. Brushless motors are usually the most expensive type of motor. Electronically commutated, brush-less DC motor systems are widely used as drives for blowers and fans used in electronics, telecommunications and industrial equipment applications. There is wide variety of different brush-less motors for various applications. Some are designed to to rotate at constant speed (those used in disk drives) and the speed of some can be controlled by varying the voltage applied to them (usually the motors used in fans). Some brushless DC motors have a built-in tachometer which gives out pulses as the motor rotates (this applies to both disk drive motors and some computer fans). In general, users select brush-type DC motors when low system cost is a priority, and brushless motors to fulfil other requirements (such as maintenance-free operation, high speeds, and explosive environments where sparking could be hazardous). Brush type DC motors are used in very many battery powered appliances. Brushless DC motors are commonly used in applications like DC powered fans and disk drive rotation motors.
Machine Vision using LabVIEW (Fig1)When the coil of an SPDT relay (Fig 1) is at rest (not energized), the common terminal and the normally closed terminal have continuity. When the coil is energized, the common terminal and the normally open terminal have continuity. The diagram below center (Fig2) shows an SPDT relay at rest, with the coil not energized. The diagram below right (Fig3) shows the relay with the coil energized. The coil is an electromagnet that causes the arm that is always connected to the common to pivot when energized whereby contact is broken from the normally closed terminal and made with the normally open terminal. When energizing the coil of a relay, polarity of the coil does not matter unless there is a diode across the coil. If a diode is not present, attach positive voltage to either terminal of the coil and negative voltage to the other, otherwise you must connect positive to the side of the coil that the cathode side (side with stripe) of the diode is connected and negative to side of the coil that the anode side of the diode of the diode is connected.
3.4.2 Features
92/8 gold silver alloy on silver palladium contact type is suitable for low level switching application. Small size and light weight can provide high density P.C. Board mounting. 2.54gmm Terminal Pitch. Low Coil Power Consumption of GS-T Type and high Coil Power Consumption of GS-D type are available to meet users selection. Employment of suitable plastic materials to be applied to high temperature and various chemical solutions. Plastic epoxy resin sealed type for washing procedure. Dept. of ECE, MVJCE Bangalore. Page 14
3.4.3 Application of SPDT Relays Telecommunication Domestic appliances Office machines Audio equipments Remote control
3.4.2 Features
LM78L05 in micro SMD package Output voltage tolerances of 5% over the temperature range Output current of 100mA Internal thermal overload protection Output transistor safe area protection Dept. of ECE, MVJCE Bangalore. Page 15
Machine Vision using LabVIEW Internal short circuit current limit Available in plastic TO-92 and plastic SO-8 low profile packages No external components Output voltages of 5.0V, 6.2V, 8.2V, 9.0V, 12V, 15V
Page 16
Machine Vision using LabVIEW Leather Industry Manufacturing Units Voltage regulators are also used in Service Industries like: Hospitals Nursing Homes Hotels Educational & Medical Institutes Commercial Complexes
3.7 RS232
3.7.1 Introduction to RS232 Serial Communication
Serial communication is basically the transmission or reception of data one bit at a time. Today's computers generally address data in bytes or some multiple thereof. A byte contains 8 bits. A bit is basically either a logical 1 or zero. Every character on this page is actually expressed internally as one byte. The serial port is used to convert each byte to a stream of ones and zeroes as well as to convert a stream of ones and zeroes to bytes. The serial port contains a electronic chip called a Universal Asynchronous Receiver/Transmitter (UART) that actually does the conversion. The serial port has many pins. We will discuss the transmit and receive pin first. Electrically speaking, whenever the serial port sends a logical one (1) a negative voltage is effected on the transmit pin. Whenever the serial port sends a logical zero (0) a positive voltage is effected. When no data is being sent, the serial port's transmit pin's voltage is negative (1) and is said to be in a MARK state. Note that the serial port can also be forced to keep the transmit pin at a positive voltage (0) and is said to be the SPACE or BREAK state. (The terms MARK and SPACE are also used to simply denote a negative voltage (1) or a positive voltage (0) at the transmit pin respectively). When transmitting a byte, the UART (serial port) first sends a START BIT which is a positive voltage (0), followed by the data (general 8 bits, but could be 5, 6, 7, or 8 bits) followed by one or two STOP BITs which is a negative(1) voltage. The sequence is repeated for each byte sent. Figure 3.15 shows a diagram of byte transmission . Dept. of ECE, MVJCE Bangalore. Page 18
At this point you may want to know what the duration of a bit is. In other words, how long does the signal stay in a particular state to define a bit. The answer is simple. It is dependent on the baud rate. The baud rate is the number of times the signal can switch states in one second. Therefore, if the line is operating at 9600 baud, the line can switch states 9,600 times per second. This means each bit has the duration of 1/9600 of a second or about 100 sec. When transmitting a character there are other characteristics other than the baud rate that must be known or that must be setup. These characteristics define the entire interpretation of the data stream. The first characteristic is the length of the byte that will be transmitted. This length in general can be anywhere from 5 to 8 bits. The second characteristic is parity. The parity characteristic can be even, odd, mark, space, or none. If even parity, then the last data bit transmitted will be a logical 1 if the data transmitted had an even amount of 0 bits. If odd parity, then the last data bit transmitted will be a logical 1 if the data transmitted had an odd amount of 0 bits. If MARK parity, then the last transmitted data bit will always be a logical 1. If SPACE parity, then the last transmitted data bit will always be a logical 0. If no parity then there is no parity bit transmitted. The third characteristic is the amount of stop bits. This value in general is 1 or 2. Assume we want to send the letter 'A' over the serial port. The binary representation of the letter 'A' is 01000001. Remembering that bits are transmitted from least significant bit (LSB) to most significant bit (MSB), the bit stream transmitted would be as follows for the line characteristics 8 bits, no parity, 1 stop bit, 9600 baud. LSB (0 1 0 0 0 0 0 1 0 1) MSB The above represents (Start Bit) (Data Bits) (Stop Bit) To calculate the actual byte transfer rate simply divide the baud rate by the number of bits that must be transferred for each byte of data. In the case of the above example, each character requires 10 bits to be transmitted for each character. As such, at 9600 baud, up to 960 bytes can be transferred in one second. The above discussion was concerned with the "electrical/logical" characteristics of the data stream. Dept. of ECE, MVJCE Bangalore. Page 19
Machine Vision using LabVIEW Serial communication can be half duplex or full duplex. Full duplex communication means that a device can receive and transmit data at the same time. Half duplex means that the device cannot send and receive at the same time. It can do them both, but not at the same time. Half duplex communication is all but outdated except for a very small focused set of applications.
These signals are the Carrier Detect Signal (CD), asserted by modems to signal a successful connection to another modem, Ring Indicator (RI), asserted by modems to signal the phone ringing, Data Set Ready (DSR), asserted by modems to show their presence, Clear To Send (CTS), asserted by modems if they can receive data, Data Terminal Ready (DTR), asserted by terminals to show their presence, Request To Send (RTS), asserted by terminals if they can receive data. The section RS232 Cabling describes these signals and how they are connected. Note that hardware flow control requires the use of additional wires. The benefit to this however is crisp and reliable flow control. Another method of flow control used is known as software flow control. This method requires a simple 3 wire serial communication link, transmit data, receive data, and signal ground. If using this method, when a device can no longer receive, it will transmit a character that the two devices agreed on. This character is known as the XOFF character. This character is generally a hexadecimal 13. When a device can receive again it transmits an XON character that both devices agreed to. This character is generally a hexadecimal 11.
Page 20
Machine Vision using LabVIEW implemented in the null modem connection, communication is only possible at speeds at which it is sure the receiving side can handle the amount information even under worst case conditions.
Page 21
2 3 5
3 2 5
Rx Tx Signal Ground
Tx Rx
Compatibility Issues
If you read about null modems, this three wire null modem cable is often talked about. There is a problem, if either of the two devices checks the DSR or CD inputs. These signals normally define the ability of the other side to communicate. As they are not connected, their signal level will never go high. This might cause a problem. The same holds for the RTS/CTS handshaking sequence. If the software on both sides is well structured, the RTS output is set high and then a waiting cycle is started until a ready signal is received on the CTS line. This causes the software to hang because no physical connection is present to either CTS line to make this possible. The only type of communication which is allowed on such a null modem line is data-only traffic on the cross connected Rx/Tx lines. This does however not mean that this null modem cable is useless. Communication links like present in the Norton Commander program can use this null modem cable. This null modem cable can also be used when communicating with devices which do not have modem control signals like electronic measuring equipment etc. As you can imagine, with this simple null modem cable no hardware flow control can be implemented. The only way to perform flow control is with software flow control using the XOFF and XON characters.
Page 22
Fig 3.17 DB-9 Pin Male and Female Connectors The DB9 connector is mainly used for serial connections, allowing for the asynchronous transmission of data as provided for by standard RS-232.There are DB9-DB25 adapters for easily converting a DB9 plug into a DB25, and vice versa. Pin No. 1 2 3 4 5 6 7 8 9 NAME CD - Carrier Detect RXD - Receive Data TXD - Transmit Data DTR - Data Terminal Ready GND - Signal Ground DSR - Data Set Ready RTS - Request To Send CTS - Clear To Send RI - Ring Indicator Shield
Machine Vision using LabVIEW generator functions are available as cells in the Texas Instruments LinASIC library.
3.10.2 Features
Meet or Exceed TIA/EIA-232-F and ITU Recommendation V.28 Operate With Single 5-V Power Supply Operate Up to 120 kbit/s Two Drivers and Two Receivers Low Supply Current . . . 8 mA Typical Designed to be Interchangeable With Maxim MAX232 ESD Protection Exceeds JESD 22 2000-V Human-Body Model (A114-A)
3.10.3 Applications
o TIA/EIA-232-F,Battery-Powered Systems, Terminals, Modems, Computers
OUTPUT TOUT
H L
Page 24
INPUT RIN
L H
OUTPUT ROUT
H L
12 R1OUT 9 R2OUT 8 R2IN Fig 3.21: Logic Diagram of MAX 232 RIN
Page 25
Page 26