DOC PREVIEW
GVSU EGR 345 - Lab 6 - Position Control with an Encoder

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

9.0.1 Lab 6 - Position Control with an Encoder9.0.1.1 - Purpose9.0.1.2 - Background9.0.1.3 - Theory9.0.1.4 - Prelab9.0.1.5 - Equipment9.0.1.6 - Experimentalegr345 lab guide - 9.19.0.1 Lab 6 - Position Control with an Encoder9.0.1.1 - PurposeTo use proportional and integral gain control to position a motor using an encoder.9.0.1.2 - BackgroundRotational position is often measured with potentiometers. The devices typically are low cost and provide reasonable accuracy (typ. 1%) but they have limited ranges of rotation. Encoders are more expensive devices that allow unlimited ranges of motion. An optical encoder is shown in Figure 9.1. In this device two pairs of optical emitters and detectors are directed through a disk with openings. By counting the number of times the light beam is broken the distance of rota-tion is measured. Two light beams are used to detect the direction of rotation.Figure 9.1 An optical encoderlightemitterslightdetectorsShaft rotatesphase Aphase Begr345 lab guide - 9.29.0.1.3 - TheoryA very low resolution encoder disk is shown in Figure 9.2. The dashed line indi-cates the position where the light beams cut across the disk. As the disk rotates the beams are broken at staggered intervals. Figure 9.2 Encoder diskOptical encoders can operate at high speeds with a longer life because there is no mechanical contact. Mechanical encoders use a rotating disk with metal rings in patterns similar to those in optical encoders. As the disk rotates mechanical contacts are opened and closed. These mechanical contacts are prone to ’bounc-ing’ as they make and break contacts, and hence they do not work well for higher rotational speeds. Typically the contacts bounce time is less that 10ms. Although limited in speed, mechanical encoders are popular because they gen-erally cost less than optical encoders.This quadrature input pattern from an encoder is shown in greater detail in Figure 9.3. If we were to simply count the rising edges on one of the inputs we would be able to measure a total distance covered. However we must also use the sec-ond phase to determine the direction of motion. This method still uses one of the phases for the count. When a positive edge is encountered the counter is incremented if the other phase is true. However, if the other phase is false then sensors read acrossa single radial lineDisk rotatesegr345 lab guide - 9.3the counter is decremented. Figure 9.3 Quadrature EncodersThe previous method is simple to implement, but less accurate. A more accurate method looks at the current and previous state of both quadrature inputs. Con-sider the example in Figure 9.4 where the two phases are binary inputs. If the last input value was 00 and an updated value is 10 then the motion is clockwise, if the updated value is 01 then the motion is counterclockwise. Figure 9.4 Quadrature Encoders as binary inputsA program to read position and velocity input from an encoder is given in Figure Quad input AQuad Input Btotal displacement can be determinedQuad input AQuad Input BNote the changeas directionis reversedby adding/subtracting pulse counts(direction determines add/subtract)clockwise rotationcounterclockwise rotationQuad input AQuad Input BQuad input AQuad Input Bclockwise rotationcounterclockwise rotation01 00 10 11 01 00 10 11 01 00 10 110100101101001011 01001011egr345 lab guide - 9.49.5. The program uses pins 0 and 1 on port B as encoder inputs. In this case the program counts on both the positive and negative edges of both phases. This is done by comparing the current encoder position to the previous encoder posi-tion. When the inputs change the encoder value is either incremented or decre-mented, depending upon the preious values.Figure 9.5 Subroutines for reading position using an encoderA position control system is shown in Figure 9.6. This system uses the H-bridge from the previous laboratory to drive a motor, which in turn drives an encoder #include <avr/io.h>/* ATMEGA32 I/O register defines */int ENC_init(){ /* initialize the register once */DDRB &= ~_BV(PB0); /* set PB0 as an input */DDRB &= ~_BV(PB1); /* set PB1 as an input */}int Position = 0;void ENC_update(void){ /* interrupt driven encoder update *//* Static variables for position calculation */static unsigned char state = 0xFF;unsigned char new_state;new_state = (PINB & (_BV(PB0) | _BV(PB1))); /* Read encoder state *//* Update position value */if (state!=new_state) {switch (state) {case 0x00:if (new_state==0x01)Position++;elsePosition--;break;case 0x01:if (new_state==0x03)Position++;elsePosition--;break;case 0x03:if (new_state==0x02)Position++;elsePosition--;break;case 0x02:if (new_state==0x00)Position++;elsePosition--;break;}state = new_state;}}egr345 lab guide - 9.5used for position feedback.Figure 9.6 Position control systemThe block diagram for the control system is shown in Figure 9.7. This control sys-tem will use a desired position for the system, in terms of the encoder position. An interrupt driven subroutine will be used to implement the feedback control-ler. It will calculate the system error by subtracting the encoder counter from the desired position. This will then be passed through a proportional and inte-gral function. The result will be corrected for the deadband and output to con-trol the motor as a PWM signal. ATMega32PWMCWCCWPhase A (PB0)Phase B (PB1)H-bridge(L293D)motorencodershaft couplerCdegr345 lab guide - 9.6Figure 9.7 Position control feedback loopAll of the functions in the control system have been implemented in previous labo-ratories, except for the integration term. To integrate in a program we will need to add new values to previous values, using a known time step, as shown in Fig-ure 9.8. A subroutine to implement the proportional-integral controller is shown in Figure 9.9. The integration subroutine also includes a crude limiting function to prevent the integral value from becoming excessively large.Figure 9.8 Numerical integration+-motor++proportionalintegralKiCe∫()KpCe()encoderPWM/L293Ddead-bandwhere,pulsecounterCwCdRTIICeCaVsθCfCffeedback position (int -32768 to 32767)=Cddesired position(int -32768 to 32767)=Cesystem error (int -32768 to 32767)=KiKp, controller integral and proportional gain constants=Cwwanted output (int -32768 to 32767)=Caactual PWM output (unsigned char 0 to 255)=et()td∫Te t() et T–()td∫+≈where,T the time period (4ms in our system)=et() feedback error=egr345 lab guide - 9.7Figure 9.9 Proportional integral controllerPlease


View Full Document

GVSU EGR 345 - Lab 6 - Position Control with an Encoder

Documents in this Course
Y Axis

Y Axis

2 pages

Load more
Download Lab 6 - Position Control with an Encoder
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab 6 - Position Control with an Encoder and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab 6 - Position Control with an Encoder 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?