MEM458-001 Microprocessor-Based Control Systems Lab 4 Modeling and Simple Feedback Control DSP28355, CCSv5.2 B.C. Chang and Mishah U. Salman Department of Mechanical Engineering & Mechanics Drexel University 2014 1. Introduction In this lab, you will use the program 4s_opnlpmodel_A to identify the input-output relationship and mathematical model of a DC-motor. You will also implement a simple up-down feedback controller to manipulate the motor speed and direction using 4s_updown_fdbkcntrl_B. Initially, this program will cause the motor speed and direction to follow the variable ref_speed which can be changed in real-time. The program will then be modified so that the closed-loop system step response can be recorded and viewed in a CCS Graph on the computer screen. 2. Objectives a) Record the steady-state speed and direction of the open-loop motor system as a function of the PWM duty cycle, which is determined by the value of the registers EPwm1Regs.CMPA.half.CMPA and EPwm1Regs.CMPB. b) Record the step response graphs of the open-loop motor system for a variety of step changes in the value of the register, EPwm1Regs.CMPA.half.CMPA. c) Use the results of (a) and (b) to construct a mathematical dynamic model of the DC-motor system. d) Record the step response graphs of the closed-loop system for a variety of step changes in the value of the variable ref_speed. e) Comment on the performance of the up-down feedback controller and how the feedback update step-size affects the closed-loop system performance. 3. Construct a Mathematical Model for the DC-Motor You will use the program 4s_opnlpmodel_A to find the input-output relationship of the DC-motor/H- Bridge system, and then construct a mathematical model for the open-loop system based on the experimental results. This program is a slight modification of 3s_opnlpcntrl_C, which was used in Lab 3. The connections remain the same as in Lab 3, and are as follows: 1. Connect the DC-motor, Faulhaber 2230.G0003, with HEDS 5540 optical encoder, to the MOTOR header pins on the left side of the H-Bridge board. 2. Connect ezdsp P8:pins 33 and 34 to TO CONTROLLER pins 1 and 2 of the H-Bridge board. 3. Connect ezdsp P8: pins 9 and 10 to TO CONTROLLER pins 3 and 4 of the H-Bridge board. (Note that reversing the PWM pins will reverse the motor spin direction.) 4. Connect ezdsp P8: pins 39 and/or 40 to the GND pins of the H-Bridge board. MOTOR TO CONTROLLER 1 2 3 4 SENSOR 3.3V GND H-Bridge Board illustrating necessary connection pins. Connect the ezdsp board to the USB port of the PC DO NOT OPEN THE SOCKET on the board to avoid damaging the DSP chip inside. GND PWR H-Bridge Motor Controller B.C. Chang, MEM Dept. Drexel Univ. 1/14 B.C. Chang, MEM Dept. Drexel Univ. 2/14
3A. Migrate the CCSv3.3 Project 4s_opnlpmodel_A to CCSv5.2 The CCSv3.3 project, 4s_opnlpmodel_A.pjt, together with the associated C program, 4s_opnlpmodel_A.c and a gel file 4s_opnlpmodel_A.gel can be found in the folder 4s_opnlpmodel_A _orig, which is inside the directory C:/tidcs/c28/DSP2833x/v131/CntrlDSP. You can employ the migration procedure you learned in Lab 1 to migrate the existing CCSv3.3 Project 4s_opnlpmodel_A to CCSv5.2. You also have an option to follow the procedure in Section 3 of Lab 2 Manual to directly create the new CCSv5.2 project from scratch based on 4s_opnlpmodel_A.c. 3B. Debug, Build and Run the Project 1. Select the project by clicking the 4s_opnlpmodel_A in the "Project Explorer" view. 2. Click on the green bug (debug button) on the tool bar as shown in the following figure. (ii) It allows you to connect the target device and control it (run, suspend, etc.) 5. Select "Run Load Load Program" to load the executable file 4s_opnlpmodel_A.out to the target device. 6. Select View Expresions. Type the names of the registers and variables of interest on the Expressions View as shown at the top of the CCS window: EPwm1Regs.TBCTR EPwm1Regs.TBPRD EPwm1Regs.CMPA.half.CMPA EPwm1Regs.CMPB ECap1IntCount ECap2IntCount num_of_ints angle_deg rpmnew CpuTimer0.InterruptCount Speed_cntrl inp_graph rpm_graph 7. Use Real-Time Mode to observe continuous updates of the values of the above registers and variables in the Expressions View window. 8. In the program, 4s_opnlpmodel_A.c, you ll see the input, speed_cntrl (or EPwm1Regs.CMPA.half.CMPA), is a periodic function of time with a period of 5 seconds: 3500 for the 1st second, 4500 for the next 3 seconds, and 2500 for the final second. 9. In the program, you ll record the input as a function of time in inp_graph (500) and record the output values in rpm_graph(500). 10. Run Resume 11. Observe the motion of the motor shaft, and the value changes of EPwm1Regs.CMPA.half.CMPA ( or speed_cntrl ) and rpmnew in the Expressions View window for at least 20 seconds. 12. Run Suspend, and the motor will stop. 13. In the Expressions View window, click the small triangle sign on the left of in_graph to expose the content of in_graph, which is an array consisting of 500 values of speed_cntrl recorded over a 5 second period. After observing the content, click the triangle sign to hide the content. 14. Repeat Step 13 to observe the content of rpm_graph in the Expressions View window. 15. Use Graph of CCSv5.2 to plot inp_graph and rpm_graph. In the CCS Workbench Window, Tools Graph Dual Time.., then modify the pop-up Dialog window as follows. 3. The debugging process will do the following: (i) Save all open files in the project selected (ii) Build the selected project and create an executable file 4s_opnlpmodel_A.out, which appears in the folder Debug (iii) Automatically switched to the CCS Debug perspective 4. The "Debug" view is now visible. (i) This view should always be open. Do not close it. If it is accidently closed, you can open it again using the "view debug" menu item. B.C. Chang, MEM Dept. Drexel Univ. 3/14 B.C. Chang, MEM Dept. Drexel Univ. 4/14
19. Perform a computer simulation of the mathematical model, and compare the simulated responses with the experimental results. 4. A Simple Up-Down Feedback Speed Control for the DC-Motor You will use the program 4s_updown_fdbkcntrl_B, and a slight modification of it, to achieve a simple up-down feedback speed control of the DC-motor. The idea is pretty simple: increase the PWM duty cycle if the motor speed is slower than desired, or decrease the PWM duty cycle otherwise. First of all, you will use a fixed step size to update the PWM duty cycle. Later, you may want to vary the update step size to improve the performance. The connections remain the same as those in Section 3: 1. Connect the DC-motor, Faulhaber 2230.G0003, with HEDS 5540 optical encoder, to the MOTOR header pins on the left side of the H-Bridge board. 2. Connect ezdsp P8:pins 33 and 34 to TO CONTROLLER pins 1 and 2 of the H-Bridge board. 3. Connect ezdsp P8: pins 9 and 10 to TO CONTROLLER pins 3 and 4 of the H-Bridge board. (Note that reversing the PWM pins will reverse the motor spin direction.) 4. Connect ezdsp P8: pins 39 and/or 40 to the GND pins of the H-Bridge board. Connect the ezdsp board to the USB port of the PC DO NOT OPEN THE SOCKET on the board to avoid damaging the DSP chip inside. 16. Click OK at the bottom of the Dialog window, graphical displays of in_graph and rpm_graph will appear in the CCS Window. 17. Repeat the above procedure with different step inputs to obtain a set of step responses of the motor system at different operating regions. 18. Construct a mathematical model for the DC-motor based on the experimental results. B.C. Chang, MEM Dept. Drexel Univ. 5/14 4A. Migrate the CCSv3.3 Project 4s_updown_fdbkcntrl_B to CCSv5.2 The CCSv3.3 project, 4s_updown_fdbkcntrl_B.pjt, together with the associated C program, 4s_updown_fdbkcntrl_B.c and a gel file 4s_updown_fdbkcntrl_B.gel can be found in the folder 4s_updown_fdbkcntrl_B _orig, which is inside the directory C:/tidcs/c28/DSP2833x/v131/CntrlDSP. You can employ the migration procedure you learned in Lab 1 to migrate the existing CCSv3.3 Project 4s_updown_fdbkcntrl_B to CCSv5.2. You also have an option to follow the procedure in Section 3 of Lab 2 Manual to directly create the new CCSv5.2 project from scratch based on 4s_updown_fdbkcntrl_B.c. 4B. Debug, Build and Run the Project 1. Select the project by clicking the 4s_updown_fdbkcntrl_B in the "Project Explorer" view. 2. Click on the green bug (debug button) on the tool bar. 3. The debugging process will do the following: (i) Save all open files in the project selected (ii) Build the selected project and create an executable 4s_updown_fdbkcntrl_B.out, which appears in the folder Debug (iii) Automatically switched the CCS Debug perspective 4. The "Debug" view is now visible. (i) This view should always be open. Do not close it. If it is accidently closed, you can open it again using the "view debug" menu item. (ii) It allows you to connect the target device and control it (run, suspend, etc.) 5. Select "Run Load Load Program" to load the executable file 4s_updown_fdbkcntrl_B.out to the target device. 6. Select View Expressions. Type the names of the registers and variables of interest on the Expressions View as shown at the top of the CCS window: EPwm1Regs.TBCTR B.C. Chang, MEM Dept. Drexel Univ. 6/14
EPwm1Regs.TBPRD EPwm1Regs.CMPA.half.CMPA EPwm1Regs.CMPB ECap1IntCount ECap2IntCount num_of_ints angle_deg rpmnew ref_speed ints_in_10ms 7. Use Real-Time Mode to observe continuous update of the values in the Expressions View Window. 8. Run Resume. You will see the motor start to turn approximately the speed of approximately 100 rpm. This is because ref_speed was initially set at 100. 9. When the program is running in real time, you can change ref_speed in the Expressions View window to a number between -700 and 700. Observe the motor motion and the values of ref_speed, EPwm1Regs.CMPA.half.CMPA, and rpmnew in the Expressions View Window. 10. Repeat Step 9 several times and record your observation results. 5. Step Responses of the Simple Up-Down Feedback Speed Control System 5A. Create a New CCSv5.2 Project 4s_updown_fdbkcntrl_C In this section, you will create a new CCSv5.2 Project 4s_updown_fdbkcntrl_C. The function of this project is similar to the project in Section 4, 4s_updown_fdbkcntrl_B, which uses a simple incremental up-down approach to achieve feedback speed control. The only difference is that it will include inp_graph(500) and rpm_graph(500) as in 4s_opnlpmodel_A.c so that inp_graph(500) will record the values of ref_speed, which is a periodic function of time with a period of 5 seconds, and rpm_graph(500) which will store the values of rpmnew, the actual motor speed, corresponding to ref_speed. The reference speed input is programmed to be 100 rpm in the first two seconds, then 200 rpm for the last three seconds. The procedure to create this new CCSv5.2 project is similar to what you learned in Section 3 of Lab 2 Manual. The starting point will be the C program you just did in Section 4 of Lab 4, 4s_updown_fdbkcntrl_B.c. You ll make a copy of it, rename it as 4s_updown_fdbkcntrl_C.c, and keep it in the new directory, C:/tidcs/c28/DSP2833x/v131/CntrlDSP/4s_updown_fdbkcntrl_C. The CCSv5.2 project creation procedure is briefly reviewed as follows: 1. Keep the new project files in a new workspace folder, workspace_v5_4sc. File Switch Workspace Others to create the new workspace folder, workspace_v5_4sc. 2. Select File New CCS Project from the manual. This opens the New CCS Project wizard. 3. In the Project Name field, type the new project name: 4s_updown_fdbkcntrl_C. 4. In the Output type, select Executable. 5. Select C2000 in the Family field. 6. In the Variant field: select 2833x Delfino and EZDSPF28335. 7. In the Connection field, select Spectrum Digital DSK-EVM-eZdsp onboard USB Emulator. 8. The Advanced settings section is minimized by default. Nothing needs to be changed. However, you still can expand it to see the compiler version (TIv6.1.0). 9. Expand the Project templates and examples section. Then select Empty Project you will add files to the new project in a little while. 10. Press the Finish button. B.C. Chang, MEM Dept. Drexel Univ. 7/14 11. You will see the new project 4s_updown_fdbkcntrl_C appears on the Project Explorer View window, and a new folder 4s_updown_fdbkcntrl_C is created in your workspace folder. Note that the target configuration file, EZDSPF28335.ccxml, which is automatically generated, and the linker command file, 28335_RAM_lnk.cmd, and a header files folder, C:/ti/ccsv5/tools/compiler/c2000_6.1.0/include, are already included in the project. Next, you ll add more files and headers to complete the project creation. 12. Add files to the project: Select Project Add Files, and look in the folder C:/tidcs/c28/DSP2833x/v131/CntrlDSP /4s_updown_fdbkcntrl_C and double click 4s_updown_fdbkcntrl_C.c to add it to the project. 13. Repeat step 12 to look in C:/tidcs/c28/DSP2833x/v131/DSP2833x_common/source and select DSP2833x_CpuTimers.c, DSP2833x_DefaultIsr.c, DSP2833x_EPwm.c, DSP2833x_PieCtrl.c, DSP2833x_PieVect.c, and DSP2833x_SysCtrl.c. 14. Also go to C:/tidcs/c28/DSP2833x/v131/DSP2833x_headers/source to add DSP2833x_GlobalVariableDefs.c to the project. 15. Repeat to find the assembly source files: DSP2833x_ADC_cal.asm, DSP2833x_CodeStartBranch.asm, and DSP2833x_usDelay.asm, in C:/tidcs/c28/DSP2833x/v131/DSP2833x_common/source and add them to the project. 16. Repeat to add the Linker Command File DSP2833x_Headers_nonBIOS.cmd to the project from C:/tidcs/c28/DSP2833x/v131/DSP2833x_headers/cmd. 17. Look at the Project Explorer View window to make sure there are two.cmd file, eight.c files, and three.asm files in the project folder 4s_updown_fdbkcntrl_C. 18. Next, you ll add three more header file folders to the project. Select Project Properties Include Options from the manual. In the lower-right pane of the Properties for 4s_updown_fdbkcntrl_C window, click the green arrow icon (Add) to pop up the Add directory path. 19. Press the button File System to search for the directory C:/ti/xdais_7_21_01_07/packages/ti/xdais then click the OK button. B.C. Chang, MEM Dept. Drexel Univ. 8/14
20. Repeat Step 19 again to add the following two header file folders to the project: C:/tidcs/c28/DSP283x/v131/DSP283x_common/include C:/tidcs/c28/DSP283x/v131/DSP283x_headers/include 21. The Project Explorer View window now appears as the following: 22. It is the time to modify the main C program 4s_updown_fdbkcntrl_C.c to include inp_graph(500) and rpm_graph(500) as described in the first paragraph of this section (Section 5A). 23. Then the project is ready for debug and compiling. 5B. Make hardware connections and open the CCSv5 project, 4s_updown_fdbkcntrl_C 1. Keep the connections as described in Sections 3 and 4. 2. Power on the ezdsp board after checking all connections are correct and secure. 3. Open the Texas Instruments Code Composer Studio v5 (CCS v5). 4. The pop-up CCS window will appear either in the CCS Debug prospective or in the CCS Edit prospective. You can click the button "CCS Edit" or "CCS Debug" on the upper right corner of the window to change the prospective back and forth. In the CCS Edit prospective, you can see the project files appear in the "Project Explorer" view. You can click the little triangle button on the left of the folder 4s_updown_fdbkcntrl_C to see the files inside the folder. Among these files, you can find the source file 4s_updown_fdbkcntrl_C.c. Double click it to open to see the source code. 5C. Debug, Build and Run the Project B.C. Chang, MEM Dept. Drexel Univ. 9/14 1. Select the project by clicking the 4s_updown_fdbkcntrl_C in the "Project Explorer" view. 2. Click on the green bug (debug button) on the tool bar. 3. The debugging process will do the following: (i) Save all open files in the project selected (ii) Build the selected project and create an executable file 4s_updown_fdbkcntrl_C.out, which appears in the folder Debug (iii) Automatically switched the CCS Debug Perspective. 4. The "Debug" view is now visible. (i) This view should always be open. Do not close it. If it is accidently closed, you can open it again using the "view debug" menu item. (ii) It allows you to connect the target device and control it (run, suspend, etc.) 5. Type the names of the registers on the Expressions view as shown at the top of the CCS window: EPwm1Regs.TBCTR EPwm1Regs.TBPRD EPwm1Regs.CMPA.half.CMPA EPwm1Regs.CMPB ECap1IntCount ECap2IntCount num_of_ints angle_deg ref_speed rpmnew ints_in_10ms CpuTimer0.InterruptCount inp_graph rpm_graph 6. Select "Run Load Load Program" to load the executable file 4s_updown_fdbkcntrl_C.out to the target device. 7. Use Real-Time Mode to observe continuous updates of the values of the above registers and variables in the Expressions View window. 8. In the program, 4s_updown_fdbkcntrl_C.c, you ll see the input ref_speed is a periodic function of time with a period of 5 seconds: 100 rpm in the first two seconds, then 200 rpm for the next three seconds. 9. In the program, you ll record the input as a function of time in inp_graph (500) and record the output values in rpm_graph(500). 10. Run Resume. 11. Observe the motion of the motor shaft, and the value changes of EPwm1Regs.CMPA.half.CMPA and rpmnew in the Expressions View window for at least 20 seconds. 12. Run Suspend. 13. In the Expressions View window, click the small white triangle sign on the left of in_graph to expose the content of in_graph, which is an array consisting of 500 values of speed_cntrl recorded over a 5 second period. After observing the content, click the triagle sign to hide the content. 14. Repeat Step 13 to observe the content of rpm_graph in the Expressions View window. 15. Use Graph of CCSv5.2 to plot inp_graph and rpm_graph. In the CCS Workbench Window, Tools Graph Dual Time.., then modify the pop-up Dialog window as follows. B.C. Chang, MEM Dept. Drexel Univ. 10/14
16. Click OK at the bottom of the Dialog window, graphical displays of in_graph and rpm_graph will appear in the CCS Window. 6. Discussions Discuss how well your mathematical model of the DC-motor matches the experimental results. Comment on the simple up-down feedback control scheme. If you have tried a varying update size approach, describe how the update size changes with the error and comment on the closed-loop performance of the system using the varying update size approach. Appendix A: ============================================================================= FILE: 4s_opnlpmodel_A.c This program is modified from 3s_opnlpcntrl_C.c, by B.C. Chang, Mishah U. Salman, Drexel Univ. on April 18, 2010 B.C. Chang, MEM Dept. Drexel Univ. 11/14 This program requires the DSP2833x/DSP2823x C/C++ Header Files V1.31, released by TI on August 4, 2009. ========================================================================== Observe the waveform of epwm1a and epwb1b on an oscilloscope or LabVIEW with DAQ card. EPWM1A is on GPIO0, ezdsp P8:pin9 EPWM1B is on GPIO1, ezdsp P8:pin10 Let the input be a periodic function of time with period 5 seconds: Record the input in inp_graph (500). Record the output in rpm_graph(500). Use Graph of CCS to plot inp_graph and rpm_graph. Use Watch Window to observe EPwm1Regs.TBPRD EPwm1Regs.TBCTR EPwm1Regs.CMPA.half.CMPA EPwm1Regs.CMPB ECap1IntCount ECap2IntCount num_of_ints angle_deg rpmnew ints_in_10ms CpuTimer0.InterruptCount speed_cntrl inp_graph rpm_graph DESCRIPTION: This example configures epwm1 for: * epwm1: Active high PWMs, Use Up Count Mode This example configures GPIO24 (ezdsp P8:pin33) as CAP1 This example configures GPIO25 (ezdsp P8:pin34) as CAP2 CONECTIONS: Connect the DC motor, Faulhaber 2230.G0003, with HEDS 5540 optical encoder, to JP20 of the H-Bridge board. Connect ezdsp P8:pins 9 and 10 to JP22 pins 3 and 4 of the H-Bridge board. Connect ezdsp P8:pins 33 and 34 to JP22 pins 1 and 2 of the H-Bridge board. Connect ezdsp P8:pins 39 and/or 40 to JP24 (GND pins) of the H-Bridge board. =============================================================================== Appendix B: =============================================================================== FILE: 4s_updown_fdbkcntrl_B.c This program is modified from 3s_opnlpcntrl_C.c, by B.C. Chang, Mishah U. Salman, Drexel Univ. on April 20, 2010 This program requires the B.C. Chang, MEM Dept. Drexel Univ. 12/14
DSP2833x/DSP2823x C/C++ Header Files V1.31, released by TI on August 4, 2009. ============================================================================== Observe the waveform of epwm1a and epwb1b on an oscilloscope or LabVIEW with DAQ card. EPWM1A is on GPIO0, ezdsp P8:pin9 EPWM1B is on GPIO1, ezdsp P8:pin10 Use Watch Window to observe EPwm1Regs.TBPRD EPwm1Regs.TBCTR EPwm1Regs.CMPA.half.CMPA EPwm1Regs.CMPB ECap1IntCount ECap2IntCount num_of_ints angle_deg rpmnew ref_speed ints_in_10ms DESCRIPTION: This example configures epwm1 for: * epwm1: Active high PWMs, Use Up Count Mode This example configures GPIO24 (ezdsp P8:pin33) as CAP1 This example configures GPIO25 (ezdsp P8:pin34) as CAP2 CONECTIONS: Connect the DC motor, Faulhaber 2230.G0003, with HEDS 5540 optical encoder, to JP20 of the H-Bridge board. Connect ezdsp P8:pins 9 and 10 to JP22 pins 3 and 4 of the H-Bridge board. Connect ezdsp P8:pins 33 and 34 to JP22 pins 1 and 2 of the H-Bridge board. Connect ezdsp P8:pins 39 and/or 40 to JP24 (GND pins) of the H-Bridge board. ========================================================================== Appendix C: ============================================================================= FILE: 4s_updown_fdbkcntrl_C.c This program is modified from 4s_updown_fdbkcntrl_B.c, by B.C. Chang, Mishah U. Salman, Drexel Univ. on April 20, 2010 This program requires the DSP2833x/DSP2823x C/C++ Header Files V1.31, released by TI on August 4, 2009. =============================================================================== Observe the waveform of epwm1a and epwb1b on an oscilloscope or LabVIEW with DAQ card. EPWM1A is on GPIO0, ezdsp P8:pin9 B.C. Chang, MEM Dept. Drexel Univ. 13/14 EPWM1B is on GPIO1, ezdsp P8:pin10 Let the reference speed input be a periodic function of time with period 5 seconds: Record the input in inp_graph (500). Record the output in rpm_graph(500). Use Graph of CCS to plot inp_graph and rpm_graph. Use Watch Window to observe EPwm1Regs.TBPRD EPwm1Regs.TBCTR EPwm1Regs.CMPA.half.CMPA EPwm1Regs.CMPB ECap1IntCount ECap2IntCount num_of_ints angle_deg rpmnew ref_speed ints_in_10ms CpuTimer0.InterruptCount inp_graph rpm_graph DESCRIPTION: This example configures epwm1 for: * epwm1: Active high PWMs, Use Up Count Mode This example configures GPIO24 (ezdsp P8:pin33) as CAP1 This example configures GPIO25 (ezdsp P8:pin34) as CAP2 CONECTIONS: Connect the DC motor, Faulhaber 2230.G0003, with HEDS 5540 optical encoder, to JP20 of the H-Bridge board. Connect ezdsp P8:pins 9 and 10 to JP22 pins 3 and 4 of the H-Bridge board. Connect ezdsp P8:pins 33 and 34 to JP22 pins 1 and 2 of the H-Bridge board. Connect ezdsp P8:pins 39 and/or 40 to JP24 (GND pins) of the H-Bridge board. ================================================================================ B.C. Chang, MEM Dept. Drexel Univ. 14/14