Starting from:
$30

$24

Lab 6 PID Motor Controller Solution

Note: For this lab, you will be borrowing the Motor and the RS232 Cables from us. You have to return the Motor and the cables at the end of the term.

In most engineering applications, electric motors are controlled with some kind of feedback controller. In this lab, you will demonstrate why a feedback controller is better than an open loop controller. You will also build two kinds of feedback controllers to demonstrate why the PID variety is superior.

Pre-Lab Assignments:

1. Review an article “PID without a PhD” available in course website

2. Complete the Pre-Lab Questions.

Note: To protect your microcontroller it is important to deselect reset and run, this will make it easier to change your program without having to disconnect the motor. Though you should disconnect the 5V power each time you program the board.

(Options for target)- Utilities- Settings make sure “Reset and Run” is NOT selected.

This means you will have to hit the reset button to start your new software once it is loaded. But it also means that your motor will always be under control.

Task 1: UART

Using the UART to display your results on the PC will make the data gathering portion of this lab much easier. UART is a serial to parallel protocol supported by the Male RS232 port on the NUC140. There are other options to displaying your output on the PC which you can also explore. In this first task you will print “Lab 6” to your serial terminal emulator on your computer. If you have Windows 8 or 10 you can download an emulator such as Tera Term, as the Windows OS no longer provides a serial terminal emulator. You will also need a female RS232 to USB cable, or a female to female RS232 adapter with a male RS232 to USB cable. The lab has these in limited quantity and you may have to share with a classmate or purchase your own. The UART driver uses a struct similar to the PWM driver.

The ‘plant’ to be controlled in this lab is a DC motor. The speed of the motor is controlled by a power FET. The signal to the gate of the FET is the PWM output of the microprocessor (μP). The circuit is shown in Figure 1 below.

Figure 1: DC Motor Speed Control with Power FET

The RPM of the DC motor is sensed with the NTE3100 optical sensor similar to the one that was used in lab 3. The DC motor spins a disk or paddle that interrupts the IR beam between the LED and the sensor in the NTE3100. The NTE3100 is then connected to one of the external interrupts or timer event counters on the μP. Each rotation of the DC motor thus registers as 2 counts. By reading the count periodically, the RPM of the motor is determined. The circuit for the RPM sensor is shown in figures 2 and 3. Note that the circuit uses the CD4050 buffer as discussed in lab 3.

Hardware Setup:

Note: This takes more time than you think

DC motors are very noisy and, if not isolated from the board, could cause issues with the internal electronics. This lab will use three different isolation techniques. The Motor assemblies have built in capacitors between source and ground that provide the first layer of isolation. The second layer is to isolate the voltage source for the motor from the rest of the board and circuit. An external 3.3V source is ideal. If you cannot use an external source, the 5V source on the board is isolated from the rest of the chip and can be used as the motor source. However, the 5V can cause the motor to run fast. As you test out the different duty cycles of the PWM, you can choose to limit your highest duty cycle so that the motor does not rotate too fast for the sensor to keep track. Another option is to add a voltage divider between the 5V and the motor to lower the voltage supplied to the motor. The voltage source for the rest of the circuits should be the 3.3V source from the board and the same ground should be used for the circuit and the motor. This isolation will also improve the edge detect of the external interrupt of your choice (less noisy signal, means less false counts). The final isolation is adding a diode across the motor source and ground. The LED provided in the kit is a diode and can be used for this purpose, note that it should NOT light up if you have it placed correctly. In addition to isolating the noisy DC Motor, it is also important to limit the current drawn from the board. This is done using a resistor in series with the PWM output and connected to the gate of the IRLz14 logic level FET. The R3 resistance is a suggestion.

INT 3.3V 3.3V PWM 5V

Figure 2: DC Motor RPM Sensor

There are two prebuilt motor assembly configurations for the ECE4330 students and a build your own option for the ECE5330 students. The motor assembly pin diagrams are in Appendix A. Figure 3 is a diagram of a motor assembly connected to the MCU.

Figure 3: Full connection diagram

Task 2: Open Loop Controller

As you learned in lab 5, there are two kinds of control systems: open loop and closed loop. Your task in part 1 of this lab is to build an open loop DC motor controller. The speed of the motor is controlled by the PWM. The greater the duty cycle of the PWM output, the faster the motor turns. The RPM is measured using an edge triggered external interrupt of some type (EINT0, Timer0 event counter, etc).

Task 2: In-lab Tasks

1. Build an open loop controller based on the circuits in Figures 1, 2 and 3.

2. Use the keypad to vary the duty cycle of the PWM output from 0% to 100%. Record the data and use Excel to find out a linear relationship between the number loaded into the PWM output register (CMR3) or the PWM output duty cycle (sPt.HighPulseRatio) and the RPM of the motor.

3.

Program the keypad to control the RPM of the DC motor. Make Key 1 set the RPM to the low end of the range as measured in 2. Make Key 9 set the RPM to the high end of the range as measured in 2. Have the keys on the keypad set the RPM to increasing values that are integer multiples of 500 RPM e.g. key 2 sets the RPM to 2,500, key 3 sets the RPM to 4,000, key 4 sets the RPM to 5,000 and so forth. Note that the switches now command RPM, not a certain PWM duty cycle. Note that some motors might range from 9,000 RPM to 35,000 RPM. You will need to characterize your motor in step 2 and limit the high end to less than 40,000 RPM.

4. Use UART and the PC terminal to record actual RPM versus commanded RPM for various step changes in commanded RPM. You can save the terminal display more easily than trying to record LCD data. If you choose to use Excel for your graphs you may consider formatting your data with commas or spaces in columns to make the data import easier.

◦ Commanded RPM is the RPM set by the switch.

