The labs are to be conducted in a professional manner. The steps you are expected to follow are listed below. In essence the calculations and design work are to be completed before the laboratory. When you arrive at the laboratory you will be expected to build lab equipment, conduct tests and collect data to verify the system performance. After the lab you will compare the theoretical and experimental data.
If any of the required components in a laboratory experiment is missing, 50% of the final grade will be automatically deducted. If two or more required sections are missing, the lab will not be graded and returned with a grade of zero.
2.1.1 Before the Lab[an error occurred while processing this directive]
- Students are expected to write a planned procedure to be followed during the lab. When there are questions about the work to be done during the lab, reasonable assumptions should be made. This will require you to read and understand the ’Experiment’ section of the experiment.
2.1.2 During the Lab[an error occurred while processing this directive]
- Have the prelab work in the lab book checked and signed at the beginning of the lab. If work has not been done before the lab marks will be deducted accordingly. However, the pre-lab work must still be completed. Failure to do so may result in a grade of zero for the lab.
2.1.3 After the Lab[an error occurred while processing this directive]
2.1.4 Notebooks[an error occurred while processing this directive]
3.0.1 Lab 1 - Programming the Atmel Atmega32 Thumb Board[an error occurred while processing this directive]
A method for generating variable analog outputs, called Pulse Width Modulation (PWM), is shown in Figure 3.1 Pulse Width Modulation (PWM). If the output is on all the time, the effective output voltage is the maximum voltage of the output. If the output is only on half the time, the effective output voltage is only half. By varying the ratio of on-time to off-time, the effective voltage is varied. The percentage of time that the signal is on is called the duty cycle. So, if the voltage is only on half the time, the effective voltage is half the maximum voltage, and the duty cycle is 50%. This method is popular because it can produce a variable effective voltage efficiently. (Aside: The frequency of these waves is normally above 20KHz, above the range of human hearing.)
An analog to digital (A/D or ADC) converter converts an analog input voltage to a digital value. A successive approximation A/D converter is shown in Figure 3.2 Analog to digital converter. This device is like the one in the AtMega. The main operation concept is based on the successive approximation logic. Once the reset is toggled the converter will start by setting the most significant bit of the 8 bit number. This will be converted to a voltage Ve that is a function of the +/-Vref values. The value of Ve is compared to Vin and a simple logic check determines which is larger. If the value of Ve is larger the bit is turned off. The logic then repeats similar steps from the most to least significant bits. Once the last bit has been set on/off and checked the conversion will be complete, and a done bit can be set to indicate a valid conversion value.
In the ATMega 32, the A/D converter is 10 bit, and there are up to eight 0-5V inputs available on port A. To operate the A/D converter the following steps must be used. Once the analog input value has been read it can be converted back into a voltage using equation (2).
Microcontrollers are often used in real-time applications. Real-time systems must respond to events with time constraints. In other words they must always respond to inputs and cannot ’go to sleep’ as normal desktop computers do. To achieve this responsiveness interrupts are used. An interrupt can be generated by an external event, such as input change, or by an internal timer. When an interrupt occurs the computer will stop whatever it is doing and store its current state. It then runs a designated interrupt subroutine. The interrupt subroutine should run briefly and then allow the computer to restore its previous state and return to normal operations. In a realtime controller the interrupt routine typically runs 100 to 1000 times per second to check motor positions and update outputs to control the motors.
Serial communication typically involves sending bytes between devices. These bytes are often ASCII encoded characters. Multiple bytes make up a string. For our purposes we will use serial communication to send commands to the microcontrollers, and to get responses (including data) back. Serial communications can be done multiple ways. The simplest method will be over the USB port, using a virtual serial port under windows. We may then use a program such as Hyperterminal to interact with the microcontroller.
Communications may also occur without wires. Many wireless communication standards are already in use, however the boards we are using include hardware for a new wireless networking method called Zigbee. This is meant for consumer products with low power consumption and slower data rates. One interesting difference between simple communication and networking is that there may be multiple clients able to talk at one time. And, each client on the network will have a unique identifier, known as a network address. For Zigbee this will be a value between 0 and 255.
1. Boot your PC and login to the network. (Note: don’t forget to use a browser first to login to the campus network first.) Plug the board into a USB port. At this point windows (XP) should recognize that new hardware has been inserted and look for a driver. If not already installed you will need to do the following --> A message "Welcome to the Found New Hardware Wizard" should appear. For the prompt "Can Windows Connect to Windows Update to search for software?" use "Yes". Select "Install the Software Automatically". You should see something that says "USB->Serial". This process will be repeated for "USB Serial Port". An LED on the PCB may flash indicating that the board has power - if this does not occur don’t worry.
3. Install the following software packages in the order shown. These packages are available on the course home page (http://claymore.engineer.gvsu.edu/~jackh/eod/egr345.html), or on the C2D2 web page. Note: Be careful to install the packages in the order shown below.
4. Run megaload and select the com port found in step 2. In Megaload set the "File to be program in the flash" to be "test.hex", and set the baud rate to 38,400. You should then be able to push the reset button on the board and load the program. If all was successful you will see a few lines of text in the "messages" window and the last line will be "Flash Prog Done!".
d) Under ’Debug Platform’ select ’AVR Simulator’ - Many of the other choices require hardware for incircuit debugging. Under ’Device’ select ’ATMEGA 324P’ - If this choice is not present you will need to install a newer version of the software.
f) Enter the program in Figure 3.3 Test program (simple.c).
g) Open ’Project/Configure Options’ and Enter a ’Frequency’ of 8000000 (8 million) - this tells the compiler what default CPU frequency is so that it may calculate delays properly. Verify that the ’Create Hex File’ option is selected - this will create the ’hex’ file that we can download. Select ’OK’ to close the window.
h) Select ’Build/Build All’ to compile the program. If any compiler errors occur they will appear on the bottom of the screen. Double click on any errors to go to that line in the program. Once the program is compiled correctly go to the next step.
7. Start the Megaload program and make sure that the ’File to be programmed in the flash’ is pointing to the ’lab1_a.hex’ file in the project directory. Press the reset button on the board to download the program. A message will appear if the download was completed successfully. The program will now be running.
8. The program toggles the output on Pin 6C. This is slowed by the ’delay’ function. Connect the positive side of a multimeter to the PC6 output. Connect the negative side of the multimeter to a common/ground terminal. Change the delay and download the program again.
9. Enter, compile, and download the program in Figure 3.4 Digital inputs. Test it by changing inputs on port A and verifying that the same output changes on port B. Note: if an input is not connected, it will tend to assume a random value.
10. Enter, compile, and download the program in Figure 3.5 Analog inputs. Test the program by setting an analog input with a variable power supply connected to PA0. The 5 most significant bits of the outputs will be on port B. Set the input voltage to different voltages and measure the digital outputs. Convert the binary values to a decimal value and plot the results.
11. Enter, compile, and download the program in Figure 3.6 Analog Outputs with Pulse Width Modulation (PWM). The program will accept the input voltage on PA0 and output a corresponding voltage on PD7. Use a DMM to verify that the input and output voltages match. Use an oscilloscope to verify that the output wave is PWM and trace a few examples at different duty cycles.
12. Enter, compile and download the program in Figure 3.7 A system clock using interrupts. The outputs on port B will change in a binary pattern.
13. Download the files sio.c and sio.h to your working directory. Enter, compile and download the program in Figure 3.8 ASCII Communications. You will then need to close ’megaload’ and start hyperterm. Choose ’com1’ with 9600baud, 8 data, 1 stop, no parity and Xon/Xoff handshaking. You should see text messages on the screen.
4.0.1 Lab 2 - Numerical Methods[an error occurred while processing this directive]
1. Write a C Program to integrate the area beneath the function below. The program should ask the user for the start and end points, as well as the number of steps. (you can download compilers from http://claymore.engineer.gvsu.edu/~blaucha/c2d2/c2d2.html)
2. Enter and test the numerical integration Scilab program written for the prelab. Change the step size and determine what step size results on ’convergence’ of the results. Show a graph of the results.
5.0.1 Tutorial - Creating Web Pages[an error occurred while processing this directive]
2. Go to http://www.mozilla.org/editor and download the web page editing tool. In the editor go to ‘claymore.engineer.gvsu.edu’ and look for your account under ‘students’. You should be able to find a page that starts with ‘YOUR_NAME_GOES_HERE’.
3. First, save the page using ’save’. If one doesn’t exist, create a ‘temp’ directory on the computer. This directory will be used to temporarily hold your web page files. Make sure that the files will be saved in the ‘temp’ directory, and then ‘save’ the file as ’index.html’, all in lower case. An editor will start on the screen.
4. The editor behaves much like Microsoft Word, with some subtle differences. At this point add your name, and change your email address to your university account. You can change your email address by clicking on the email link, and then clicking on the ’chain link’ near the top of the screen.
5. To upload the changes use FTP. Many computers have ’WSFTP’ installed, although other FTP tools are available and may be used. You will need to connect to ’claymore.engineer.gvsu.edu’ and login with you user ID and password. (NOTE: Don’t save these on the computer you are using because somebody else could use your account.) Change to the ’public_html’ directory and copy the files there. As a minimum you will need to copy the ’index.html’ file, but any other files you need should also be in this directory, or in a subdirectory.
6. Use Firefox, not the editor, to see if the changes have occurred. Your changes may not show up on the browser. This is because Firefox does not reload pages every time to look at them. Pages are often stored for up to 1 month on the PCs hard drive, and reused when you look at them. One way to update the screen before this time limit is to click on the ’reload’ or ’refresh’ button.
7. Next we will add links to your home page. Identify the file you would like to link to, and move it to the temp directory with the ’index.html’ file. Use a file name that is all lower case such as ‘test.mcd’ - any upper case letters cause problems in Windows. Open your homepage in the editor, if it is not open already. Write a simple description for the file, and highlight it with the mouse. Use the ’link’ button at the top of the editor screen, and enter the file name for the link. If it is in the same directory nothing else is needed beyond the file name. Pay attention to the case of the file name, upper and lower case are significant. Upload the page (using FTP) and the file to claymore and verify that the link works.
8. Get your home page back in the editor. Someplace on the page add a line that says ’GVSU’. Use the mouse to select what you just typed, and then click on the link button. For the link name enter ‘http://www.gvsu.edu’, and apply the change. This will now be a link to the Grand Valley home page. Upload and test the link.
6.0.1 Lab 3 - A Feedback Controller[an error occurred while processing this directive]
A basic feedback control system is shown in Figure 6.1 Atmega32 based velocity feedback controller. In this system the atmega32 will output a control voltage as a PWM signal. When the output is 0V, the transistor will be off, and act like an open switch. However, when the output is 5V, it will turn the transistor on, and allow current to flow to the motor. (Note: There will be a voltage drop across the transistor, in this case approximately 0.8V.) The motor shaft is connected to a tachometer to measure the motor speed. (Note: In this lab we will use another motor as the tachometer.) The tachometer will produce a voltage proportional to the motor speed.
To complete the control system, a program is required. The program reads the motor speed input, Ct, from the analog voltage, Vt, and use it to adjust the output, Cc, to adjust the voltage, Vs, to control the motor speed. Normally a user may supply a setpoint, Cd. This setpoint indicates the desired speed. In this program care is required to ensure that the Cc value remains in the range from 0 to 255 because of the limitation of the PWM functions.
The PWM output to the motor is a square wave with a variable duty cycle. Equation (1) below shows how to convert the PWM value to an effective output voltage. It is worth noting that part of the voltage from the power supply is lost across the transistor, thus reducing the effective voltage to the motor.
To implement this controller we need a better program structure than was used before. This is shown in the following program listing. The IO_update() function will be called many times per second by an interrupt subroutine. The CLK_setup function initializes the interrupt routines in the processor so that the ’SIGNAL(SIG_OVERFLOW1)’function will be called once evey 10ms. This in turn will call the IO_update() function. The main program sets up the various input output devices and then begins a loop where it deals with keyboard IO. Notice that the subroutines to update the inputs and outputs do not appear in the main program loop. It communicates with those routines by changing the value of the global variable ’count’.
One major challenge when constructing a system is debugging. The flowchart in Figure 6.3 The Traditional Debugging Approach shows the tradition approach to debugging.
While this debugging approach is easy to understand it takes much longer to solve problems and can become very frustrating. The debugging approach shown in Figure 6.4 Enlightened Debugging Approach is much more mature. Although it involves a few more steps, it will often take substantially less time. The essence of this method is that the program is not changed until the source of the problem in known. Common methods are to use print statements, or other debugging tools to see what the program is doing.
2. Write a program that will allow keyboard commands to change the PWM, and output the analog input to the screen once a second. Please note that this may be noisy and using the average of multiple readings may be required to reduce the noise.
3. Write a program that implements the feedback controller described in the background section. Put the feedback loop in an interrupt subroutine, and use the main program for keyboard IO. Don’t forget to consider the number limitation of the chosen datatypes. (i.e., 2’s compliment integers)
1. Build the motor speed controller pictured in Figure 6.5 PWM control of motor speed. Use Figure 6.6 TIP 120/122 NPN Darlington pair transistor when connecting the transistor. (Note: if the transistor gets hot during operation use a heat sink on the transistor to help dissipate heat). Use the PWM program from the previous lab to control the PWM output and test the motor speed control.
2. Use a second motor as the tachometer (not to be confused with the strobe tachometer, used for calibration). This is done by connecting the motor shafts using a light colored piece of tape. It is also advisable to fix both motors to a common base to reduce vibrations. DO NOT CONNECT THE TACHOMETER LEADS TO THE ANALOG INPUT YET.
4. Use the program developed for the prelab to vary the PWM output to control the motor speed. Take the following readings in a tabular form. The motor RPM can be measured using the strobe tachometer as a reference. Vt is measured from the motor tachometer using the DMM, and a second DMM is used to measure Vs. The table should have at least 5 points spanning the range. (Note: if there is excessive vibration correct it before taking readings.)
5. If the voltages for Vt were negative swap the V+ and V- labels on the motor tachometer. FAILURE TO DO THIS MAY DAMAGE YOUR EQUIPMENT. Connect the motor tachometer to the analog input as shown in Figure 6.7 Motor tachometer analog input. You may also change the signs for Vt in the table.
7. Enter and test the feedback control program developed in the prelab with a gain of P=2. Change the setpoint, Cd, to different values and measure the resulting speed, Ct. Record these values in a new table.
7.0.1 Lab 4 - Deadband Compensation for Bidirectional Motion[an error occurred while processing this directive]
Friction in motors will prevent them from turning when small voltages are applied. This effect is normally known as ’stiction’, a combination of the words static and friction. Friction is present in all motors, however this effect is greater in lower cost motors. When a motor is connected to a mechanical system the friction may increase greatly. In most cases we can reduce the cost of a new design by using less expensive motors and compensating for larger friction effects in software.
In motors there are two types of friction that must be considered. The static friction, ’stiction’, will prevent initial motion. If the motor supplies enough torque to break free and start turning, the kinetic friction will provide a roughly constant friction torque.
Figure 7.1 Motor deadband for a bidirectional motor shows an example of how this friction affects the relationship between the voltage applied to a motor, and the resulting velocity. At very low voltages the torque is too low to overcome the stiction. The region where the applied voltage has no effect is called the deadband. Once the applied voltage exceeds the deadband limits the motor will start to turn. While turning, the motor experiences kinetic friction, damping and other effects. If the voltage supplied to the motor is slowly decreased it will eventually ’stick’. However, the sticking force will be lower than the static friction force. This alternate path is shown in the figure as a heavy dashed line.
There are a number of methods for compensating for a non-linear deadband in a system. A simple method is shown in Figure 7.2 Deadband approximation for a bidirectional motor. This method involves finding the voltages where the motor breaks free in the positive and negative directions. These are used in a program to change the wanted output voltage, to an adjusted output voltage.
The equations to implement a deadband compensator are shown in Figure 7.3 Deadband approximation for a bidirectional motor. These adjust the wanted voltage to exclude the deadband. In this case the equations also adjust the relationship to allow the full use of the PWM output scale.
The equations from the previous example are implemented in the subroutine given in Figure 7.4 Deadband compensation for an ATMega32 controlled output. This subroutine actually allows the positive and negative deadband limits to be different, as would be expected in an actual motor. The subroutine also verifies that the corrected values are within the limits of the PWM output. In the example the equations have been rearranged to prevent roundoff errors during the integer calculations. The moving variable must be set so that when the velocity of the system is approaximately zero, it will have a value of 1. The algorithm includes an option to apply a higher (static) torque when not moving (moving == 0) to ’break away’. Normally this would be used for a short period of time to allow the motor to start moving, and then be reduced (moving = 1) so that the kinetic friction torque is used. If a system has feedback the detection of motion can be used to change the coefficient used.
Limiting function are used when the requested output exceeds the available output range. An example is shown in Figure 7.5 An output limiter.
In previous labs we used a transistor to control motor movement in one direction. The H-bridge circuit shown in Figure 7.6 H-bridge circuit for motor control can be used to drive a motor in two directions. As before, the transistors are used to switch current flow. In this case applying a voltage to the A1 and A2 terminals would allow voltage to flow left-to-right through the motor. Turning on inputs B1 and B2 would cause current to flow right-to-left through the motor. When the inputs are controlled using a PWM signal the effective motor voltage can be varied.
When controlling an H-bridge some extra logic circuitry is commonly used, such as that in Figure 7.7 H-bridge control logic. The main purpose for this circuitry is to protect the H-bridge. For example, if A1 and B1 were both on at the same time, current would bypass the motor, on the left side. The current would be high, similar to a short circuit, eventually destroying the devices. The logic in the figure prevents this. In the logic the PWM output is connected to the E (enable) input. The direction is then used to determine which pair of transistors is turned on.
In this lab we will use an integrated circuit that already contains protection circuitry. For our purposes we can approximate the control logic in that chip with that in Figure 7.8 H-bridge control logic. In this logic we will apply the PWM signal to the E (enable) input. We will then turn on the CW (clockwise) or CCW (counter clockwise) output to determine direction. Care is required to avoid turning both the CW and CCW outputs at the same time.
As you will recall from previous labs the PWM output range is from 0 to 255. However for bidirectional motion we will have both positive and negative motor outputs. The program in Figure 7.9 Subroutines for PWM outputs and reversing the motor direction is designed to compensate for this by checking the sign of the requested output value. Depending upon the sign the CW and CCW outputs will be switched, and the negative values made positive. This routine also checks to make sure that the values don’t exceed the maximum limit of 255. This subroutine also changes the direction of rotation by reversing two of the output bits on port C.
The subroutines in Figure 7.10 The output update subroutines deal with general IO updates, as well as a simple delay routine. It allows the deadband compensation to be disabled to simplify the identification of deadband limits.
The main program is shown in Figure 7.11 The main test program. It includes numerous keystroke commands to allow the modification of settings.
1. Develop a program for open loop velocity control using the subroutines given in the theory section. The program should compensate for the deadband of the motor, as described in the prelab. The main program should initialize the PWM routines and other outputs and allow keyboard inputs to change the setpoint. The routines that correct for the deadband stiction and update the PWM output are not part of an interrupt driven subroutine. This is because we are using feedforward control and there is no feedback value available to update the system.
1. Set up the motor controller as shown in Figure 7.13 Using an ATMega32 motor controller with a L293Ddriver, the pins for the device are shown in Figure 7.13 Using an ATMega32 motor controller with a L293Ddriver and Figure 7.14 L293D pinout diagram (top view). The L293D actually contains four drivers, or the equivalent of two H-bridges. In this case we will use two of these that can supply a peak current of 600mA.
3. Run the program with the deadband correction disabled. Vary the voltages for the motor to fall between -255 and 255 and record the desired motor speed, the output voltage and the actual motor speed in a table. Note: that the negative values are probably shown as 2’s compliment negative value and must be converted to positive values.
8. By now you will have observed that even with deadband compensation the motors may still ’sick’ at very low speeds. One trick to overcome this issue is to add a brief ’kick’ at the start of a speed increase. Do this by adding some code similar to that shown in Figure 7.15 ’Kick’ code - please note you will need to modify this somewhat.
8.0.1 Lab 5 - Position Control with an Encoder[an error occurred while processing this directive]
Rotational 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 8.1 An optical encoder. 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 rotation is measured. Two light beams are used to detect the direction of rotation.
A very low resolution encoder disk is shown in Figure 8.2 Encoder disk. The dashed line indicates the position where the light beams cut across the disk. As the disk rotates the beams are broken at staggered intervals.
Optical 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 ’bouncing’ as they make and break contact, 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 generally cost less than similar optical encoders.
An quadrature input pattern from an encoder is shown in greater detail in Figure 8.3 Quadrature Encoders. 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 second 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 the counter is decremented.
The previous method is simple to implement, but less accurate. A more accurate method looks at the current and previous state of both quadrature inputs. Consider the example in Figure 8.4 Quadrature Encoders as binary inputs 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.
A program to read position and velocity input from an encoder is given in Figure 8.5 Subroutines for reading position using an encoder. The program uses pins 0 and 1 on port B as encoder inputs. In this case the program counts upon both the positive and negative edges of both phases. This is done by comparing the current encoder position to the previous encoder position. When the inputs change the encoder value is either incremented or decremented, depending upon the preious values.
A position control system is shown in Figure 8.6 Position control system. This system uses the H-bridge from the previous laboratory to drive a motor, which in turn drives an encoder used for position feedback.
The block diagram for the control system is shown in Figure 8.7 Position control feedback loop. This control system 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 controller. It will calculate the system error by subtracting the encoder counter from the desired position. This will then be passed through a proportional and integral function. The result will be corrected for the deadband and output to control the motor as a PWM signal.
All of the functions in the control system have been implemented in previous laboratories, 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 Figure 8.8 Numerical integration. A subroutine to implement the proportional-integral controller is shown in Figure 8.9 Proportional integral controller. The integration subroutine also includes a crude limiting function to prevent the integral value from becoming excessively large.
Please note that the interrupt subroutines given in a previous lab use the same timer (1) as the PWM output. As a result new version using counter 0 is given in Figure 8.10 Interrupt subroutine using counter 0.
1. Connect the control system and the motor using an L293D to drive the motor and an encoder as shown in Figure 8.11 Connecting the Encoder to the ATMega or Figure 8.12 Connecting a mechanical encoder to the ATMega32. Note the motor used in this lab may be a 3V motor, so the power supply voltage may differ from previous labs.
2. Test the program developed for the prelab. (Note: Remember to build and test in pieces whenever possible.) Determine all necessary parameters, such as the deadband limits. Note: if the motor positive and encoder positive directions are opposite, then the motor will rotate forever. This problem can be solved by reversing the motor leads.
5. Supply different set points of motor positions and measure the steady state position. Also observe the response speed. After the motor settles, attempt disturbing the motor position (gently) and record your observations.
9.0.1 Lab 6 - Motion Control[an error occurred while processing this directive]
A simple (e.g., proportional) controller will move faster when further from the setpoint (desired position). This means at the start of motion there is normally a period of fast acceleration, resulting in a ’jerk’ and high acceleration. At the end of motion the controller slows smoothly to a stop. In many cases we prefer motion that starts and stops smoothly. This is achieved by adding motion control.
A block diagram for a motion controller is shown in Figure 9.1 Motion generation. In this system a target position is used to generate a set of points and times along a smooth path in a setpoint schedule table. These points are then used as setpoints for the feedback control loop. Motion starts at the beginning of the table with the first setpoint. At the given times, the setpoint is updated to the new value in the table. In this system the controller is always shooting for the next point on a smooth path.
There are multiple methods for generating a smooth motion path, this section outlines two of these. The first is shown in Figure 9.2 Generating smooth motion paths, it controls motion using a parametric function ’p(u)’. The function value varies from 0 to 1 as the parameter ’u’ varies from 0 to 1. However, the parameters of the function are selected so that the motion starts and stops with a velocity of zero. In this case the final polynomial equation, (3), is fairly simple. This equation can then be used in equation (1) to generate a smooth motion path between any arbitrary start and end point, with arbitrary start and end times.
The example in Figure 9.3 Generating smooth motion paths shows the use of a trigonometric function, instead of a polynomial. This function was used to generate the points in the following sample program in Figure 9.4 Subroutines for motion profile generation and use.
The program in Figure 9.4 Subroutines for motion profile generation and use generates a motion table that can then be used to update setpoints. The function ’table_init()’ must be called once when the program starts to set up global time and table values. When a new target position has been specified the ’table_generate()’ function is called to generate the setpoint table. The ’table_update()’ function is called once every interrupt scan to check the setpoint table, and update the global setpoint variable, ’point_current’ at scheduled times. This function also includes a simple clock to keep track of the system time.
2. Write a program to use the setpoint generation routines with the position feedback control system developed in previous labs. The user interface should allow the user to increment or decrement a target value using ’i’ or ’d’. The user should be able to set the duration using key ’0’ to ’9’. The target value will not update the motion table until ’g’ is input. ’s’ will stop the motion.
10.0.1 Lab 7 - Characterizing Brushed DC Motors[an error occurred while processing this directive]
DC motors will generate a torque between the rotor and stator that is related to the applied voltage or current. When a voltage is applied the resulting current will generate a torque causing the rotor to accelerate. For any voltage and load on the motor there will tend to be a final angular velocity due to friction and drag in the motor. And, for a given voltage the ratio between steady-state torque and speed will be a straight line.
The basic equivalent circuit model for the motor is shown below. We can develop equations for this model. This model must also include the rotational inertia of the rotor and any attached loads. On the left hand side is the resistance of the motor and the ’back emf’ dependent voltage source. On the right hand side the inertia components are shown. The rotational inertia J1 is the motor rotor, and the second inertia is an attached disk.
These basic equations can be manipulated into the first-order differential equation in Figure 10.2 The first-order model of a motor.
A method for calculating motors parameters given the motor response to a step input is shown in Figure 10.3 Estimating motor parameters from performance. In this example the motor windings had a measured resistance of 40 ohms. When a 15V step input was applied, the motor ran with a steady state velocity of 2400 RPM. The motor responded to the input with a time constant of 0.5s.
3. Write a program for the ATMega32 that will set the PWM output and collect data for tachometer speed. Hitting the ’R’ key will make the process idle, with a PWM output of 0. Hitting a key between ’0’ and ’9’ will set the PWM output value between 0 and 255 in equal divisions. At this point the program should begin to collect analog input values every 10ms and save these in an array for 1 second. After the data collection period, the PWM output should stop and the program should become idle. Hitting the ’D’ key should dump the data to the screen so that it can be saved and plotted in Excel. The program should also include deadband compensation.
1. With the motor disconnected from all other parts of the circuit, measure the resistance across the motor terminals. You may need to rotate the shaft slightly (and slowly) as the resistance will vary as the motor brushes and commutator make/break contact.
2. Connect the motor and the ATMega32 board so that the PWM output drives the motor with the TIP 120/122 transistor or L293D. The motor shaft should be connected to the motor being used as the tachometer.
5. Obtain velocity curves for the motor with different voltage step functions. Use these to determine the motor parameters. Note: it is useful to use a range of voltages so that the data includes a wide range of steady state angular velocities.
11.0.1 Lab 8 - System Modeling and Simulation[an error occurred while processing this directive]
In the previous laboratory we modelled a motor using a differential equation that did not include friction. To compensate for the effects of friction a deadband compensator was used. If we include friction in the model for the motor it is possible to develop a better motor model that is more accurate. It also makes it possible to develop a simulation that accurately models the system as a whole.
The differential equation is rederived in Figure 11.1 The torque and inertia in a basic motor model and Figure 11.2 The first-order model of a motor experiencing kinetic friction to include a term for friction. In the derivation it is assumed that the motor is turning, and the friction is dynamic. Clearly the motor will not turn if the motor torque is less than the static friction limit.
The coefficients for the differential equation in Figure 11.2 The first-order model of a motor experiencing kinetic friction can be found for the motor in a dynamic case using steady state velocities. The static torque value can be found using the deadband limits.
Potentiometers measure the angular position of a shaft using a variable resistor. A potentiometer is shown in Figure 11.3 A Potentiometer. A potentiometer is based upon a resistor, normally made with a thin film of resistive material. A wiper can be moved along the surface of the resistive film. As the wiper moves toward one end there will be a change in resistance proportional to the distance moved. If a voltage is applied across the resistor, the voltage at the wiper interpolate the voltages at the ends of the resistor.
The potentiometer in Figure 11.4 A Potentiometer as a Voltage Divider is being used as a voltage divider. As the wiper rotates the output voltage will be proportional to the angle of rotation.
Potentiometers are inexpensive but have limited accuracy, normally in the range of 1%. They measure absolute position, and are calibrated by rotating the shaft to given angles and measuring the resulting output voltage. The range of rotation is normally limited to less than 360. An example of a potentiometer used for position feedback is given in Figure 11.5 Position control system.
For the laboratory this week we will use a system like that defined in Figure 11.6 Block diagram of a position control system, with a potentiometer for position feedback.
A control system can be evaluated numerically using a program similar to the one shown in Figure 11.7 Scilab program to simulate position feedback control and Figure 11.8 Scilab program to simulate position feedback control. The program uses the simple model of the motor, without friction, and proportional feedback control. The program has also been designed to model the potentiometer input and PWM output.
3. Write a C program to control the motor using the potentiometer for position feedback. The program should use deadband compensation (note: this is the static friction torque when the motor is not moving, but the kinetic friction torque while turning). The program should have a user interface similar to the one used for measuring motor parameters. The motor should start at rest, and when a key is pushed it should be given a new setpoint. The data should be collected, and dump when the user hits another key.
5. Provide a step input to the ATMega32 controller and measure the response. Compare the actual motor response to the curve simulated in Scilab with the same system conditions. The comparison should be in terms of first/second order characterizations, such as damped frequency, overshoot or time constant.
12.0.1 Lab 9 - Variable Frequency Drives[an error occurred while processing this directive]
AC induction motors are designed with motor winding on the stator (outside) of the motor. The AC current in the stator coils sets up an alternating magnetic field. This field induces currents in the conductors (squirrel cage) in the rotor. This current creates a magnetic field that opposes the field from the stator. As a result a torque is created. In actuality the rotor must rotate somewhat slower than the field changes in the stator, this difference is called slip. For example a 3 phase motor (with two poles) that has a 60Hz power applied will with absolutely no rotational resistance rotate at 60 times per second. But in use it might rotate at 58 or 59Hz. As the number of poles in the motor rises, the speed of rotation decreases. For example a motor with four poles would rotate at half the speed of a two pole motor. The speed of the motor can be controlled by changing the frequency of the AC power supplied to the motor.The motor that we will use in the lab is a 3 phase AC motor made by Marathon Electric. It is a Black Max model number 8VF56H17T2001. The motor drives are Allen Bradley model 161 motor drives.
An induction motor has the windings on the stator. The rotor is normally a squirrel cage design. The squirrel cage is a cast aluminum core that when exposed to a changing magnetic field will set up an opposing field. When an AC voltage is applied to the stator coils an AC magnetic field is created, the squirrel cage sets up an opposing magnetic field and the resulting torque causes the motor to turn.
The motor will turn at a frequency close to that of the applied voltage, but there is always some slip. It is possible to control the speed of the motor by controlling the frequency of the AC voltage. Synchronous motor drives control the speed of the motors by synthesizing a variable frequency AC waveform, as shown in Figure 12.1 AC Motor Speed Control.
These drives should be used for applications that only require a single rotational direction. The torque speed curve for a typical induction motor is shown in Figure 12.2 Torque Speed Curve for an Induction Motor. When the motor is used with a fixed frequency AC source the synchronous speed of the motor will be the frequency of AC voltage divided by the number of poles in the motor. The motor actually has the maximum torque below the synchronous speed. For example a motor 2 pole motor might have a synchronous speed of (2*60*60/2) 3600 RPM, but be rated for 3520 RPM. When a feedback controller is used the issue of slip becomes insignificant.
The equipment used in this laboratory is designed for industrial use and requires some knowledge of basic electrical concepts. These motors use 3-phase power. Most of the electrical sources you use are single (1) phase Alternating Current (AC). In these systems the power is delivered with three wires, the hot (black), the neutral (white), and the ground (ALWAYS GREEN). Important: The ground is used for safety, it should always be connected first to all major metal pieces in a system. The neutral should normally be a 0V (like a DC common). The hot will be switched on/off and provide a 120Vac 60Hz sine wave voltage to the system. The hot also has a fuse attached for safety. In this arrangement power flows from the hot to the neural, and should not flow through the ground unless there has been a short or some other fault.
Three phase electrical systems deliver power with 3-three lines. Each of the lines (L1, L2, and L3) contains a 60Hz sinusoidal voltage that has a 0, 120, or 240 degree phase shift. A useful mathematical property of these is that the sum of all three voltages is 0V. When 3-phase power is used with balenced loads there is no need for a neutral, although one is often provided for unbalanced loads. Grounds are also required for these systems.
When connecting grouns it is important to do so in a ’tree’ configuration. The grounds in the electrical system are connected to a deep conductor burried beneath the building. These are then run up to each outlet and machine from central points. A problem called a ground loop can occur when connections are made that cross the branches of the tree such that a circle of ground wire is made. Any magnetic fields cutting across these loops induce currents/voltages. These are often the source of randon failures, electrical shocks, etc.
1. Visit the Marathon Electric and Allen Bradley web sites and review the manuals for the motor and controllers. Don’t print these, but make a note of the web address so that you can find the manuals easily during the lab.
2. Connect the 3 phase motor to a tachometer for a velocity feedback. Before connecting the tachometer to the ATMega32 and check the polarity and maximum voltage when the motor is running at the maximum speed. Do not use the tachometer if the voltage exceeds 5V. Connect the tachometer to the ATMega32 board and use a capacitor to reduce noise from the tachometer.
3. Use the ATMega32 to collect motor speed data for a step input to the VFD. The step input can be obtained by putting the VFD in program mode, setting the potentiometer to e new position and then putting the motor back in run mode. The display should be set to display the motor speed. Repeat the process for different setpoints, and plot the curves on the same graph.
4. Using the manual, determine how to change the PID parameters. Don’t forget to connect the tachometer to the motor drive for velocity feedback. Run a number of tests to see what it does. Record the data and graph it in your lab book.
13.0.1 Tutorial - Allen Bradley 161 Variable Frequency Drives[an error occurred while processing this directive]
1. The motor should be connected the the drive as shown in the figure below. The three phase power lines are T1, T2 and T3. These can be connected to the drive by loosening the screw on the front face of the drive. (WARNING: make sure the power is off before opening the drive, and relseal the drive when done) The two other lines P1 and P2 from the drive are for a thermal overload relay, we will not use these. For general caution the ends of the wires should be covered with electrical tape to prevent accidental contact with other conductors. The wire from P24 (a 24V power source) and input 3 are for an emergency stop and must be connected for the drive to work. These terminals can be found under a flip up panel on the bottom front of the drive that can be opened by pulling on the right side of the face.
2. Notice the display and lights on the front face of the drive. When a program is running the ’RUN’ light is on. The program can be started using the green ’1’ button, and stopped with the red ’0’ button.
3. Program the unit using the buttons on the front panel, following the steps below (from page 17 in the manual). After the steps have been followed press the run button and turn the potentiometer to vary the speed. Try holding the shaft (cover the shaft to avoid cuts) at high and low speeds. What do you notice at very low speeds?
4. Connect a proximity to the controller as shown in the diagram below. Display the input values using ’D05’.The bits on the screen should move up for an active input, and down for an inactive input. Input 3 will always be active because it is being used for the emergency stop (a factory default).
14.0.1 Lab 10 - IO Using Labview[an error occurred while processing this directive]
Programming languages are essential components of complex systems. Languages such as ’C’ execute one function at a time as the program executes. This is good for program with a clear execution order. However for programs dealing with a continuous system this can be cumbersome.
Labview is a dataflow methodology, like a block diagram. This allows the creation of programs that show how inputs flow through functions to create outputs. Labview allows us to write programs for calculation and data collection, but instead of typing instructions we draw function blocks and connect them. How we connect them determines how the data (numbers) flow. The functions are things like data reads and calculations.
In general people can learn to write simple Labview programs quickly, however more complicated programming tasks can be more difficult than similar programs written in C. But, Labview has a distinct advantage when developing Graphical User Interfaces.
The connector for the card, shown in Figure 14.1 PCI-1200 Card edge connector pinout, can be found on the back of the computer. It will have a connector with pinouts like the one shown below. A ribbon cable will be used to make electrical connection to the connector in the back of the computer.
In this lab we will be using Labview to connect to a data acquisition (DAQ) board in the computer. This will allow us to collect data from the world outside the computer, and make changes to the world outside with outputs.
When interfacing to the card using a program such as Labview, there must be ways to address or request information for a specific input or output (recall memory addresses in EGR226). The first important piece of information is the board number. There can be multiple DAQ boards installed in the computer. In our case there is only one, and it is designated device ’1’. There are also many inputs and outputs available on the card. For analog outputs there are two channels so we need to specify which one when using the output with 0 or 1. For analog inputs there are 8 channels, and as before, we must specify which one we plan to read from using 0 to 7. For digital I/O there are a total of 24 pin distributed across 3 ports (1 byte each). Therefore when connecting inputs and output we must specify the port (PA=0, PB=1, PC=2) and the channel from 0 to 7. Note is that we can make the ports inputs or outputs, but not mixed - in other words we must pick whether a port will only be used for inputs or for outputs.
The voltage levels for the inputs and outputs are important, and you will need to be aware of these. For the digital outputs they will only ever be 0V or 5V. But the analog inputs and outputs will vary from -5V to 5V. This is build into the board. If we exceed these voltage limits by a few volts on the inputs, the boards have built in protection and should be undamaged. If we exceed the input voltages significantly, there is a potential to permanently damage the board.
2. Enter the LabVIEW program (layout) schematically shown in Figure 14.2 Analog input using Labview and connect a signal generator to the analog input (ACH0). (Note: there is a pin diagram for the connector in the Labview tutorial section.) Start the signal generator with a low frequency sinusoidal wave. Use the ‘DAQ Configure’ software to test the circuitry and verify that your hardware is operational. Then run your Labview program. Record the observations seen on the screen.
4. Connect the multimeter as shown in Figure 14.3 Analog output using Labview. Test the circuit using the ‘DAQ Configure’ utility. Enter the LabVIEW program schematically illustrated below and then run it. You should be able to control the output voltage from the screen using the mouse. Record your observations.
5. Connect the digital input and output circuits to the DAQ card, as shown in Figure 14.4 Digital IO using Labview, and use the test panel to test the circuits. To do this, run the ‘DAQ Configure’ utility, double click on the ‘PCI-1200’, run the test panel window and ensure that the inputs and outputs are working correctly. Create the LabVIEW screen schematically illustrated below. This should allow you to scan an input switch and set an output light. When done, quit the program and run your LabVIEW program.
6. Use a counter output for a PWM device. Figure 14.5 PWM output using Labview shows a simple program to control the PWM output on the DAQ board. Enter the program and verify the operation with an Oscilloscope and DMM.
15.0.1 Lab 11 - Torsion[an error occurred while processing this directive]
- Select a round rod for the spring. A longer length, and a diameter from 1/4" to 1/2" will give a reasonable frequency range. Make sure you can identify the material so that you can estimate the spring coefficient.
- Select a mass of 10-20kg. Ideally the mass will have a simple geometry that will simplify the calculation of the moment of inertia. Placing parts of the mass farther from the center of rotation will lower the frequency.
3. Calibrate the potentiometer so that the relationship between the output voltage and angle is known. Plot this on a graph and verify that it is linear before connecting it to the mass. Calculate the relationship between input angle and output voltage. Use this in following steps to convert potentiometer voltages to angles.
16.0.1 Lab 12 - System Simulation with Simulink[an error occurred while processing this directive]
2. Select a ’Sources/Step’ block and drag it to the blank window. This will be a step input to the system. By default it is a unit step that starts at t=0s. This can be changed by right-clicking, or double clicking, on the icon and selecting new parameters.
3. Create a summation block, so that we can use negative feedback, using ’Math/Sum’. The default block will sum both inputs. Change this by changing the parameters from ’I++’ to ’I+-’. This will be reflected on the main window as a negative feedback summation block.
5. Add a proportional gain to the system with ’Math/Gain’. The default gain for this is ’1’, but this can be changed by changing the properties. Connect this to the output of the summation block. (Note: the ’s’ and ’D’ operators are equivalent so 1/(s+1) = 1/(D+1).)
8. Connect the output of the transfer function back to the negative input of the summation block. At this point the system diagram should look like Figure 16.1 A simple feedback system in Simulink.
12. Enter the simulation for the second order differential equation, as shown in Figure 16.2 Simulation of a differential equation. Enter different values for the coefficients and verify the system behavior. Print and include graphs in your lab book.
13. Verify the results in the previous section by explicitly integration the differential equation for one set of values used in the previous step. Plot the function and compare it to the response found with Simulink.