Home
inverted pendulum control - Introduction
Contents
1. 2 2 1 2 Project Aims and Objectives 2 0 000 0 2 1 3 Overview of the Project FN ee e ee eere eee e deme ea 3 1 4 Organisation of 2 ne nennen 4 CHAPTER 2 INVERTED PENDULUM 5 2 1 Pole Shaft and First 73 5 2 2 Two Phase bipolar stepper motar 2 9 6 2 3 L298 Full Bridge driver from National Semiconductor 44 7 2 4 HEDS 9140 Incremental Encoder From Hewlett Packard 11 2 4 1 HEDS 9140 Incremental Encoder Characterstics esee 11 2 4 2 HEDS 5140 Code 2 2 15 CHAPTER 3 Programming and configuration of the Z8 17 3 1 Overview and Configuration of Zilog 7 Encore MCU Conntroller 17 3 2 Contigurat in OT GP Owe ent E E Pee TR e RE den ceed reds 18 3 3 Configtgtiomof Interrupt Ene eee tei du e n end 23 3 3 1 Interrupt port for Inilialization 2 2 2 2 2 00 2 24 Ww Set Interrupt ee 25 3 3 3 Interru
2. 6 39 6 2 Budget Management 40 6 3 Equipments and resources used in laboratory 2 21 2 0 41 CHAPTER 7 Conclusion and Further work 2 2 2 42 T MConcl si n c oc etra m oe DEN 42 7 2 Acheivements e ee E EI RO ERR EAR RII 42 7 3 Overall Comment on this 43 7 4 Potenial Further work 2 2 1 44 7 4 1 Problems and 44 PAD Ert WODE en etae neues d e Ib d ed rae 44 REFERENCES Bibliography Appendix Shareef Mohd Aslam Inverted Pendulum Control iv ud Department of Electronic Communication and Electrical Engineering University of Hertfordshire GLOSSARY FIS Fuzzy Interference System GPIO General Purpose Input Output IC Integrated Circuit MCU Micro controller unit MF Membership Function PWM Pulse Width Modulation PID Proportional Integral derivative LED Light Emitting Diode PAOUT Port A Output PDIN Port D Input Shareef Mohd Aslam Inverted Pendulum Control Msc Final Year Project Report Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 1 INTRODUCTION In this chapter discussions w
3. FOR HEDS 3040 OPTION 3 99 0 150 4 INDEX PULSE e 0 20 POSITION TYPICAL 899 0 006 ALIGNING PINS 0 354 MAX 0 76 0 030 HIGH MAX MAX 2 44 2 41 0 096 0 095 DIA 23 36 mm 0 920 in 0 25 0 010 X 45 CHAMFER ii 2 PLACES DIMENSIONS IN MM INCHES Figure 6a HEDS 6140 Codewheel Used with HEDS 9040 i 3 2 56 SETSCREW 17 27 20 83 0 820 USE 0 035 HEX WR 0 18 0 680 21 0810 B30 Rot 843 lt t 0 332 E 5048 DIA OPTICAL CENTER 1 987 MAX M2 5 X 0 45 2 56 UNC 28 SETSCREW 3632 22 50 2 PLACES 1 430 0 886 36340143 2 36410151 be Rap 475 INDEX PULSE mn POSITION TYPICAL ARTWORK SIDE ARTWORK SIDE HEDM 6141 HEDM 6140 Figure 5 Mounting Plane Side A DIMENSIONS IN mm INCHE Figure 6b HEDM 614X Series Codewheel used with HEDS 9040 le 5 94 10 234 MOUNTING BOSS 25 7 1 01 1 80 0 0711 DIA MAX NI o 3 14 0 250 SETSCREW _ 10 16 10 400 12 70 INDEX PULSE MAX POSITION TYPICAL 22 56 SETSCREW USE 0 035 HEX WRENCH 3 58 0 141 Rop 11 00 mm 0 433 in DIMENSIONS IN MM INCHES 07900900000 Figure 7 HEDS 5140 Codewheel Used with 085 9140 Shareef Mohd Aslam Inverted Pendulum Control 58 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Appendix D Mechanica
4. Pole second link Shaft and First Link Motor Dual full bridge L298 motor driving IC Opto Coupler HEDS 9140 Incremental Encoder HEDS 5140 Code Wheel 2 1 Pole Shaft and First Link The First link on which Shaft is fixed 1s made of aluminium has a weight of 0 1Kg This link is mounted on the 2 phase bipolar stepper motor shaft and tightened with a screw The shaft to which the pendulum is attached is made of steel has a mass of 0 05Kg firmly fixed on the first link able to rotate freely but no axial movement with less friction Therefore two bearings are used to hold the shaft substantially with the first link The pole on the shaft is 25cm in length and 0 03Kg in mass approximately it is made of aluminium The one end of the pole is fixed on the shaft which gives the pole a 2 degree freedom of rotation either Left or Right rotates freely in vertical plane Furthermore there must be no movement between the shaft and the pole because the pole angle position and direction of the pendulum is measured by the incremental encoder whose code wheel is fixed on other end of the shaft Therefore two circular rings with nut is used to firmly fixed pole on the shaft Figure 2 1 shows the diagram of the pole and the shaft see Appendix D for Mechanical Drawings Bearings Shaft Encoder Circular Rings CodeWheel with nut First link Pole Figure 2 1 Pole Shaft and First Link Shareef Mohd Aslam Inverted Pendulum Control 5 ud Depart
5. Port Output PAOUT These bits contain the data to be driven out from the port pins The values are only driven if the corresponding pin is configured as an output and the pin is not configured for alternate function operation mm 7 s 2 x v FIELD POUT6 POUTS POUT4 POUT3 POUT2 POUTI POUTO COMME LN R W RW ADDR FD3H FD7H FE3H FE7H FEBH FEFH Table 3 3 3 PortA Output data sub registers 8 POUTx Port Output 0 Drive a logical 0 Low 1 Drive a logical 1 high High value is not driven if the drain has been disabled by setting the corresponding port output control register bit to 1 Where x indicates the specific GPIO Port pin number In my project motor has 4 leads hence the PAOUT is configured based on the energizing sequence of the 2 phase bipolar stepper motor winding I have chosen PAO 1 2 and as output pins of PortA If we want the 2 phase bipolar stepper motor to rotate in clockwise direction or anticlockwise then the corresponding pin is configured as an output Shareef Mohd Aslam Inverted Pendulum Control 21 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report For Clockwise For Anti Clockwise Case 1 First step Case 1 First step 0 05 PAOUT 00000101 0 09 00001001 Break Break Case 2 Second step
6. Incremental decoder co Figure 2 4 1 5 Diagrams show typical interface between Z8 controller and the channel optical Incremental Encoder module Problem Encountered and Solution HCTL 2016 2020 quadrature decoder counter is not compatible to Z8 controller it requires external clock with higher frequency than the Z8 controller which is quite difficult to achieve using the available equipments in the lab Hence this problem can be solved via software In year 2006 Kok Jiann Horng tried to interface between Z8 controller and incremental encoder via hardware approach that is using HCTL 2016 2020 quadrature decoder counter but he is fail to close the inverted pendulum hardware Hence this problem can be solved through software approach by using timers In Z8 controller we have counter option by using this we can count the number of pulses Hence there is no need to go for decoder counter circuit 2 4 2 HEDS 5140 Code wheel As mentioned earlier code wheel rotates between the emitter and detector causing the light beam to be interrupted by the pattern of spaces and bars on the code wheel The photodiodes which detects this interrupts are arranged in a pattern that corresponds to the radius and design of the code wheel From the data sheet 7 HEDS 5140 two and three channel code wheel optical encoder mode has the following characteristics 1 Resolutions from 96 CPR counts per revolution to 2048 CPR 2 Code wheel available in glass film
7. Project Report 47 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 0 00 else 0 0x01 if dir_switch 1 If reg174 reg1 1 j j else reg1 if reg1 1 reg1 4 j switch reg1 Pattern of energizing the motor windings 1 PAOUT 0x05 break case 2 PAOUT 0x06 break case 3 PAOUT 0x0A Shareef Mohd Aslam Inverted Pendulum Control 48 U Department of Electronic Communication and Electrical Engineering University of Hertfordshire break case 4 PAOUT 0x09 regl 0 break Msc Final Year Project Report MMIII SWITCH LOOP CLOSEDJ LOOP 8 1 1 7 WHILE LOOP CLOSEDY AIMMIIHHHIIITI LHII MAIN LOOP CLOSEDY PIIIITIIT WIMIMIMITITITI initializes the 7 void init p3ad void SET VECTOR P3AD isr p3ad SET VECTOR P3AD 18 p3ad PDADDR ALT FUN PDCTL 0x00 PDADDR DATA DIR PDCTL 0x28 IRQIEO 0x08 IRQIEI 0x08 IRQES 0x08 IRQPS 0x28 IRQCTL 0x80 interrupt service routine for P3AD pragma interrupt void p3ad void Shareef Mohd Aslam Inverted Pendulum Control 49 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire P
8. The HEDS 8905 and HEDS 8906 alignment tools are recommended for mounting the modules with Side B as the mounting plane The HEDS 8905 is used to mount the HEDS 9140 and the HEDS 8906 is used to mount the HEDS 9040 These tools fix the module position using the codewheel hub as a reference They will not work if Side A is used as the mounting plane The following assembly procedure uses the HEDS 8905 8906 alignment tool to mount a HEDS 9140 9040 module and a HEDS 5140 6140 codewheel Instructions 1 Place codewheel on shaft 2 Set codewheel height by placing alignment tool on motor base pins facing up flush up against the codewheel as shown in Figure 3 Tighten codewheel setscrew and remove alignment tool 3 Insert mounting screws through module and thread into the motor base Do not tighten screws 4 Slide alignment tool over codewheel hub and onto module as shown in Figure 4 The pins of the alignment tool should fit snugly inside the alignment recesses of the module ALIGNMENT TOOL b MODULE SIDE A 6 08 0 240 MODULE 6 90 0 272 SIDEB NOTE 1 copEWwHEEL N Msc Final Year Project Report 5 While holding alignment tool in place tighten screws down to secure module 6 Remove alignment tool Mounting with Aligning Pins The HEDS 9040 and HEDS 9140 can also be mounted using aligning pins on the motor base Hewlett Packard does not provide aligning pins For this configuration Sid
9. Case 2 Second step 0 06 00000110 PAOUT 0x0A PAOUT 00001010 Break Break Case 3 Third step Case 3 Third step PAOUT 0x0A 00001010 PAOUT 0x06 PAOUT 00000110 Break Break Case 4 Fourth step Case 4 Fourth step 0 09 PAOUT 00001001 PAOUT 0x05 00000101 Break Break Table 3 2 4 Energizing sequence for clockwise and anticlockwise I wrote this code in C programming and I have observed its output on the LEDS connected on the bread board in series with the RL 1000 resistance to avoid any damages to the LEDS Hence the LEDS are blinking in right sequence for both clockwise and anticlockwise as shown in below figure 3 2 5 Shareef Mohd Aslam Inverted Pendulum Control 22 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Z8 micro controller LEDS Resisters Figure 3 2 5 show the connection between Z8 controller and LEDS After testing this I have given this 4 pin output of PortA PA2 and and GND from 78 controller to L298 Full Bridge driver inputs input1 input2 input3 and input4 3 3 Configuration of Interrupt Interrupt requests IRQs allow device to suspend CPU operation in an orderly manner and force the CPU to start an Interrupt Service Routine ISR usually interrupt service routine is involved with the exchange of da
10. Pole amp ngle is zero and Angular __ velocity is Zero then Torque is Zero 1 2 If Pole amp ngle is zero and Angular velocity is PL then Torque is clockwise 1 3 If Pole Angle is PL and Angular velocity is Zero then Torque is Anti clockwise 1 4 If Pole Angle is PL and amp ngular X velocity is PL then Torque is Zero 1 5 If Pole Angle is zero and Angular__velocity is PH then Torque is amp nti clockwise 1 6 If Pole amp ngle is NH and Angular __ velocity is Zero then Torque is clockwise 1 and Then Angular velocity Torque is Connection Weight Oor and 1 Delete rule Add rule Change rule The rule is added Figure 4 2 2 Show the fuzzy rules 4 2 3 Defuzzification The defuzzifier takes the fuzzy interference system output and creates a single crispy output There are several defuzzification methods but probably the most popular one is the centroid technique It finds the point where a vertical line would slice the aggregated set into two equal masses Mathematically this centre of gravity COG can be expressed as 14 5 COG g Shareef Mohd Aslam Inverted Pendulum Control 34 Department of Electronic Communication and Electrical Engineering University of Hertfordshire Shareef Mohd Aslam Inverted Pendulum Control Msc Final Year Project Report EE 35 Department of Electronic Communic
11. Value PWM Output High Time Ratio 96 x 100 Reload Value For example if Reload value is FFFF the prescale value is set to 32 and system clock frequency of Z8 controller is 18 432MHz then the PWM period is 65536 x 32 PWM period 18432000 0 1137s 113 7 ms Figure 3 4 2 Timer 1 gt and Timer 2 gt Output waveform from oscilloscope Two pulses are created similar to the encoder module output that is 90 degree out of phase by giving delay between two timers as shown in figure 3 4 2 The phase difference between two timers can be adjusted by setting delay time Therefore by changing the PWM value in the Timer PWM High Low TXPWML Byte registers we can change the duty cycle of the modulated PWM pulse Shareef Mohd Aslam Inverted Pendulum Control 30 um Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 4 Fuzzy interference system FIS In this chapter discussion will be on Fuzzy Interference controller used to control the inverted pendulum hardware Discussions will be on creating fuzzy sets membership function fuzzy rules and design considerations 4 1 FIS introduction Fuzzy interference system is the process of mapping between given inputs to an output using the theory of fuzzy logic Fuzzy logic mimics the human decision making by using fuzzy rules with vague terms It represents expert knowledge wit
12. and cybernetics University of Hertfordshire lecture notes year 2007 Zilog application note A stepper motor controller using a ZILOG Encore MCU www zilog com Perminder singh thiara DSP based fuzzy logic controller for an inverted pendulum Final Year Report University of Hertfordshire April 2001 Anderson M J and Grantham W J Lyapunov Optimal Feedback Control of a Nonlinear Inverted Pendulum Journal of Dynamic Systems Measurement and Control Vol 111 pp 554 558 1989 Sheng Liu Lihui Cui Jie Chen and Ming Bai Research of Rotary Inverted Pendulum Using Fuzzy Strategy Based on Dynamic Proceedings of the 4 world congress on intelligent control and automation Shanghai P R China june 2002 Micheal Negnevitsky Artificial Intelligence A Guide to Intelligent systems first edition 2002 Lily Meng Neurofuzzy and cybernetics University of Hertfordshire lecture notes year 2007 Zilog product specification 78 encore 64K series High performance 8 bit microcontroller product specifications www zilog com Shareef Mohd Aslam Inverted Pendulum Control 45 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Bibligraphy 1 Chen Wei Ji Fang Lei and Lei Kam Kin Fuzzy logic controller for an inverted pendulum system proceedings of the IEEE International conference on Intelligent Proc
13. and metal Shareef Mohd Aslam Inverted Pendulum Control 15 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report TOOL ALIGNING RECESSES Three channel CODEWHEEL optical Shaft incremental MODULE SIDE B bipolar stepper Figure 2 4 2 1 Alignment tool is used to set height of the code wheel Assembly tools required for alignment Code wheel on HEDS 9140 Incremental encoder is for Centering and Gap Setting HEDS 8905 alignment tool is required shown in figure 2 4 2 1 Shareef Mohd Aslam Inverted Pendulum Control 16 ud Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 3 Programming and configuration of the Z8 controller In this chapter we will see how the Zilog Z8 Encore 78 64200100 MCU is programmed and configured to control the inverted pendulum hardware 3 1 Overview and Configuration of the Zilog Z8 Encore ZF642X MCU controller Specifications and main features of Zilog Z8 Encore Z8F64200100KIT MCU controller are as follows from Z8 Encore User Manual 8 20MHz eZ8 CPU Up to 64KB Flash Memory with in circuit programming capability Up to 4KB register RAM Seven 8 bit Ports A G and one 4 bit Port H general purpose input output GPIO pins 12 channel 10 bit analog to digital converter ADC Two full duplex 9 bit UARTs with b
14. input output GPIO As mentioned earlier the 64K series Z8 controller having seven 8 bit ports Ports A G and one 4 bit port Port H for general purpose input output GPIO Each pin is individually programmable for input or output operations Some bits of the ports can be configured for special functions such as interrupts timers and UARTS etc In this project two out of the eight ports are used 4 pins of the PortA are configured as output ports PAO 1 PA2 and and 2 pins of the PortD are configured as input ports P3AD and P5AD The first 4 pins of the port is connected to the L298 full bridge driver to control the direction and current applied to the 2 phase bipolar stepper motor and PortD pin P3AD 15 configured for special function that is for interrupt purpose an interrupt occurs when ever P3AD goes in high state the interrupt request allow device to suspend CPU operation and for CPU to start an interrupt service routine and hence an interrupt service routine code is executed during this period 2 pins of PortD are connected to the incremental encoder output Channel A and channel B Shareef Mohd Aslam Inverted Pendulum Control 18 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Four registers for each port provide access to GPIO control input data and output data Port A H Address and Control registers are used together to provide acce
15. radius of 11 00mm 0 433 from data sheet HEDS 9140 is an emitter or detector module Coupled with a code wheel this module translates the rotary motion of a shaft into a three channel digital output PHOTO DIODES PROCESSING SIGNAL CIRCUITRY PROCESSING CIRCUITRY EMITTER SECTION CODE DETECTOR SECTION WHEEL Figure 2 4 1 1 HEDS 9140 Block Diagram 6 If we look at the figure2 4 1 1 block diagram HEDS 9140 contains a single light emitting diode LED as its light source The light collimated into a parallel beam by means of a single polycarbonate lens located directly over the LED Opposite the emitter is the integrated detector circuit This IC consists of multiple sets of photo detectors and the signal processing circuitry necessary to produce the digital waveforms from data sheet Shareef Mohd Aslam Inverted Pendulum Control 12 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 24V 04v CH A 24 04v CH B AMPLITUDE ROTATION Figure 2 4 1 2 HEDS 9140 Output Waveform 6 The code wheel rotates between the emitter and detector causing the light beam to be interrupted by the pattern of spaces and the bars on the code wheel Photo diodes which detect this interrupt are arranged in a pattern that corresponds to the radius and design of the code wheel There detectors are placed in such a way that a light pe
16. shaft encoders and absolute encoders are available in market To avoid any friction on the shaft incremental encoders or the absolute encoders are the right choice because these encoders avoids any mechanical contacts required to know the pole angle position or the direction of the pole But in the market absolute encoders are too expensive compare to incremental encoders After looking so many encoders and the price of the encoders hence I decided to go for the following encoder HEDS 9140 three channel optical incremental encoder e HEDS 5140 Code wheel 2 4 1 HEDS 9140 nas the following characteristics listed below from the data sheet 6 See Appendix D for HEDS 9140 characteristics Two Channel Quadrature output with Index Pulse Resolution up to 2000 CPR counts per revolution Low Cost Easy to mount No signal Adjustment required Small size 40 C to 100 C Operating Temperature Shareef Mohd Aslam Inverted Pendulum Control 11 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report TTL Compatible e Single 5V supply voltage HEDS 9140 has two channel quadrature outputs waveforms out of phase in addition with a third channel index output This index output is a 90 electrical degree high true index pulse which is generated once for each full rotational of the code wheel HEDS 9140 is designed for use with a HEDS 5140 code wheel which has an optical
17. there stuff to move to some other place because renovation or construction is taking place in the manufacturing department John Wilmot helped me a lot he requested in manufacturing department and finally 1 got the inverted pendulum hardware After I get the inverted pendulum as I said earlier I said one issue how to fix the incremental encoder on one end of the shaft it has created a lot of trouble We have to look what is the best possible way to fix this encoder on the shaft finally we manage to fix the incremental encoder on the shaft I ordered the code wheel alignment tool but till the end of the project I haven t got it Software part was the biggest challenge for me because I don t know anything about the programming I have gone through C programming books to learn about C coding Dr David Lee helped me a lot in this software part and he explained me about the coding Finally at the end I wrote a program to run a 2 phase bipolar stepper motor Firstly I have tested this code on a breadboard and after seeing that the LEDs which are connected on the bread board are blinking in a correct sequence of pattern then I have giving this connections to the dual full bridge driver to run the motor Finally I have tested the stepper motor the 2 phase bipolar stepper motor changing its direction based on the 8 bit binary data presented to the stepper motor terminals for energizing the motor windings Furthermore the study and research on Z8 controller
18. to configure for this project is gone in much depth This Z8 controller configuration is also one of the challenging part for this project The suitable ports and pins have been chosen and assigned for particular purposes The control and sub registers for each port are studied to configure the Z8 encore controller for particular tasks like GPIO for receiving data and sending date from encoder to the stepper motor respectively timers to generate output waveforms which are very similar to the incremental encoder output and interrupts to know which channel is leading and which channel is lagging Finally the connections of the incremental encoder Z8 encore development board controller motor and PC has been established 6 3 Overall comment on this project Shareef Mohd Aslam Inverted Pendulum Control 43 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Even though FIS controller has not been developed and implemented on the real time inverted pendulum hardware By using a C code which is compiled and debugged in ZDS II C complier provided by the ZILOG Z8 encore development board 1 control the pole of the inverted pendulum hardware So finally we can say that for nonlinear systems like inverted pendulum can be controller by closing the loop of the system by using appropriate sensors like encoders FIS controller are quite reliable for this type of systems because just b
19. 00 Divide by 1 001 Divide by 2 010 Divide by 4 011 Divide by 8 100 Divide by 16 101 Divide by 32 110 Divide by 64 111 Divide by 128 Timer Input Output Polarity Operation of this bit is a function of the current operating mode of the timer Timer Enable Timer is disabled 1 Timer is enabled Figure 3 4 2 Timer Control 1 Register 8 Steps for configure a Timers for PWM mode Zilog user Manual 1 First Configure the 8 bit Timer control 1 register e Disable the timer Set the TPOL e Prescale value and e And configure the timer for PWM mode TxCTL1 01101101 2 Write the Timer High and Low Byte registers to set the starting count value 3 Write to the PWM high and Low Byte registers to set the PWM value 4 Write to the Timer Reload High and Low Byte registers to set the Reload value The Reload value must be greater than the PWM value 5 Configure the PortC pin for the Timer Output alternate function 6 Write the timer control 1 register to enable the timer The PWM period is calculated using the following equation Reload value x Prescale value PWM period s System Clock Frequency Hz The TPOL is set to 1 the ratio of the PWM output High time to the total period is calculated by the following equation Shareef Mohd Aslam Inverted Pendulum Control 29 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report PWM
20. 08 0 100 1 02 0 10 0 82 004020004 0 347 PTICAL 4752001 22 MA CES MOUNTING pom ELE LINE 0 187 0 004 0 096 0 095 1 85 0 073 HOLE 2 PLACES 1782010 546 0 10 2 16 0 085 0349 24u44ix279 00703 0 004 0 215 0 004 DE REF 0 096 0 095 X0 110 2 92 0 10 1 2 16 0 085 DEEP 0 115 0 004 dos 10 16 0 825 OPTICAL CENTER 0 400 6 35 0 250 REF TYPICAL DIMENSIONS IN SIDE A MILLIMETERS AND INCHES SIDE B Shareef Mohd Aslam Inverted Pendulum Control 55 uO Department of Electronic Communication and Electrical Engineering University of Hertfordshire Recommended Operating Conditions Parameter Temperature Supply Voltage Load Capacitance Count Frequency Shaft Perpendicularity Plus Axial Play Shaft Eccentricity Plus Radial Play Msc Final Year Project Report ww 00 00 0 010 0 04 0 0015 mm in TIR 30 eom 780 6 9 mm 0 27 in from mounting surface 6 9 mm 0 27 in from mounting surface Note The module performance is guaranteed to 100 kHz but can operate at higher frequencies For the HEDS 9040 T00 for operation below 0 C and greater than 50 kHz the maximum Pulse Width and Logic State Width errors are 60 e d Shareef Mohd Aslam Inverted Pendulum Control 56 Department of Electronic Communication and Electrical Engineering University of Hertfordshire Mounting with an Alignment Tool
21. 460 He had been very friendly and helped me with all my components ordering and he assisted me in building the project hardware This project couldn t be completed without him Also I would like to express my gratitude to my parents and all others who have shown a great deal of affection toward me through out my ordeals Without their support I wouldn t imagine myself in this position I would also like to thanks my brother and sisters for there encouragements and support Lastly a special thanks to all my friends for their support and enthusiasm and also i like to thank the following department and institutions 1 Manufacturing Department for there co operation University of Hertfordshire 2 The department of Electrical Electronics and Communication Engineering University of Hertfordshire for their co operation Shareef Mohd Aslam Inverted Pendulum Control ii Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report TABLE OF CONTENTS ABSTRACT e NA 4 i ACKNOWLEDGEMENTS 1 GLOSSARY iv CHAPTER 1 INTRODUGCTION e av e c 1 1 1 Project Background 0 41 2 1 1 1 1 Inverted Pendulum System 2 9 9 1 1 1 2 Inverted Pendulum System Modelling
22. MASTER OF SCIENCE DEGREE DEGREE WITH HONOURS IN Embedded Intelligent Systems Final Year Project Report Department of Electronic Communication and Electrical Engineering University of Hertfordshire INVERTED PENDULUM CONTROL Report by SHAREEF MOHD ASLAM Supervisor DR DAVID LEE Date SEPTEMBER 2007 DECLARATION STATEMENT I certify that the work submitted is my own and that any material derived or quoted from the published or unpublished work of other persons has been duly acknowledged ref UPR AS C 6 1 Appendix I Section 2 Section on cheating and plagiarism Student Full Name Mohd Aslam Shareef Student Registration Number 06144184 oce MUN Date 16 January 2008 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report ABSTRACT Inverted pendulum is an application of a Mechatronics Mechatronics means combination of different department mechanical engineering electronic engineering computer science control system and electrical engineering The two challenging inverted pendulum are arm driven and rotational system whose aim is to balance a pendulum on upright position using feedback control This report mainly describes how to close the inverted pendulum hardware loop using encoder Detailed working principles of each part or component used in this project are discussed Solutions for technical problems are discussed in det
23. ail How inverted pendulum hardware can be closed without using encoders by choosing some other alternate options like timers used to generate a pulses which is quite similar to the Incremental encoder module output waveforms for testing purposes A detailed description of how to configure and program a Z8 encore MCU Development board for a specific task like timers interrupts and GPIO port initialization are discussed The objective has been achieved in hardware the Z8 controller acts as a interface between host PC and inverted pendulum hardware to balance a pendulum in dynamic state Also this report focuses on the FIS logic controller fuzzy sets membership functions and fuzzy rules In the end discussion on project time budget management and project conclusions are made Some of the potential further works are highlighted in the report Shareef Mohd Aslam Inverted Pendulum Control Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report ACKNOWLEDGEMENTS Praises to God Almighty for the benefactions of his mercy to me all the time I wish to acknowledge the generosity and co operation of my project supervisor Dr DAVID LEE for his continued assistance and guidance towards successful completion of the project His superb guidance has leaded me on the way of leaming I would like to express my gratitude to Mr John Wilmot from the university workshop Lab C
24. am Inverted Pendulum Control Msc Final Year Project Report 52 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Appendix B Motor specifications Direct drive stepper motors 97 52 10Watts E 48 steps revolution 7 5 Absorbed power 10 W E 2 4 versions available e J Specifications 2 phases 4 phases Type 82 930 0 82 930 0 Number of phases 2 4 Electronic controller used Bipolar Unipolar per phase Q Current per phase Voltage at motor terminals V 0 75 6 6 0 48 10 4 82 930 002 is 0 81 6 0 39 12 5 82 930 015 am characteristics SE Absorbed _Absorbedpower W 0 10 Folding torque mN m torque mN m 8 155 Step angle 7 5 7 5 Positioning accuracy mm 5 5 Inertia of rotor 84 84 Max detent torque mN m 12 12 Max coil temperature C 120 120 Storage temperature C 40 80 40 480 Thermal resistance of coil ambient air C W 7 7 Insulation resistance at 500 MQ following NFC 51200 standard gt 10 gt 10 Insulation voltage 50 Hz 1 minute V following 51200 standard 600 600 Wires le mm 250 250 Weight 0 340 340 Protection rating IP40 IP 40 Product adaptations 9 W Special output shafts W Special supply voltag
25. ation and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 5 Implementation and testing In this chapter inverted pendulum hardware is tested The problems and difficulties faced for interfacing between sensor and Z8 controller are discussed 5 1 Incremental encoder module When I was trying to interface between Z8 encore controller and three channel incremental encoder module I faced a wiring problems Because the first link horizontal link which is directly connected to the 2 phase bipolar stepper motor shaft is rotating by 360 degrees I made the order for adjusting code wheel in incremental encoder but I haven t got it So there is a slip between the code wheel and the shaft which is giving a bit noisy or distortion in the output signal The output of the incremental encode is shown in figure 5 1 1 Figure 5 1 1 HEDS 9140 incremental output waveform from oscilloscope 5 2 Close the Inverted Pendulum Hardware The signals generated by the three channel incremental encoder are send to the Z8 encoder development board port Initially I was planned to go for timers which will count the incoming pulses generated by the encoder and gives me the pole angle pole position and velocity of the system Average velocity Position2 Positionl time Because of limited time period and technical problems I was unable to do calculation of the inverted pendulum system So finally I changed my mind to use inte
26. ause of technical problem as I said earlier I have to look for some other sort of resources That is instead of incremental encoder I used PWM to generate a pulses which is similar to the incremental encoder module Again I Shareef Mohd Aslam Inverted Pendulum Control 39 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report have to look for its specifications and configurations so I used another microcontroller to generate pulses which has typically increased the hardware complexity I spend some time in learning C language I learned different syntax of C language The software which is available in the electronic labs is not compatible to the Z8 controller development board so I have to install the appropriate software to interface between PC and Z8 controller 7 2 Budget Management This is another one of the challenging area for me MSc students are allowed to spend 60 budget for there projects For example If I am going for stepper motor and motor driver board it is only costing me around 55 and more However with the help of lab technician John Wilmot I manage to get hardware for my project Table 6 2 1 shows all the components used to build the inverted pendulum hardware Parts components Manufacturer Supplier Quantity x cost Zilog Encore Z8F64200100 Zilog UH Store 1x 34 99 development board Three channel Hewlett 1x 29 73 optical Pac
27. cc Rp INPUT OUTPUT figure 2 3 5 Test circuit for time response Shareef Mohd Aslam Inverted Pendulum Control 10 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report I have taken four opto couplers for four Z8 controller output pins Connection for the Opto coupler is shown in above figure 2 3 5 Output from the Z8 controller is connected to the anode terminal and all cathodes are connected to the Z8 controller GND Pin number 39 A 5V power supply is applied across Vcc terminal all base terminals are grounded and output from the emitter terminal is connected to the L298 Full Bridge driver When I am applying the rated supply voltage required by the stepper motor that is 12V to the L298 Full Bridge Driver IC the L298 IC is getting heated up which can damage the L298 Dual full bridge driver IC very easily Therefore a heat sink 1s attached to 1 298 Full Bridge Driver IC which absorbs the heat dissipated by the L298 IC Hence these avoid any damages or burns to L298 driver IC 2 4 HEDS 9140 Incremental Encoder from Hewlett Packard In inverted pendulum the measurement of pole angle position and direction of rotation with respect to the upright absolute zero position is very important If the accuracy of the system is good that is 1f we get the precise values of pole angle and position then the system is more the robust Several sensors like potentiometer
28. connector 2 2 sf is plugged cato the se sterface ia oi connector 1 for reference ANAT Shareef Mohd Aslam Inverted Pendulum Control 62 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Initialize the GPIO ports Configure the interrupt Canfionre the interrimt service rantine Compare the PortD 2 bit binary data when interrupt occurs Yes Read incremental No output if PDIN amp 0x20 dir_switch 0x00 dir_switch 0x01 Motor will Motor will rotate in rotate in Pendulum Shareef Mohd Aslam Inverted Pendulum Control 63
29. done to improve the performance of the system specially shaft which is fixed on the first link has to be changed to reduce the friction Design the FIS controller and implement this fuzzy interference system controller on the inverted pendulum hardware Learn how to interface between host PC and Z8 controller using Shareef Mohd Aslam Inverted Pendulum Control 44 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Reference l 2 Ye Zhang Inverted pendulum with ANFIS controller Project Report Master of Engineering University of Hertfordshire August 2005 Kok Horng Close the loop on the inverted pendulum hardware Project Report Master of Engineering University of Hertfordshire September 2006 T Yamakawa Stabilization of an inverted pendulum by a high speed fuzzy logic controller hardware system Fuzzy sets and systems Vol 32 2 pp 161 180 1989 Data sheet 2 Phase Bipolar Stepper Motor http www crouzet com catalogue_web int eng 293 Stepper motors Direct drive stepper motors ENG 1201 htm Data sheet L298 Dual Full bridge driver http www st com stonline products literature ds 1773 1298 pdfmcv Data sheet 5 9140 Incremental Encoder http www farnell com datasheets 6186 pdf Data sheet HEDS 9140 Code Wheel http www farnell com datasheets 16616 pdf Dr David Lee Neurofuzzy
30. e mechanical computer electronics electrical and control system in order to understand the fundamental and basic concepts The actual time plan was quite close to the initial plan proposed because of some technical and practical works there are some delays in time compare to the proposed time table 7 1 1 Extra time spend on selecting components and building inverted pendulum hardware I struggled a lot for selecting inverted pendulum components because of low budget When I was going for cheap components it is not compatible to the other components A lot of research and test have made I spend a lot of my project time on selecting the right components and building the inverted pendulum hardware There is lots of delay in getting my components Still I haven t got the code wheel alignment toolbox Design and build the inverted pendulum hardware Test the each part or component separately and then connect to the inverted pendulum hardware to avoid any damages I have designed the supporting structure for inverted pendulum 7 1 2 Extra time spend on programming configuring the Z8 encore microcontroller development board In the initial time plan the programming of Z8 controller is not included This is one of the biggest challenging and time consuming area A lot of time is spend on programming to interface between stepper motor controller and PC I have to look for C complier software provided by the ZDS II development board Again bec
31. e A must be used as the mounting plane The aligning recess centers must be located within the 0 005 in R Tolerance Circle as explained above Figure 5 shows the necessary dimensions ALIGNING RECESSES MODULE SIDE A MODULE SIDE 8 Figure 3 Alignment Tool is Used to Set Height of Codewheel Shareef Mohd Aslam NOTE 1 THIS DIMENSION 15 FROM THE MOUNTING PLANE TO THE NON HUB SIDE OF THE CODEWMHEEL Figure 4 Alignment Tool is Placed over Shaft and onto Codewheel Hub Alignment Tool Pins Mate with Aligning Recesses on Module Inverted Pendulum Control 57 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Mounting with Aligning Agilent does not provide aligning Radius Tolerance Circle as Pins pins For this configuration Side explained in Mounting The HEDS 9040 and HEDS 9140 A must be used as the mounting Considerations Figure 5 shows can also be mounted using plane The aligning recess centers the necessary dimensions aligning pins on the motor base must be located within the 0 005 32 56 SETSCREW CODEWHEEL 50 6 1 99 USE 0 035 HEX WRENCH 4 DIA MAX 11 4 Eh A Sas Ex I 10 175 MAX 3 12 0 123 SCREW 0 0 0 NOTE 1 399 0 187 MOUNTING PLANE 1 050 974 19 0 0 747 NOTE 1 THESE DIMENSIONS INCLUDE SHAFT END PLAY AND CODEWHEEL WARP MARKER NOTE 2 RECOMMENDED MOUNTING SCREW TORQUE IS 4 KG CM 3 5 IN LBS
32. enerate two Pulse Width modulation PWM externally using another Z8 controller in place of encoder temporarily because my hardware was not ready There were so many disturbances in the engineering department because of school renovation Therefore I generated the Pulse width modulation which 18 similar to the output of the three channel optical incremental encoder The Z8 controller has 4 internal timers they are Timer0 Timerl Timer2 and Timer3 Timer and Timer 2 are configured as PWM mode PWM signal are send from PCO PCO TIOUT and T2OUT to the main Z8 controller pins and PDS to read the output signal Shareef Mohd Aslam Inverted Pendulum Control 27 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report generated by the temporarily Z8 controller Used in place of encoder Each timer has 8 bit registers namely TxL Low Byte Register TxH High Byte Register TxRL PWM Low Byte Register TxRH PWM High Byte Register TxPWML PWM Low Byte Register TxPWMH PWM High Byte Register TxCTLO Timer Control 0 Register e TxCTLI Timer Control 1 Register Where x is the timer number 0 to3 buds ro SS cl SSS SS Timer Block Data Bus 7 gt Control Conr gt l 16 Bit Interrupt gt Reload Register PWM Interrupt Ti
33. es W Special cable lengths Special connectors Shareef Mohd Aslam Inverted Pendulum Control 53 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Curves 2 phases 4 phases 2 phases Max stopping starting Max stopping starting frequency and operating curves at constant curves as a function of the external PBL 3717 for 2 motor phases 9 inertia load at zero antagonistic Q Holding torque 150 mN m torque Tests at constant U Current per phase 0 53 A 0 200 750 1000 1250 1500 9 RPM RPM RPM 2phases Max stopping starting curves stopping starting curves Max stopping starting curves 4phases Max operating curves Inertia of measuring chain 3 4 g cm constant voltage controller with Rs resistance in series 0 b constant voltage controller with Rs resistance in series R motor c constant voltage controller with Rs resistance in series 2R motor d constant voltage controller with Rs resistance in series motor The measurements are made with full stepping 2 phases energised Dimensions Axe version D Version 1 DES Us 16 Version 2 635 1 1395 16 Version 3 6352 12 75 16 Xo 4205 2 Fixing holes 0 4 4 Connections 2 phases Step Step Energisation sequence for clockwise Energisation sequence for clockwise r
34. essing Systems Beijing China pp 185 189 October 1997 2 Mr James Driver and Mr Dylan Thorpe Design build and control of a single double rotational inverted pendulum Final year report of engineering The university of Adelaide school of Mechanical Engineering October 2004 3 Sigeru Omatu Michifumi Yoshioka Stability of Inverted pendulum by Neuro PID control with Genetic Algorithm IEEE 0 7803 4859 1 98 pp 2142 2145 1998 4 Zilog Technical note Using the GPIO pins of the Z8 Encore MCU TN002401 0304 www zilog com 5 BalaguruSamy Programming in Ansi C McGraw Hill Education march 2004 6 The Math Works Inc www mathworks com 7 C Programming www cprogramming com Shareef Mohd Aslam Inverted Pendulum Control 46 Department of Electronic Communication and Electrical Engineering University of Hertfordshire Appendix A C Program for Z8 Controller include lt ez8 h gt include port h HH definitions of Port define DATA_DIR 0x01 define ALT FUN 0x02 define OUT 0x03 WII Global Declarations int dir switch int reg0 reg1 void isr_p3ad void void init p3ad void main routine void main PAADDR ALT FUN PACTL 0x00 PAADDR DATA DIR PACTL 0x00 PAADDR OUT CTL PACTL 0x00 PAOUT 0x00 init p3ad while 1 double delay if reg0 0x00 Shareef Mohd Aslam Inverted Pendulum Control Msc Final Year
35. ew Fie Edi view FIS Variables Membership function plots Plot points 181 FIS Variables Membership function plots Plot points NL zero PL PH 1 NL Zero PL 1 12 14 input variable Angular velocity Current Membership Function click on MF to select Pole Angle Zero input pm i trimf 16867 105 1347 021 021 021 021 File Edi FIS Variables Membership function plots Plot points 181 Zero clockwise 8 10 12 output variable Torque Current Variable Zero output trimf 5 082 10 5 15 14 0211 E 1n Selected variable Torque b Output membership functions Figure 4 2 1 1 Memebership functions a Input membership functions and b output membership fucntions 4 2 2 Rule evaluation Shareef Mohd Aslam Inverted Pendulum Control 33 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report In this stage fuzzy interference system takes the fuzzified inputs and applies them to the fuzzy rule base If a fuzzy rule has multiple rules then fuzzy operator AND or OR is used to create a single number which represents the truth value of the fuzzy rule Some rules for the inverted pendulum is created and shown in below figure using MATLAB FIS editor Rule Editor Inverted pendulum control E Fie Edit view Options 1 If
36. h fuzzy sets The concept of fuzzy logic was proposed by Lofti Zadeh A professor at the University of California at Berkley Fuzzy logic can be implemented on hardware inverted pendulum software simulation or on both Fuzzy logic is simplest way of mapping between input and output The principle of fuzzy inference system is a list of if then statements called rules Before we build a system that interprets rules we have to define the linguistic variables pole angle angular velocity and torque and linguistic values low medium and high called membership function and fuzzy sets A fuzzy set can be simply defined as a set with fuzzy boundaries 13 Let X be the universe of discourse and its elements be denoted as x in classical theory crisp set A of X is defined by a function fa x called the characteristic function of A 13 fA x X2 0 1 Where _ fi if xe A xinh 0 if x amp A This function map universe of discourse X to a two elements For any elements of x of universe X fa x characteristic function is equal to 1 if x is an element of set A and equal to Zero if x is not an element of set A In fuzzy theory fuzzy set of universe X is defined by function pa x called membership function of set A 13 ua x Xo 0 1 Where p x 1 i x is totally in w x 0 if x is not in A 0 lt lt 1 i x is partly in Shareef Mohd Aslam Inverted Pendulum Control 31 U Department of Electro
37. he PortD Output Data Register is driven onto the port pin 1 Input The port pin is sampled and the value written into the portA Input Data Register The Output is tri stated Configure the data direction of 2 bits of PortD that is pin3 and pin5 by writing the desired configuration value to the control register So the 8 bit configuration value for the control register will be 00101000 0x28H 3 3 2 Set Interrupt priority The IRQ1 Enable High and Low bit registers form a priority Priority is generated by setting bits in each register How to set interrupt priority is shown in below table From Zilog User Manual IRQIENL x Priority Description IRQ1ENH x Shareef Mohd Aslam Inverted Pendulum Control 25 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report ee 57127 1 1 Level3 High Table 3 3 3 Priority configuration table Where x indicates the register bits from 0 through7 In my project interrupt is very important to know in which direction pendulum is rotating Hence i have chosen high interrupt priority that is Level3 by setting both Enable High and Enable Low bit registers of P3AD of PortD to 1 So the 8 bit configuration value of Interrupt request priority is IRQE will be 00001000 0x08 IRQIEO 0x08 IRQIEI 0x08 3 3 3 Interrupt Edge selection Register Interrupt edge selection register determines whether an inte
38. id a output PEIN 00 double delay PFIN 00 if PDIN PGCTL 00 PGIN 00 PDIN 0x20 reg 0 01 dir_switch 0x00 regl 0 04 AEN Z8 0x01 PHCTL 00 PHIN 00 dir switch 0 01 alad 0x00 controller R A2 0D R2 01 DD R4 00 RS 00 R6 00 R7 R8 00 R9 00 10 02 R11 52 di input R12 FB R13 1C R14 0E R1S F6 void double delay void FLAGS 28 RP E0 RRO 200 RR2 0100 RR4 0000 sint dd OxFFFF RR6 0043 RR8 0000 RR10 0252 RR12 FBlC RR14 0EF6 C 0 2 0 5 1 V 0 D 1 0 mE 01 0 U2 0 Bl portc X8 Encore Interface Driver Version 4 9 0 Allcopyright 2004 21106 Inc All Rights Reserved CPU Z8F642BA Target Z8F64200100KIT SERIAL On Chip Debugger OCD Revision 0x122 Smartcable Version 6 04 03 SystemClock 18432000Hz IPort COM1 Baudrate 57600 Loading IEEE 695 Absolute file G DOCUME 1 ECEE 1 C46 Desktop 22 08 1 COPYOF 2 portc lod SES T To debug A Find in Files Find in Files 2 Messages Command lls gt For Help press F1 Ln 83 Col 1 RUN CAP NUM READ Figure 5 2 1 Software for controlling Inverted pendulum Figure 5 2 1 and 5 2 2 shows how the values of the Z8 controller output Port A pin values are changing PAOUT with respect to the Z8 controller input PortD pins PDIN if PDOUT amp 0x20 1 dir switch 0x00 Shareef Mohd Aslam Inverted Pendu
39. ill be on project background project overview project aims and objectives 1 1 Project Background 1 1 1 Inverted Pendulum system Inverted pendulum system is widely used in automatic control systems Inverted Pendulum is a non linear unstable and multi variable system This project is mainly about rotational inverted pendulum hardware design control and fuzzy interference system FIS An inverted pendulum system typically consists of two links rotating about an axis First link driven by a stepper motor rotates in horizontal axis to balance a second link pendulum or pole which rotates freely in vertical axis The inverted pendulum system typically consists of four inputs pole angle pole position angular velocity and speed and single output torque By monitoring the current input values the controller generates an appropriate direction Clockwise or Anti clockwise of torque to the first link Horizontal link so that the second link pole can be balanced in the upright position as shown in figure 1 1 1 below Pole angle Pole or second link First link 2 phase bipolar Stepper motor Figure 1 1 1 Inverted Pendulum Shareef Mohd Aslam Inverted Pendulum Control 1 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 1 1 2 Inverted pendulum system modelling methodology Inverted pendulum system is one of the most common controlling methodo
40. incremental encoder output channel B If code wheel rotate in the direction of the arrow of the encoder module then channel A will lead the channel B otherwise channel B will lead the channel A One interrupt is enough to know which channel 15 leading and lagging 3 3 1 Interrupt Port Initialization Void init p3ad void SET VECTOR P3AD isr p3ad The interrupt request 1 IRQ1 register stores interrupt requests for both vectored and polled interrupts When a request is presented to the interrupt controller the corresponding bit in the IRQI register becomes 1 From Zilog User Manual Shareef Mohd Aslam Inverted Pendulum Control 24 ud Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report FIELD PAD7I PAD6I PAD4I PAD I PADII PADOI RESET R W ADDR Table 3 3 2 Interrupt Request port initializatioin 8 PADxI Either PortA or interrupt request 0 No interrupt request is pending for GPIO PortA or PortD 1 An interrupt request from GPIO PortA or PortD is awaiting service Where x indicates the specific GPIO Port pin number Firstly we have to initialize the PortD pin numbers 3 and 5 I am not using any alternate function of PortD that is timers UART or Watch Dog timer So the 8 bit configuration value of control register values 00000000 0x00H PDADDR ALT FUN PDCTL 0x00 PDADDR DATA DIR PDCTL 0x28 0 Output Data in t
41. kard Farnell incremental encoder module Three channel Hewlett Farnell Ix 15 14 Code wheel Packard L298 Dual Full National Ix 2 40 Bridge Driver Semiconductor Farnell Bearings 2x 3 78 Shareef Mohd Aslam Inverted Pendulum Control 40 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report HEDS 5140 code Hewlett Farnell 1x 6 46 alignment tool Packard 25 Pin IC socket for Z8 controller UH store pins 2 phase bipolar Crouzet stepper motor UH Store 1 1 1 1 1 pro uid NI on first link m i Table 6 2 1 Components and Cost Total Cost Supporting stand for Inverted pendulum UH Store Hardware with Pendulum 6 3 Equipments and Resources used in laboratory e Two power supply is used one for encoder 5V Opto coupler 5V and L298 Dual Full Bridge driver 12V ZDS II Z8 encore controller software for debugging compiling the C program An oscilloscope for waveform display Multimeter for testing circuit voltage and current Breadboards and wires for circuit connections Shareef Mohd Aslam Inverted Pendulum Control 41 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 6 Conclusions and further work This is the last chapter of the project report In this chapter Project conclusion and further potential work for this project a
42. l Drawings 2 Off required 100 eda 4 25 dia ef M drilled and tapped 2mm Mild steel 20 70 lt 375 di g imdrierence fi ee 7 a shown of ee and tapped 62 i 4 dia 1 5 e 3 ei H7 25 dia part A 10 d a 62 p Aluminium N drilled and T E 25 dia 10 e 10 dia 62 h Note not drawn to scale 2 Off required 2 Off required All dimensions in mm unless otherwise stated 20 SWG Aluminium Shareef Mohd Aslam Inverted Pendulum Control 59 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 2 Off required cama 100 25 dia TEN drilled and tapped 1 5mm Mild steel ET LLL paf A welded in cu 22 penwe un ernez drilled and tapped aT Eg 4 dia part A 10 dia e Shareef Mohd Aslam Inverted Pendulum Control 60 Department of Electronic Communication and Electrical Engineering Msc Final Year J l University of Hertfordshire Project Report Appendix E Schematics for the Z8 encore 64K MCU Development board Shareef Mohd Aslam Inverted Pendulum Control 61 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report slatfccm the Local LE m HEADER by pia we c
43. ler FLAGS 08 RP RRO 2059 RR2 DIES RR4 0000 RR6 0043 RR8 0000 RR10 02C2 RR12 FFOC RR14 0EF6 C 0 2 0 S 0 V 0 D 1 H 0 Ui 0 U2 0 T2CTL1 0x01 T2H 0x00 TZL 0x01 0x00 input TZRL 0x00 T2CTLl 0x81 H void isr timerl void xl n E porte Tm Ll 28 Encore Interface Driver Version 4 9 0 Copyright 2004 21106 Inc All Rights Reserved CPU Z8F642BA Target Z8F64200100KIT SERIAL On Chip Debugger O0CD Revision 0x122 Smartcable Version 6 04 03 SystemClock 18432000Hz Port COM1 Baudrate 57600 Loading 695 Absolute file G DOCUME 1 ECEE 1 C46 Desktop 20 08 1 COPYOF 1 portc lod LESESTE A Debug A Find in Files Find in Files 2 Y Messages Command Es For Help press F1 1n 76 Col 14 RUN NUM READ Figure 5 2 2 Software for controlling Inverted pendulum The test was completed successfully and I have demonstrated the close loop inverted pendulum hardware to my supervisor 7 Project Management Shareef Mohd Aslam Inverted Pendulum Control 38 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report In this chapter we will discuss the time management budget management and resources in the lab for the inverted pendulum control project 7 1 Time Management Inverted pendulum is a real time control system It need a lot of reading in different areas lik
44. logies in robotics industries and in control areas The inverted pendulum is famous because many variations of the system represent different kind of robotics arms and balancing A lot of research on control of inverted pendulum system using different methodologies has been done After reading technical papers I come to know that there are so many controllers to balance an inverted pendulum like PID controllers Fuzzy interference system Neuro fuzzy interference system and Adaptive Neuro fuzzy interference system In 2005 Ye Zhang build an Adaptive Neuro fuzzy interference system controller that to balance an inverted pendulum using cart and pole But he did not succeed in applying adaptive Neuro fuzzy on real inverted pendulum hardware 1 In 2006 Kok jiann Horng continued the incomplete project by Ye Zhang and tried to close the inverted pendulum hardware but he did not succeed in closing the inverted pendulum hardware 2 Yamakawa designed a high speed fuzzy controller hardware system and used only seven fuzzy rules to control the angle of an inverted pendulum 3 1 2 Project aims and objectives The overall aim of the project is to design build inverted pendulum hardware and develop a controller using FIS algorithm to balance an inverted pendulum system in non linear or multi variable state e To achieve this aim the following objectives must be accomplished e Do research and understand the basic components required by the inverted pendu
45. lum system e Study Zilog Z8 Encore 78 64200100 development board manual study the specification of Z8 Encore MCU and understand how to configure Z8 Encore amp for this particular project Design and build the inverted pendulum hardware and assemble all the components e Study and understand the fuzzy interference system FIS Learn how to create membership functions rules and construct the FIS controller under MATLAB using FIS editor Shareef Mohd Aslam Inverted Pendulum Control 2 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report e Learn C language and try to interface between motor and Incremental encoder by writing the program in ZDS II software C compiler provided by ZILOG Z8 Encore amp Z8F64200100KIT MCU software Dosimulation in MATLAB to achieve a successful FIS controller e Apply the FIS controller to the inverted pendulum hardware 1 3 overview of the project Computer 2 phase Z8 bipolar Fuzzy Inverted Encore amp Stepper interference pendulum system using MATLAB Incremental encoder Figure 1 3 Inverted Pendulum Block Diagram Inverted pendulum 1s an application of Mechatronics Mechatronics means combination of different department mechanical engineering electronic engineering computer engineering control system and electrical engineering Balancing of an inverted pendulum is a real time c
46. lum Control 37 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report else 1 dir switch 0x01 j Every time an interrupt occurs the controller sees the PD5 PortD pin 5 value if it low then the dir switch value is 0x00 means the motor rotates in clockwise direction and if PD5 value is high then dir switch is 0x01 hence the motor rotates in clockwise direction portc ZDS 1 Z8 Encore Family portc c portc c ee Edit View Project Build Tools Window Be eT amp mx Debug Sims 8 b Fd 1 ELO 91 EP D Ed Rl dep Ss m E M H WHILE 100 CLOSED Cd x Cy Project Fies 9 Group PORTS porth void init timerl void E at eben amp 0x42 E zsidevinit asm 0x00 External Dependencies 0 01 TIRH 0x00 TIRL 0x00 8 ll Z8 controller PCCTL 0x00 PCADDR 0 01 PCCTL 0x21 double delay output double delay SET VECTOR TIMERI isr IRQOENH 0x40 IRQOENL 0x40 IRQCTL 0x80 4 double_delay double delay Z8 ERES mE 01 R3 E8 TICTLl 0 2 R4 00 RS 00 R 00 R7 R8 00 R9 00 R10 02 11 2 void init timer2 void 2 1 0 14 0 RIS F6 control
47. ment of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 2 2 Two Phase Bipolar Stepper Motor 2 phase bipolar stepper motor is the source of energy for the first link From the data sheet 4 2 phase bipolar stepper motor has the following characteristics See Appendix B for Crouzet stepper motor data sheet Voltage at motor terminal 6 6V Current per phase 0 75A Resistance per phase 9 Step Angle 7 5 Absorbed Power 10W Holding Torque 180mN m Motor shaft ait 4 Figure 2 2 1 Stepper Motor 4 Figure 2 2 4 stepper motor connection 2 phase bipolar Stepper motor either rotates in clockwise or in anti clockwise based on the command that is energizing the various stepper motor coils in a particular sequence of pattern Each pattern causes the stepper motor to move in one step The wiring connections for the 2 phase bipolar stepper is shown in table 2 2 2 for clockwise and 2 2 3 for anti clockwise rotation Table2 2 3 Energizing Sequence Table 2 2 4 Energizing sequence Shareef Mohd Aslam Inverted Pendulum Control 6 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report For Clockwise For anti clockwise The above table s 2 2 3 and 2 2 4 shows the configuration of each of the four wires numbering from 1 to 4 and the two middle wires are Center tapped as shown in fig
48. mer Output Timer System Control Output Clock 16 Bit Counter p Timer with Prescaler Input gt 16 Bit PWM Compare Input E ee mand rami aed aes ed 4 Figure 3 4 1 Timer Block Diagram 8 The timer input is the system clock the timers count up to 16 bit PWM match value stored in TxPWMH and TxPWML byte registers When the timer count value matches the PWM value the timer output toggles If TPOL Timer input output polarity bit in the timer control 1 register is From Zilog manual e Set to 1 the Timer Output signal begins as High 1 and then transitions to a Low 0 when the timer value matches the PWM value The timer Output signal returns to a High 1 after the timer reaches the Reload value and is reset to 0001H e Set to 0 the Timer Output signal begins as Low 0 and then transitions to a High 1 when the timer value matches the PWM value The timer Output signal returns to a High 1 after the timer reaches the Reload value and is reset to 0001H Shareef Mohd Aslam Inverted Pendulum Control 28 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report D 7 D6 D5 D4 D3 D2 D1 DO Timer Mode 000 One Shot mode 001 CONTINUOUS mode 010 COUNTER mode 011 PWM mode 100 CAPTURE mode 101 COMPARE mode 110 GATED mode 111 Capture COMPARE mode Prescale Value 0
49. nic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 4 2 Design of fuzzy controller Input Rule Output p Inverted 4 Fuzzification Evaluation Defuzzifi Pendulum cation Fuzzy rule base Figure 4 2 1 Block diagram of Fuzzy logic controller Fuzzy interference system is basically divided into three steps they are e Fuzzification Rule evaluation and e Defuzzification 4 2 1 Fuzzification Fuzzifier takes the input variables based on that it will determine the fuzzy set and membership functions Here the input to the fuzzifier is pole angle angular velocity and output from the fuzzy controller is the torque The inverted pendulum can rotate in two directions either left or right Hence define the pole angle and angular velocity by defining the membership function for the fuzzy sets Negative high NH Negative low NL e Zero Zero Positive low PL Positive high PH Shareef Mohd Aslam Inverted Pendulum Control 32 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Similarly for toque Anti Clockwise AL e Zero Zero e Clockwise CL The fuzzy set and membership function for the input and output variables are shown figure 4 2 1 1 Membership Function Editor Inverted pendulum control Lj Membership Function Editor Inverted pendulum control File Edi vi
50. on of Z8 controller In this chapter discussions will be on Z8 controller programming and configuration Assign of GPIO Pins for data input and output Set up of interrupts and timer are outlined in detail Chapter 4 FIS controller design Design Fuzzy interference controller system Analyse the inverted pendulum hardware and build the fuzzy set membership functions and fuzzy rule to balance the inverted pendulum Chapter 5 Implementation and testing In this chapter the result of the output incremental encoder and how the Z8 controller output is changing based on the output values of the encoder Results of the close loop inverted pendulum 15 shown in this chapter Chapter 6 Power management In this chapter the time management budget management and resources for the inverted pendulum is discussed Chapter 7 Conclusion and further discussions This is the final chapter of the project report This chapter includes project conclusion summarizing all the important findings and achievements of this project and comments Potential further work for this project is highlighted Shareef Mohd Aslam Inverted Pendulum Control 4 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 2 Inverted Pendulum Hardware In this chapter all the major components of the inverted pendulum hardware are discussed in detail The major parts or components of the inverted pendulum hardware are
51. ontrolling Z8 Encore Z8F64200100KIT MCU is used to interface between software and the hardware Pole angle and position will be measured using three channel optical incremental encoder module output of the incremental encoder module is three waveforms Channel A Channel B and index Pulse This generated output waveforms are send to the Z8 Shareef Mohd Aslam Inverted Pendulum Control 3 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Encore amp Z8F64200100KIT MCU controller Z8 Encore amp controller looks which channel is leading and which channel is lagging based on that it will generate a write sequence of 8 binary data on its port for energizing the motor windings A dual Full bridge driver is used to change the direction of the stepper motor Figure shows the block diagram of the system 1 4 Organisation of report This report consists of 6 chapters listed below Chapter 1 Introduction This chapter gives an overview of the project project aims objectives and a brief format of the report organisation is presented Chapter 2 Inverted Pendulum Hardware In this chapter all the major components of the inverted pendulum hardware will be discussed in detail Design the frame work of the inverted pendulum and assemble them into a whole hardware structure What are the specifications of the each component or parts Chapter 3 Programming and configurati
52. otation viewed shaft end rotation 2 phases energised viewed shaft end front forward Commons connected to positive Shareef Mohd Aslam Inverted Pendulum Control 54 Department of Electronic Communication and Electrical Engineering University of Hertfordshire Msc Final Year Project Report Appendix C HEDS 9140 incremental encoder and code wheel specifications Three Channel Optical Incremental Encoder Modules Technical Data Features Two Channel Quadrature Output with Index Pulse Resolution Up to 2000 CPR Counts Per Revolution Low Cost Easy to Mount No Signal Adjustment Required Small Size 40 C to 100 C Operating Temperature TTL Compatible Single 5 V Supply Package Dimensions HEDS 9040 HEDS 9140 Description The HEDS 9040 and HEDS 9140 series are three channel optical incremental encoder modules When used with a codewheel these low cost modules detect rotary position Each module consists of a lensed LED source and a detector IC enclosed in a small plastic package Due to a highly collimated light source and a unique photodetector array these modules provide the same high performance found in the HEDS 9000 9 100 two channel encoder family 8 6 0 34 0 63 0 025 29222 2 54 0 100 59886 1 52 0 060 18 OPTION CODE 1 0 0 04 0 07 5 1 0 20 DATE CODE 221 4 3732005 0 087 254 om 0 147 0 002 2
53. pt Edge Selection Register 2 2 0 0 26 3 34 Interr pt Port Select eoe Ege eso tene Ne ese i tes 27 3 4 Configuration 2 eme sense se e e e eher 27 CHAPTERA Fuzzy Interference System 2 e eene 31 A TRIS Introduction coo certet era ERR ER ES REG REA RARE QU nU EIS 31 4 2 Design of Fuzzy 2 eese he eme 32 Shareef Mohd Aslam Inverted Pendulum Control iii U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report 42 1 F zzifiCatlon odit pt eiae de rr rediere tutes 32 42 2 Rule Evaluation e RE NE A ee 33 4 2 3 Defuzzification esee de eee 34 CHAPTER 5 Implementation and Testing 2 2 36 5 1 Incremental Encoder Module 2 9 36 5 2 Close Inverted Pendulum Hardware 2 2 36 CHAPTER 6 Project Management 4 39 6 1 Time 2 2 9 292 39 6 1 1 Extra time spend on selecting components and buillding inverted pendulum hardware 23 ote nO en RE 39 6 1 2 Extra time spend on programming configuring the Z8 encore Microcontroler development board
54. put Configure PortA as output Alternate Functions I am not using any alternate functions of PortA like timers UARTs or I2C of PortA So the 8 bit configuration value for the control register will be 00000000 0x00H PAADDR ALT FUN PACTL 0x00 Data Direction If 01H in Port A H Address Register accessible through Port A H Control Register Table 3 2 1 Data Direction Sub Registers 8 0 Output Data in the PortA Output Data Register is driven onto the port pin 1 Input The port is sampled and the value written into the portA Input Data Register The Output is tri stated I am configuring PortA as Output so the 8 bit configuration value for the control register will be 00000000 0x00H PAADDR DATA DIR PACTL 0x00 Output Control R W R W ADDR If 03H in Port A H Address Register accessible through Port A H Control Register Shareef Mohd Aslam Inverted Pendulum Control 20 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Table 3 2 2 Port Output Control Sub Registers 8 0 drain enable 1 drain disable Here drain values for all the ports are enabled So the 8 bit configuration value for control register will be 00000000 0x00H Otherwise high value is not driven if the drain has been disabled by setting the corresponding port output control register bit to 1 PAADDR OUT PACTL 0x00
55. re highlighted 6 1 Conclusion The aim of the project is to design build and implement FIS to the inverted pendulum hardware to balance a pole in upright position inverted pendulum hardware is successfully built I have closed the inverted pendulum loop and I have tested this hardware I observed how the direction of the inverted pendulum is changing based on the direction of the inverted pendulum to balance the pole in upright position basic idea of this control system is using a Z8 encore microcontroller which acts as an interface between inverted pendulum hardware and PC software dynamically changing inverted pendulum variables pole angle position and direction which are obtained from incremental encoder are send to the PC and simultaneously the output generated by the PC using C programming in ZDS II Z8 encore software is given to the Z8 encore controller which will generate the 8 bit binary data for the stepper motor Based on this 8 bit binary data stepper motor will rotate in either forward or backward direction by giving the desired movement to the first link the pendulum which is linked to this first link 1s kept on the upright position 6 2 Achievements Because of time limit technical problems limited resources and practical problems this project is partially completed Even though I tried my best to complete and at the beginning everything was going smoothly but at the end of the project my hardware
56. ridge is driven by four gates the input of which are In1 In2 EnA and In3 In4 EnB Therefore EnA and EnB pins are connected to the 5V power supply Vss supply voltage for the logic blocks is connected to the 5v supply To drive 2 phase bipolar stepper Shareef Mohd Aslam Inverted Pendulum Control 9 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report motor we require two H bridges therefore enable both Enable inputs EnableA and EnableB Otherwise the L298 Dual Full Bridge IC will not drive the 2 phase bipolar stepper motor Problem encountered and solution The voltage on the Z8 controller pins are 3 3V but the minimum voltage required by the L298 full bridge driver is 4 5 V Hence optocoupler is used to increase the voltage 6 5 4 1 6 ANODE 0 BASE CATHODE 5 5 5 COLLECTOR 4 1 2 3 Figure 2 3 3 Functional Diagram Figure 2 3 4 Schematic Diagram Anode Cathode Not connected Emitter Collector Base 4N25 Optocoupler used in this project It contains a light emitting diode optically coupled to a photo transistor as shown in above figure 2 3 4 From the data sheet fJ it has the following characteristics Feature 1 Current transform ratio CTR min 20 at IF 10 mA 10V 2 input output isolation voltage Viso 22500 Vrms 3 Response time tr typ 3us at VCE 10 IC 2mA Rr 1000 V
57. ring Msc Final Year J l University of Hertfordshire Project Report Input3 and input4 TTL compatible inputs of the bridge B Output and Output2 Outputs of the bridge Outputs3 and Outputs4 Outputs of the bridge B GND Ground SenseA and SenseB Between this pin and ground is connected the sense resistor to control the current of the load Enable A and Enable B TTL compatible Enable input 9 VSS Supply voltage for the logic Blocks A 100nF capacitor must be connected between the pin and the ground e Figure 2 3 2 shows the connection between the L298 Full bridge driver IC Z8 controller and the 2 phase bipolar stepper motor PAO PA2 and are the outputs from the Z8 controller of PortA are connected to the L298 full bridge driver Input1 Input2 Input3 and Input4 respectively The four wiring of the 2 phase bipolar stepper motor is connected to the L298 Full bridge driver Outputs output1 output2 output4 respectively The L298 Full bridge driver IC is powered by a separate 12V power supply PA1PA2 5V 12V GND i 2 2 1 4 4 C Ge 5 2 SSS 1 Stepper E Motor Figure 2 3 2 Connection between L298 IC Z8 Controller and Motor Diodes D1 D2 D8 are used to protect the L298 full bridge driver IC Because in inductive loads current flow from load to source when a motor accelerates or decelerates for any reason These reve
58. riod on one pair of detectors corresponds to a dark period on the adjacent pair of the detectors Because of this integrating phasing technique the digital output of channel A is in quadrature with channel B 90 degree out of phase as shown in figure below 2 4 1 2 from data sheet If the code wheel rotates in the direction of the arrow on the top of the module then Channel A will lead the Channel B by 90 If the code wheel rotates in the other direction that is opposite to the arrow on the top of the module then Channel B will lead the Channel A by 909 As shown in below figure 2 4 1 3 Shareef Mohd Aslam Inverted Pendulum Control 13 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Figure 2 4 1 4 HEDS 9140 Channel 1 gt and channel B 2 gt Output waveform from Oscilloscope Figure 2 4 1 4 Pull up resistors on HEDS 9140 encoder output 6 To ensure reliable encoding performance HEDS 9140 three channel optical incremental encoder module require 2 7K pull up resistors on output pins 2 3 and 5 that is on Channel A Channel B and channel index output as shown in above figure 2 4 1 4 Shareef Mohd Aslam Inverted Pendulum Control 14 ud Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report HEDS 9140 A HCTL Three 2016 2020 EN controller Channel quadrature
59. roject Report 0 0x01 if PDIN PDIN amp 0x20 dir switch 0x00 Motor will rotate in anti clockwise direction j else dir switch 0x01 Motor will rotate in clockwise direction j j provides delay void double delay void int dd OxFFFF while dd dd Code for generating Pulses using Timerl and Timer2 include lt eZ8 h gt include lt stdio h gt void init timerO void void init timerl void void main PAADDR 0x02 PACTL OxFF PCADDR 0x02 PCCTL OxFF init timerO Shareef Mohd Aslam Inverted Pendulum Control 50 U Department of Electronic Communication and Electrical Engineering University of Hertfordshire init timerl TOCTL 0x80 while 1 void init timerO void 1 OxFB 0 00 TOL 0x01 TOPWMH 0x80 TOPWML 0x00 TORH 0x00 TORL 0x00 deb_delay deb_delay TOCTL1 0x3C void init_timer1 void OxFB T1H 0x00 TIL 0x01 TIPWMH 0x80 TIPWML 0x00 0x00 TIRL 0x00 0x3C deb_delay deb_delay void deb delay Shareef Mohd Aslam Inverted Pendulum Control Msc Final Year Project Report 51 U Department of Electronic Communication and Electrical Engineering University of Hertfordshire int dd OxFFFF while dd dd j Shareef Mohd Asl
60. rrupt is generated for the falling edge or rising edge on the selected GPIO port input pin Table 3 3 4 interrupt Edge Select Register 8 IESx Interrupt Edge Select x 0 An interrupt request is generated on the falling edge of the PDx input 1 An interrupt request is generated on the rising edge of the PDx input Where x indicates the specific GPIO Port pin number Shareef Mohd Aslam Inverted Pendulum Control 26 um Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report Here I have chosen interrupt request on rising edge So the 8 bit configuration value of Interrupt edge select register IRQES will be 00001000 0x08 IRQES 0x28 3 3 4 Interrupt Port Select The interrupt port select register determines the port pin that generates interrupts This register allows either PortA or PortD pins to be used as interrupts RESET 0 Table 3 3 5 interrupt Port Select Register 8 PADxS PAx PDx Selection 0 PAx is used for the interrupt for PAx PDx interrupt request 1 PDx is used for the interrupt for PAx PDx interrupt request Where x indicates the specific GPIO Port pin number I have chosen PortD for Interrupt request So the 8 bit configuration value for the interrupt select port register IRQPS will be 00101000 0x28H IRQPS 0x28 3 4 Configuration of Timer The internal 1 and Timer2 is used in this project to g
61. rrupts because if we look at the incremental encoder output waveforms they are in quadrature approximately 90 Shareef Mohd Aslam Inverted Pendulum Control 36 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report degree out of phase mean if channel A leading channel B then the motor will be rotate in clockwise direction and if channel A lagging channel B then the motor will rotate in anti clockwise direction Therefore one interrupt is enough to know which channel is lagging and which channel is leading So I wrote an interrupt service routine code which will simply look the 2 bit binary data on Z8 controller PortD based on that it will rotate the 2 ph bipolar stepper motor Here I have chosen PortD pins 3 and 5 for Z8 controller input I have chosen pin3 for interrupt portc ZDS II Z8 Encore Family 1 portc1 c Edt view Project Buld Tools Window Help amp x pb Desusx eseuerela gt P Ee ES EB EO Bs Rl Ce amp ES RJ mi 4 PDADDR DAT DIR 1 Files B 0 28 Group PORTS Bl port h IRQIEO 0x08 IRQlEl 0x08 IRQES 0x28 M z IRQPS 0x08 E zsidevinit asm 5 TROCTL 0 80 External Dependencies gt 2 78 contr oller pragma interrupt PDIN 28 void isr p3ad vo
62. rse current can damage the L298 full bridge driver IC Hence 2A fast Shareef Mohd Aslam Inverted Pendulum Control 8 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report diodes are used to protect the L298 IC from reverse current coming from the load to source by turning ON when the reverse current exceeds it limit L298 integrates two power output stages The power output stage is a bridge configuration and its output is used to drive a 2 phase bipolar stepper motor depending on the states of the input Two Enable Enable A and Enable B inputs are provided to enable or disable the device independently of the input signals If inputl is high and input2 is low then the current flow from output to output2 and if input is low and input2 is high then current flow from output2 to output respectively Similarly if input3 is high and input4 is low then current flow from output3 to output4 and if input3 is low and input 4 is high then current flow from output4 to output3 respectively as shown in figure 2 3 2 Figure 2 3 2 Block Diagram of L298 Dual Full Bridge Driveri The current that flows through the load comes out from the bridge at the sense output an external resistor RSa RSs used to detect the intensity of this current Hence it is very important to connect sense resistors RSa RSs of 0 5Q to pins 1 and 15 to a ground as shown in figure 2 3 2 above Each b
63. ss to sub registers for port configuration and control from user manual 664 99 Replace x with A H accordingly Port Register Mnemonic Port Register Name PxADDR Port A H sub registers select sub PxCTL Port A H Control Register Provides access to sub registers High Drive Enable PxSMRE STOP Mode Recovery Source Enable Table 3 2 1 GPIO Port Registers and Sub Registers 1 PxADDR is the address register used to select port sub registers Three port sub registers that are used in this project are e FUN Alternate function sub register Used to configure a certain bits of a certain port as alternative function e DATA DIR Data direction sub register Used to configure port pins as input or output e OUT Output control sub register Used to enable or disable the port drain 2 PxCTL is the control register if the address register is used to select a sub register then the control register is used to configure a sub register 3 PxIN is the input register 8 bit input data is stored in this register when a GPIO port is set as input Input data register are Read Only 4 PxOUT is the output register 8 bit output data 15 stored in this register before sending out from output GPIO ports Shareef Mohd Aslam Inverted Pendulum Control 19 ud Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report In my project I have chosen Port A as out
64. ta control information and status information between the CPU and the interrupting device When the Interrupt service routine is completed CPU returns to the operation from which it was interrupted Interrupt controllers support three levels of interrupt priority shown in below figure 3 3 1 From Zilog user manual Level3 is the highest priority Level2 is the second priority and Levell is the lowest priority If all the priorities are enabled with identical interrupt priority then interrupt priority would be assigned from highest to lowest Shareef Mohd Aslam Inverted Pendulum Control 23 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report High Port Interrupts Priority Vector Priority Medium Mux Priority IRQ Request Internal Interrupts Low Priority Interrupt Request Latches and Control Figure 3 3 1 Interrupt controller Block Diagram 8 In Z8 controller the ports support interrupts they are PortA PortC and PortD I have chosen PortA for energizing 2 phase bipolar stepper motor I have chosen PortD for interrupt in my project Configure PortD for interrupt 2 bits of PortD are used to read the output signal from the incremental encoder channel and channel B Here I have chosen Pin3 and 5 of PortD as an input to the Z8 controller Pin3 is connected to the incremental encoder output channel and pin5 is connected to
65. ure 2 2 2 2 3 L298 Full Bridge driver from National Semiconductor L298 Dual Full Bridge driver is a two H bridge back to back connected IC used in this project to change the direction of the 2 phase bipolar stepper motor Direction of the stepper motor is decided based on how the wirings or the terminals of the 2 phase stepper motor are energized From the data sheet 5 L298 Full Bridge driver has the following characteristics See Appendix C for electrical characteristics Operating supply voltage up to 46V Total DC current up to 4A TTL compatible inputs Over temperature protection Low saturation voltage Logical 0 input voltage up to 1 5V High noise immunity Based on the information from the date sheet 5 we briefly look into the function of the pins of the L298 Full Bridge Driver IC The pin layout of the L298 are shown in figure 2 3 1 CURRENT SENSING B OUTPUT 4 OUTPUT 3 INPUT 4 ENABLE B INPUT 3 e 9 LOGIC SUPPLY VOLTAGE Vas ultiwatt15 2 GND 7 INPUT 2 ENABLE A 5 INPUT 1 SUPPLY VOLTAGE V eo 3 OUTPUT 2 2 OUTPUT 1 1 CURRENT SENSING A P TAB CONNECTED TO PIN 8 DSSIN240A Figure 2 3 1 Pin Connections of the L28 Full Bridge IC Pin Functions used in the project 1 Vs Supply voltage for the power output stages 2 Inputland Input2 TTL compatible inputs of the bridge A Shareef Mohd Aslam Inverted Pendulum Control 7 Department of Electronic Communication and Electrical Enginee
66. us transceiver Driver Enable Control Dc Serial Peripheral Interface Two Infrared Data Association IrDA compliant infrared encoder decoders Up to four 16 bit timers with capture compare counter and PWM capability Watch Dog timer WDT with internal RC oscillator 3 channel DMA 24 interrupts with configuration priority On chip Debugger Power On reset POR 3 0 3 6V operating voltage with 5V tolerant inputs Below figure 3 1 1 shows a diagram of the 78 Encore Z8F64200100KIT MCU controller For convenience purpose Zilog Z8 Encore Z8F64200100KIT MCU is know called as Z8 controller in this project report Among the many features only certain features of the Z8 controller are used in this project such as GPIO ports Interrupts and Timers Shareef Mohd Aslam Inverted Pendulum Control 17 U Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report TEST JP1 P1 Console JP2 Figure 3 1 1 Z8 Encore 64K serial MCU development board 8 In this project Z8 controller works as a interface between the PC software programming and the hardware inverted pendulum The 78 controller read the signals from the incremental encoder on one of the GPIO ports and sends them to PC as input data and then according to the output data from PC the Z8 controller will generate the PWM signal for the 2 ph bipolar stepper motor 3 2 Configuration of general purpose
67. was not ready because of so many disturbances in the university The frame for the inverted pendulum is designed and build This has taken plenty of time and one more issue is fix the incremental encoder shaft which is directly connected to the pendulum Practical work consumes a lot of time because everyday a new problem arises For example when i was trying to interface between Z8 controller and H bridge the output voltage on the Z8 controller is not sufficient for L298 dual full bridge IC to drive 2 phase bipolar stepper motor Hence Opto coupler are used to increase the voltage Finally I completed the inverted pendulum hardware and I have tested this hardware I have seen how the 8 bit of the Z8 controller are changing based on the inverted pendulum angle which are obtained through Shareef Mohd Aslam Inverted Pendulum Control 42 Department of Electronic Communication and Electrical Engineering Msc Final Year University of Hertfordshire Project Report the incremental encoder and send to the Z8 microcontroller GPIO pins Finally the inverted pendulum hardware is build and tested I have generate the two output waveforms pulses using two timers which are very similar to the incremental encoder output and I have calculated the pulse width modulation period in the mean time when my hardware was not ready because the manufacturing department said they are not going to complete my hardware supporting structure because they have packed
68. y closing the loop of the inverted pendulum we cant get the desired position of the inverted pendulum in non linear state 6 4 Potential Further Work 6 4 1 Problems and Difficulties Inverted pendulum hardware is completely built but the only problem in this hardware is the friction between the first link and the shaft As I said earlier manufacturing department was 18 in so hurry that they just build the hardware Even though I used the bearing I was unable to reduce the friction between shaft and link I think it will be fine if we change the shaft rod because the shaft rod is not smooth I mean it has got some rough surface bends Although the inverted pendulum hardware is tested using C programming compiled and debugged in ZDS II C compiler But still I am not sure these coding work properly therefore if required try to modify the program 6 4 2 Further work The performance of the inverted pendulum is limited by the low budget If a further work in this area is required then following things have to changed Instead of incremental encoder I will prefer the absolute encoders which give me the exact position of the shaft in one rotation No need to count the pulses for calculating the pole position Which will substantially decreases the burden on processor Z8 controller performance or hardware complexity if we are using increment decoder counter Although inverted pendulum hardware 15 completed but still some modification have to be
Download Pdf Manuals
Related Search
Related Contents
SNシリーズ シ リ ン ダ Copyright © All rights reserved.