◦ Actual RPM is the RPM detected by the optical sensor.

◦ Output both RPM values to the terminal using the DrvUART_Write() statement. A good period for data output is once or twice a second.

◦ Run several step changes while recording data via the terminal.

5. Use Excel to graph the commanded RPM versus actual RPM data.

◦ Import the data into Excel by clicking on Data, then Get External Data, then Import Text File. Browse to the data file created by the terminal and open it. In the Text Import Wizard - Step 1 of 3, select Delimited then Next . In Step 2 of 3, select Space or Comma then Finish. Click on OK in the final screen and the data put out by the printf statement will be transferred to Excel.

◦ Use Excel’s charting functions to graph commanded RPM and actual RPM versus time for several step changes. Your graph should look something like figure 3.

◦ If actual RPM data is noisy, apply a single pole filter to the data. This can be done using code like the following:

displayRPM = 0.1 * measuredRPM + 0.9 * displayRPM;

where displayRPM is the data sent out in the DrvUART_Write() statement and measuredRPM is the RPM measured in the last control cycle.

Figure 4: Example Graph of Commanded RPM versus Actual RPM for an Open Loop Controller

Task 3: Simple Feedback Controller

With a feedback controller, plant output is sampled and used to correct control signals to the plant so that plant output adjusts to the desired output value. In this case, the plant output is DC motor RPM, the output is sampled by measuring RPM with the NTE3100 optical sensor and the control signal is the duty cycle of the PWM signal to the FET.

In the second part of this lab, you will build a simple feedback controller that samples RPM and adjusts the PWM so that the motor turns at the commanded RPM. This controller is a simple feedback controller because it does not do any math to figure out the fastest way to achieve the commanded RPM. The simple controller just senses if actual RPM is too high or too low and then nudges the PWM by one increment in the correct direction.

Task 3: In-lab Tasks

1. Modify the software from part 1 so that the actual RPM is used to nudge the PWM output in the necessary direction.

◦ If measured RPM is too low, increment the PWM output value by one.

◦ If the measured RPM is too high, decrease the PWM output value by one.

◦ If you are using the CMR3 register to control the PWM duty cycle consider using

+100 or -100 rather than +1/-1. Using the CMR3 register allows greater control of the PWM.

2. An important consideration is how often to sample the RPM and correct the PWM output. This is the control frequency. A control frequency of 10 Hz will work well for this lab.

3. Using the terminal, collect commanded RPM versus actual RPM data for several step changes in commanded RPM. Plot the data as in part 1. When compared to the open loop controller in part 1, the actual RPM should be closer to the commanded value.

Task 4: Proportional Feedback Controller

In the simple feedback controller built in Task 3, PWM output is modified by a constant value as required to make actual RPM conform to the commanded RPM. The result should have been a more accurate motor RPM. However, the response time is probably very long. That is, the actual RPM adjusts to the commanded RPM very slowly. The simple feedback controller is more accurate than the open loop controller, but again, its response time is very slow.

In Task 4, you will add proportionality to the controller to improve its response time. As in the simple feedback controller, the actual RPM will be very close to the commanded RPM. Unlike the simple controller, the response time should be very short. Commanded changes to RPM should very quickly be seen in actual RPM. This is very similar to what you did in Lab 5.

Task 4: In-lab Tasks

1. Modify the software from part 1 so that the amount by which the PWM output is adjusted depends on the size of the error between actual and commanded RPM.

2. Using the terminal, collect commanded RPM versus actual RPM data for several step changes in commanded RPM. Plot the data as in part 1. Controller response time should be improved compared to the simple feedback controller in part 2.

3. Go through the Lecture Notes for Lab 6, and complete any additional requirements presented during the lecture.

Parts List

1. DC motor

2. Power FET IRLz14

3. Optical sensor, NTE3100

4. Buffer, CD4050BC

5. Resistors, capacitors, LED

Deliverables

1. To Sign-Off: Demonstrate to your professor/lab instructor how the above three controllers perform. You should demo all three controllers separately.

2. Lab write-up: Follow the Lab Report Format. The report should include:

a. Introduction including summary of the lab tasks.

b. In lab tasks performed, problems encountered, your solutions, including hardware and software design and development.

c. Include the graphs of controller performance for all three kinds of controllers. Analyze and compare their performance.

d. Include the tables for the experimental data.

e. Discussion and conclusion.

f. Include separate codes for the three controllers.

Note: Each student must conduct the labs by themselves. You are not allowed to copy codes/content or to pair-up with other students to complete the labs. Each student must demonstrate individual tasks (after completion) to the professor and teaching assistant to get the full marks for the demo. Also, all the lab reports should be typed and turned in as a hard copy on time (check the syllabus for the due date), and a soft copy should be forwarded to the Teaching Assistant: Srikanth Ramadurgam on the due date and time.

Appendix A: Motor assemblies

Motor Assembly 1

Motor Assembly 2

Pre-Lab Questions for Lab 6

Name:

10 Points

1. According to the author of “PID without a PhD,” one of the three kinds of control is the most problematic. Which one is it and what makes it difficult to implement?

2. In the Technical Reference Manual, read the timer controller sections for the event counting function and the input capture function. (5.10.4.5 and 5.10.4.6)

a. What is the clock frequency rule/guideline if you have disabled the debounce?

b. What is the clock frequency rule if you have enabled the debounce?

c. Why do you think the TDR (register) value would be incorrect if these guidelines are not followed?

d. There are 4 Timers, each timer has a counter input pin and a capture input pin. Using the table 3.4.1.2 in the TRM (or the diagram 3.3.1.4) list the 8 pins used by the 4 timers for the external capture inputs and the event counter inputs.

e. What other options are there for external interrupts?

More products