VISVESVARAYA TECHNOLOGICALUNIVERSITYJnanaSangama, Belgaum-590014A Project ReportOn“Closed Loop Motor Control using Attitude Heading ReferenceSystem”Submitted in Partial fulfillment of the Requirements for VIII semesterBachelor of EngineeringinElectronics & Communication EngineeringByESHAAN KUMAR 1AR09EC015TEJAS S 1AR09EC043SHILPA S 1AR09EC032Under the Guidance ofMrs. PADMAJA VIJAYKUMARAssistant Professor, Dept. of ECEAIeMSDEPARTMENT OF ELECTRONICS AND COMMUNICATIONENGINEERINGAMRUTA INSTITUTE OF ENGINEERING &MANAGEMENT SCIENCESNear bidadi industrial Area, Bengaluru-562109
ACKNOWLEDGEMENT“The satisfaction and euphoria that accompany the successful completion of any task would beincomplete without the mention of the people who made it possible, whose constant guidanceand encouragement crowned my effort with success.”I am extremely thankful to Aeronautical Development Establishment (ADE) andAmruta Institute of Engineering & ManagementSciences (AIeMS) with its ideals andinspirations for having provided me with the facilities, which made my project a success.I earnestly thankMr. P.S.KRISHNAN, director, ADE and Dr.A.PRABHAKAR,Principal, AIeMS, for providing me with congenial environment to work in, that helped incompleting this project.I express my sincere thanks to Mr. A.M.G PILLAI Sc „F‟, Head, MST Division,ADE and Mr. C.R.RAJAGOPAL, HOD, ECE, AIeMSfor their encouragement throughoutthe demure of the project.I express my heart full gratitude to my project guide Mr. R.SRINIVASANSc „F‟,MST Division, ADE and college Internal guide Assit.Prof. PADMAJA VIJAYKUMAR,ECE, AIeMS for their able guidance and valuable advice at every stage of my project, whichhelped me in the successful completion of the project.I express my gratitude to Mr. G.S.RAVINDRAN Sc „F‟, HRD, ADE for hisencouragement throughout the project.I wish to express my solicit thanks to Mr. KASI.V.RaoSc ‟D‟, and Mrs. REVATHYSc‟D‟, MST Division, ADE for their guidance and important links.I express my sincere thanks to Mrs. MAMATHA RANI and Mr.RAHUL RAI,project co-ordinators, ECE, AIeMSfor their valuable guidance.I am thankful to all the Staff of ADE, faculty members and non-teaching staff of ECEDepartment, AIeMS for their kind co-operation.I also wish to thank my friends for their encouragement. Last but not the least, Iwould like to thank my parents and almighty for the support.TEJAS.S (1AR09EC043)
B.V.V.Sangha‟sAMRUTA INSTITUTE OF ENGINEERING ANDMANAGEMENT SCIENCESNear Bidadi Industrial Area, Bengaluru– 562109DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERINGCERTIFICATEThis is to Certify that the Project work entitled “Closed Loop Motor Control using AttitudeHeading Reference System”has been carried out by Tejas S (1AR09EC043)bonafidestudent of Amruta Institute of Engineering & Management Sciences, in the partialfulfillment of the requirements for the award of the degree in Bachelor of Engineering inElectronics & communication Engineering under Visvesvaraya TechnologicalUniversity, Belgaum during the academic year 2012-2013. It is certified that allcorrections/suggestions indicated for Internal Assessment have been incorporated in thereport deposited in the department library.Mrs. PADMAJA VIJAY KUMAR Mr. C.R RAJAGOPALDr.A.PRABHAKARAssistant Prof., Dept. of ECE Head of DepartmentPrincipalAIeMS AIeMS AIeMSName of the Examiners: Signature and Date1.2.
ABSTRACTState of art Attitude Heading Reference System (AHRS) using MEMS gyros arebeing used worldwide to control UAV’s,using control actuators,the rudder,elevator etc. Thisproject deals with the design,development and demonstration of a closed loop actuationsystem using AHRS and DC motor.The system has been designed based on the AduC 7020 and external interfaces toconnect AHRS and a DC motor.AHRS software module have been validated using C.Complete software code for the microcontroller including AHRS interface,realization of PIcontroller etc have been written and validated.The complete hardware has been realized and successfully demonstrated for theclosed loop performance which will be used for future projects of ADE.
TABLE OF CONTENTSPAGE NO1. INTRODUCTION 11.1 EVOLUTION 11.2 USER REQUIREMENTS 31.3 PROJECT OVERVIEW 42. ATTITUDE HEADING REFERENCE SYSTEM (AHRS) –LITERATURE STUDY 52.1 SERIAL PORT CONFIGURATIONS 62.2 COMMUNICATIONS COMMANDS 62.3 PIN CONFIGURATION OF AHRS USED 72.4 DEVICE MODES 82.5 AHRS FORMAT IN SENDING THE SENSOR DATA 92.6 FLOATING POINT REPRESENTATION 92.7 FLOATING POINT CONVERSION EXAMPLE 103. AHRS CONFIGURATION 123.1 BAUD RATE SETTINGS 123.2 MODE SETTINGS 123.3 ROLL AND ANGULAR RATE COMMANDS 133.4 SUMMARY OF SETTING 144. HARDWARE DESIGN 154.1 HARDWARE DESIGN 154.2 CHOICE OF MICRO CONTROLLER 164.3 MICRO CONTROLLER SYSTEM DESIGN / AHRS CONTROL CARD 174.3.1 SYSTEM CLOCK 17
4.3.2 INPUT & OUTPUT PORTS 174.3.3 PARALLEL PORT 174.3.4 INTERRUPT SYSTEM 184.3.5 UART SERIAL INTERFACE AND RS232 DRIVER 184.3.6 POWER SUPPLY COMPATIBILITY FOR MICROCONTROLLER 194.3.7 ANALOG AND DIGITAL GROUND SCHEME 194.3.8 MONITORING POINTS 194.3.9 DAC 194.3.10 TERMINATION OF THE INPUTS AND OUTPUTSFROM THE BOARD 194.4 SIGNAL CONDITIONER INTERFACE / LEVEL CONTROL CARD204.4.1 LEVEL SHIFTER DESIGN 204.4.2 VOLTAGE TO CURRENT AMPLIFIER DESIGN 214.4.3 MOTOR SELECTION 214.5 HARDWARE SUMMARY 225. SOFTWARE DESIGN 265.1 MICRO CONTROLLER REGISTER INITALIZATION 265.2 GENERAL PURPOSE IO PINS 265.3 BAUD RATE SETTING FOR UART SERIAL INTERFACE 275.3.1 SETTING OF DATA LENGTH 275.3.2 TRANSMISSION AND RECEPTION OF DATA 285.4 DAC SYSTEM 285.5 INTERRUPT SYSTEM 285.6 TIMERS 295.7 FLOATING POINT CONVERSION ALGORITHM 295.8 ANGLE REPRESENTATION FROM AHRS 335.9 READING THE PARALLEL PORT 335.10 PORTING DATA INTO DAC 345.10.1 COMPUTATION OF ERROR 345.10.2 SATURATION LOGIC 35
6. SOFTWARE FLOW CHART 366.1 OVERVIEW OF SOFTWARE PROGRAMMING 366.2 OVERALL FLOWCHART 377. RESULTS 417.1 RESULTS TAKEN DURING DEVELOPMENT 417.2 PROGRAPH OF THE HARDWARE SET UP 488. CONCLUSION AND FUTUREWORK 528.1 CONCLUSION 528.2 FUTURE WORK 52REFERENCESAPPENDIX
LIST OF FIGURESPAGE NOFig 1.1 Aircraft with variety of sensors 1Fig1.2 Typical Mechanical Gyroscopes 2Fig1.3 Principle axis of Rotation of an Aircraft 2Fig1.4 Basic Block diagram arrived based on User Requirements 4Fig2.1 Typical AHRS 5Fig2.2 Pin configuration of AHRS 7Fig4.1 Basic Block diagram based on User Requirements without using Microcontroller 15Fig4.2 Basic Block diagram based on User Requirements using Microcontroller 15Fig4.3 Basic Block diagram based on User Requirements using Microcontroller 16Fig4.4 Level shifter circuit diagram 20Fig4.5 V-I Converter circuit diagram 21Fig4.6 The overall hardware structure 22Fig4.7 The complete circuit diagram 23Fig4.8 The detailed circuit diagram using DAC and SWITCH 24Fig4.9 The circuit diagram of Level Shifter and VI converter 25Fig5.1 Frame format 30Fig5.2 Flowchart to find Sign bit 30Fig5.3 Flowchart to find exponent part 31Fig5.4 Flowchart to find mantissa part 32Fig6.1 Overview of software programming 36
Fig6.2 Overall flowchart of project 38Fig6.3 Flowchart of Call response mode routine 39Fig6.4 Flowchart of AHRS read data routine 39Fig6.5 Flowchart of Conversion routine 40Fig6.6 Flowchart of PI controller routine K1 and K2 41Fig7.1 Shows the AHRS o/p as seen on a DAC when it is manually rotatedfrom +/- 180 degrees. 42Fig7.2 The update value from AHRS in every 10 msec 42Fig7.3 The roll output of the AHRS on DAC. 43Fig7.4 The output of the level shifter in the closed loop when seen on a oscilloscope 44Fig7.5 The output of the Roll rate on DAC in the closed loop when seenon a oscilloscope. 44Fig7.6 The roll output of the AHRS on DAC for a step command of +90 deg 45Fig7.7 The roll output of the AHRS on DAC for a step command of +157 deg 45Fig7.8 The roll output of the AHRS on DAC for a step command of +45 deg 46Fig7.9 The roll output of the AHRS on DAC for a step command of 0 deg 46Fig7.10 The roll output of the AHRS on DAC for a step command of -45 deg 47Fig7.11 The roll output of the AHRS on DAC for a step command of -90 deg 47Fig7.12 The roll output of the AHRS on DAC for a step command of -157 deg 48Fig7.13 The roll output of the AHRS on DAC for a step command of +67deg 48Fig7.14 AHRS 3DM GX-25 49Fig7.15 AHRS fitted along with the motor 49Fig7.16 AHRS Control Card Design 49
Fig7.17 Level control card design 50Fig7.18 Switch implementation on bread board 50Fig7.19 Set up of the whole system and closed loop control 51Fig7.20 Set up of the whole system and closed loop control 51
LIST OF TABLESPAGENOTable 2.1 Default serial port settings 6Table 2.2 Command summary 7Table 3.1 MODE Command 13Table 3.2 EULER ANGLE Command 13Table 3.3 EULER ANGLE and ANGULAR RATE Command 14Table 4.1 Parallel port commands configuration 17Table 5.1 Write sequence of PLLCON and POWCON 26Table 5.2 GP1CON (Reading the parallel port1 data) 27Table5.3 Values to be loaded in order to set baud rate of 115200 27Table5.4 EULER ANGLES and ANGULAR RATES 29Table 5.5 List of Commands 33INTRODUCTION
1.1 EVOLUTIONSensors and actuators are the basic hardware components that are essential in anycontrol systems. Sensors are used to sense or measure the state of the system, and actuatorsare used to adjust the state of the system.Fig 1.1 Aircraft with variety of sensorsAn aircraft attitude determination and control system typically uses a variety ofsensors and actuator, because attitude is described by three or more attitude variables.There are two basic classes of attitude sensors. The First class makes absolute measurements,whereas the second class makes relative measurements.Absolute measurement sensors are based on the fact that knowing the position of anaircraft it is possible to compute the vector directions, these directions with respect to anaircraft or body.Relative measurement sensors belong to the class of gyroscopic instruments,including the rate gyro and the integrating gyro. Classically, these instruments have beenimplemented as spinning disks mounted on gimbalsGyroscopes are physical sensors that detect and measure the angular motion of anobject relative to an inertial frame of reference. The term "Gyroscope" is attributed to themid-19thcentury French physicist Leon Foucault who named his experimental apparatus forEarths rotation observation by joining two Greek roots: gyros - rotation and skopeein- tosee.The unique feature of gyroscopes is the ability to measure the absolute motion of anobject without any external infrastructure or reference signals. All gyroscopescan be dividedinto two main categories, depending on whether the angular velocity or orientation is beingmeasured. Rate gyroscopesmeasure the angular velocity, or the rate of rotation of an object.Angle gyroscopes also called Whole Angle or Rate Integratinggyroscopes, measure theangular position, or orientation of an object directly.
Essentially all existing Micro-Electro-Mechanical-Systems (MEMS) gyroscopes areof the rate measuring type and are typically employed for motion detection (for example, inconsumer electronics and automotive safety devices) and motion stabilization and control (forexample, in smart automotive steering and antenna/camera stabilization systems).Gyroscopes allow untethered tracking of an objects angular motion and orientationand enable standalone Heading Reference Systems (AHRS).Fig 1.2 Typical Mechanical GyroscopesAHRS is a 3-axis Inertial Measurement Unit (IMU) combined with a 3-axis magneticsensor, and an onboard processor that creates a virtual 3-axis sensor capable of measuringheading (yaw), pitch, and roll angles of an object moving in 3D space.Fig 1.3 Principle axis of Rotation of an AircraftAHRS sensors were originally designed to replace the large traditional mechanicalgyroscopic aircraft flight instruments and provide better reliability and accuracy. Typically anAHRS will consists of either a fiber optic (FOG) or MEMS 3-axis angular rate gyro triad, a3-axis MEMS accelerometer, and a 3-axis magnetic sensor known as a magnetometer.An Attitude & Heading Reference System (AHRS) is a self-contained system whichprovides the pitch, roll and yaw angles as shown in figure 1.3
AHRS sensors are typically used in one of three ways. First of all they can be used asan instrument to provide flight data recording of the orientation of the platform as a functionof time. Secondly an AHRS can be used for platform stabilization. The angular rate outputscan be directly tied into a control loop to maintain platform stability. An AHRS can also beused as an attitude control system. Aircraft, helicopters, quad-rotors, blimps, and evenunderwater robotic vehicles all can benefit from the use of an AHRS to form a closed-loopattitude control system. The angular rate outputs at a high bandwidth along with the estimatedorientation angles make it possible to command a platform directly with desired attitudeangles.AHRS sensors are typically used in one of two ways. First of all they can be used asan instrument to provide flight data recording of the orientation of the platform as a functionof time. Secondly an AHRS can be used for platform stabilization. The angular rate outputscan be directly tied into a control loop to maintain platform stability.The proposed project undertaken is to design, develop and demonstrate a closed loopmotor control using the AHRS sensor meeting the following user requirements.1.2 USER REQUIREMENTSThe following are the requirements specified by the user1. Hardware design based on ADuC 7020 microcontroller having the followinginterfacesa) UART port interface to AHRS the 3DM GX-25.b) Parallel port interface to set different eight roll command inputs.c) Analog output interface to control a motor.2. Software using code to validate the working of AHRS for roll feedback and roll ratefeedback.3. Microcontroller software toa) Validate the working of AHRS.b) Inclusion of PI controllers in inner and outer loops having provision to changethe proportional and integral time constant as desired.c) Sample the data at an update rate of ~5msec.
4. Interface the motor including the design to the required voltage to current converterand demonstrate the closed loop working of AHRS as a steering and stabilizationsystem.1.3 PROJECT OVERVIEWThe project deals with design, development and demonstration of a closed loopsystem using AHRS and DC motor.Block schematic of the system is as shown in Figure-1.4.Fig 1.4 Basic Block diagram arrived based on User RequirementsThe AHRS is capable of giving angle and rate outputs in roll axis, pitch axis andheading. However, only roll angle and roll rate outputs from the AHRS is proposed to beused to meet the user requirements.
ATTITUDE HEADING REFERENCE SYSTEM (AHRS)– LITERATURE STUDYAHRS is a 3-axis Inertial Measurement Unit (IMU) combined with a 3-axis magneticsensor, and an on-board processor that creates a virtual 3-axis sensor capable of measuringheading (yaw), pitch, and roll angles of an object moving in 3D space. The user has indicatedthe use of 3DM-GX3-25 AHRS. Literature study on this AHRS is given below.The AHRS under study is from Micro strain. It has a fourth generation orientationsensor core which has the following features.1. 32-bit low power high performance processor2. USB and serial UART host interface3. 17 bit resolution on Gyros, Accelerometers, and Magnetometers4. Full 1kHz Coning and Sculling integration5. Cascaded adjustable FIR filters6. Data rates of up to 1000Hz7. Smallest and lightest full function 6-DOF orientation sensor8. Fully calibrated and temperature compensated outputsFig 2.1 Typical AHRSAHRS is an inertial sensor installation that outputs aircraft attitude, heading and flightdynamics information to flight deck displays, flight controls, weather radar antenna platformand other aircraft systems.AHRS Comprises of Gyros, Accelerometers, and Magnetometers. Gyros are basically used tomeasure the Rate of Rotation. Accelerometers are used to measure the Linear Acceleration.Magnetometers are used to measure the Earth’s Magnetic Field.
2.1 SERIAL PORT CONFIGURATIONSAHRS selected communicates with the external world [host computer] via an Rs232 serialport having the following default serial port settings as given in Table2.1.Baud Rate 115.2KParity NoneData Bits 8Stop bits 1RTS/CTS DisabledTable 2.1 Default serial port settings2.2 COMMUNICATIONS COMMANDSAHRS can be controlled by the host computer controls by issuing one or more singlebyte commands (in some cases, additional data bytes must follow the command byte). Mostcommands will cause the AHRS to transmit a response of a fixed number of bytes.AHRS can be commanded by Host computer in a continuous Mode so that AHRScould continuously output a pre-selected data quantity without being prompted by the host.AHRS can also be programmed to power-on directly into Continuous Mode without requiringany host control.Table 2.2 lists a summary of all commands available for the AHRS.
2.4 DEVICE MODESAHRS operates in one of three modes Continuous, Active, or Idle.ACTIVE MODEIn active mode, the AHRS has all sensors powered on and is performing continuoussampling and data conditioning. The communications channel is open and the AHRS canrespond to any configuration, status, or data command. The host may issue any command atany time. The sensor will not output unsolicited data records. The 3DM-GX3™ will respondto data commands by outputting the corresponding data record. Multiple commands issued bythe host will be buffered on-board the device, with one being processed at the completion ofeach successive sampling cycle.CONTINUOUS MODEIn continuous mode, the AHRS will output a data record continuously with no furtheraction by the host. The data record output corresponds to the preset data command set by thelast call to Continuous Preset. The host computer must be capable of the buffering andinterpreting the data stream at sufficient speed to prevent loss of data.Once continuous mode is set, it will remain in effect until it is terminated by issuing adifferent Mode command or the power to the device is interrupted. An alternate single bytecommand, Set Continuous Mode, can be used to start continuous mode. This command doesnot change the continuous preset value.An alternate single byte termination command, Stop Continuous Mode, may be usedto stop the continuous mode and put the sensor into active mode. The benefit of thiscommand is that it does not generate a response packet. This can be advantageous where theintroduction of a response packet in the middle of a data stream can cause a parser to get outof sync with the stream.Although the AHRS will still act on and respond to all other commands while incontinuous mode, it is better to change to active or idle mode before doing configurationcommands. This makes it easier for the host to parse the incoming stream of responsepackets.
IDLE MODEThe idle mode is the same as the active mode in that the AHRS will respond to anyconfiguration, status, or data command. However, in the idle mode, the sensors are turned offand data commands return invalid sensor data. For raw data, the values will just beundetermined. This mode is useful when doing configuration on a battery powered systemand you need to minimize the power consumption. Idle mode draws approximately one halfof the current compared to active mode.2.5 AHRS FORMAT IN SENDING THE SENSOR DATAThe sensor data say Roll angle and roll rate from AHRS is transmitted Euler angles which isin the IEEE-754 floating point format. The IEEE – 754 format of representation is as follows.The IEEE-754 format is aSingle precision floating point format in which a computernumber occupies 4 bytes (32 bits) in computer memory and represents a wide dynamic rangeof values.Single-precision binary floating-point is used due to its wider range over fixed point(of the same bit-width), even if at the cost of precision.This gives from 6 to 9 significant decimal digits precision (if a decimal string with atmost 6 significant decimal is converted to IEEE 754 single precision and then converted backto the same number of significant decimal, then the final string should match the original; andif an IEEE 754 single precision is converted to a decimal string with at least 9 significantdecimal and then converted back to single, then the final number must match the original)2.6 FLOATING POINT REPRESENTATIONThe IEEE 754 standard specifies a binary32 as having:1. Sign Bit: 1 Bit.2. Exponent Width: 8 Bits.3. Mantissa/ Significant Precision: 23 BitsSign bit determines the sign of the number, which is the sign of the significant as well.Exponent is either an 8 bit signed integer from −128 to 127 (2s Complement) or an 8 bit
Unsigned integer from 0 to 255 which is the accepted base forms in IEEE 754 32 bitdefinition. For this case an exponent value of 127 represents the actual zero.The true significant includes 23 fraction bits to the right of the binary point and animplicit leading bit (to the left of the binary point) with value 1 unless the exponent is storedwith all zeros. Thus only 23 fraction bits of the significant appear in the memory format butthe total precision is 24 bits (equivalent to log10(224) ≈ 7.225 decimal digits).The bits are laid out as follows:1 Bit 8 Bits 23 BitsThe data obtained from AHRS will be in IEEE-754 Format as shown above. Hence inorder to understand we convert this data in IEEE-754 Format to Decimal Format, Which isdone using the Conversion formula,2.7 FLOATING POINT CONVERSION EXAMPLE1Bit 8Bits 23BitsSIGN
1. Here the value of Sign Bit S=0.Hence the number is Positive.2. Here the value of Exponent E is given by E = 01111110 b = 126 de = E -127 = -13. Fractional part of Mantissa M is given byM = 10000000000000000000000 (23 bits) = 0.5 dBy substituting the values of S , E and M in the below equation, we get the converteddecimal value.In the above example N= 0.75dAHRS CONFIGURATION
The detailed description of the AHRS configuration used in the project is given below3.1 BAUD RATE SETTINGSThefollowingbaud rate setting of the AHRS isused in the project to improve upon thespeed of transmission. Care has been taken in the choice of the baud rate to match with thecapability of the microcontroller suggested by the userBaud rate 115.2KParity NoneData Bits 8Stop Bits 13.2 MODE SETTINGSAHRS operates in various modes i.e., in active, continuous, idle mode, hence it isnecessary to set the AHRS in particular mode for its proper operation. The default mode ofAHRS is Active mode; however the mode is set into Active mode by command to eliminatethe possibility in sensing wrong information from the AHRS. The command used to changemode of operation of AHRS called as MODE command. This command packet is sent to theAHRS from the Host PC.MODE command is as shown in Table 3.1The user has to transmit four bytes of commands to AHRS. The AHRS responds by aresponse packet which is used to confirm that the mode is set in Active mode only.Continuous mode is not opted in the particular application, as it is preferred to acquirethe particular data packet each time only when a packet of data has been requested i.e., at aparticular update rate/ predefined rate of 5m sec as per user requirements.Check sum which is the sum of Byte1 and byte 2 is used to declare the correctresponse for the command given.Function: Putthe 3DM-GX3™ into new mode or read current mode.Command:Byte1 0xD4Byte2 0xA3(Confirms user intent)
Byte3 0x47(Confirms user intent)Byte4 Modeselector:0:No mode change: just read current mode1:Put in Active mode (default)2:Put in Continuous mode (use Continuous Presetfirst)3:Put in Idle mode4:Put in Sleep mode5:Put in Deep Sleep modeResponse:Byte1 0xD4Byte2 Currentor new modeBytes3-4 ChecksumTable 3.1 MODE Command3.3 ROLL AND ANGULAR RATE COMMANDSAHRS provides the sensor information in EULER ANGLES by setting a command0xCE or information of EULER ANGLES and ANGULAR RATES by setting up acommand 0xCF through the host PC. The response is the data packet sent from the AHRS.Data format is as shown in Table 3.2Euler Angles (0xCE)Function: The3DM-GX3™ will output a data record containing EulerAngles.Command:Byte1 0xCEFunction: The3DM-GX3™ will output a data record containing EulerAngles.Response:Byte1 0XceBytes2-5 Roll (IEEE-754Floating Point)Bytes6-9 Pitch (IEEE-754Floating Point)Bytes10-13 Yaw (IEEE-754Floating Point)Bytes14-17 TimerBytes18-19 ChecksumTable 3.2 EULER ANGLE CommandA part of the requirement i.e. EULER ANGLES is only satisfied by this command,hence not preferred.
EulerAngles and Angular Rates (0xCF)Function: The3DM-GX3™ will output a data record containing EulerAnglesand AngularRates.Command:Byte1 0xCFFunction: The3DM-GX3™ will output a data record containing EulerAnglesand AngularRates.Response:Byte1 0xCFBytes2-5 Roll (IEEE-754Floating Point)Bytes6-9 Pitch (IEEE-754Floating Point)Bytes10-13 Yaw (IEEE-754Floating Point)Bytes14-17 AngRateX (IEEE-754Floating Point)Bytes18-21 AngRateY (IEEE-754Floating Point)Bytes22-25 AngRateZ (IEEE-754Floating Point)Bytes26-29 TimerBytes30-31 ChecksumTable 3.3 EULER ANGLE and ANGULAR RATE CommandAs both the Angle and Angular rates are required from the AHRS, the command 0XCF isinitiated to obtain this information from the sensor. Check sum i.e. sum of byte1 to byte 29 isused to check the correctness of the data received from AHRS. Roll angle and roll rate fromthis command are used as per user requirements.3.4 SUMMARY OF SETTING1. The Baud rate set for AHRS is the default 115.2K baud rate.2. During power ON, AHRS is set in Active Mode (by default) by sending four bytesCommand (0xd4, 0xA3, 0x47, 0x01). and ensure that the mode is set by checking itsresponse3. Command of Command Euler angles and Angular Rates (0xCF) is used in order toread the Roll angle and Roll rate every 5m sec update rate.4. Data from AHRS to acquire roll angle and roll rate [Euler angles and AngularRates]is read once in every 5m secHARDWARE DESIGN
4.1 HARDWARE DESIGN:The hardware design to design the system to meet the user requirements is given in thissection.The block schematic of the system required to be implemented in the hardware is as shown inFigure-4.1Fig4.1 Basic Block diagram based on User Requirements without using MicrocontrollerThe modified block schematic highlights the blocks that could be implemented in thehardware to meet the requirements given in Figure-4.2 given below.Fig4.2 Basic Block diagram based on User Requirements using Microcontroller
Fig4.3 Basic Block diagram based on User Requirements using Microcontroller4.2 CHOICE OF MICRO CONTROLLERMicro controller is required to have the following interfaces1. One Serial RS 232 interface to connect it to AHRS2. 8 bit parallel port interface to set the roll command3. DAC to convert the data into analog form to interface with a motorChoice of the controller is also based on the processing capability / speed to execute thecompensators every 5m sec interval. Micro controller ADuC7020 from M/s Analog Deviceshas been selected as it has all the interfaces required in the project and has the computationalspeed capability as given by the user. More over the same micro controller IC is available inthe laboratory with all the support tools required, hence this micro controller is selected.ADuc 7020 Micro controller has the following features:1. The ADuC7020 devices operate from an on-chip oscillator and a PLL generating aninternal high frequency clock of 41.78MHz.2. The micro-controller core is an ARM7TDMI, 16bit / 32bit RISC machine, whichoffers up to 41MIPS per performance.3. 8K bytes of SRAM and 62K bytes of non-volatile Flash/EE memory are provided on-chip. Hence no external memory is needed for storing the program.4. General Purpose Timer: Timer is general-purpose, 32bit timer with a programmableprescale. The source can be the 32 KHz external crystal, the core clock frequency, oran external GPIO, P1.0 or 0.6.
4.3 MICRO CONTROLLER SYSTEM DESIGN / AHRSCONTROL CARD4.3.1 SYSTEM CLOCK:The system clock in the Micro controller is routed through a programmable clockdivider from which the MCU core clock operating is generated. An external clock of 32.768KHz is connected to the micro controller which enables the micro controller to operate at acore clock frequency of 41.78 MHz4.3.2 INPUT & OUTPUT PORTS:The ADuC720 provide 40 general purpose, bidirectional I/O (GPIO) pins. Many ofthe GPIO pins have multiple functions. GIPO pins are used for synchronization of data inserial communication. They are also use to control the display functions and give displayinputs.4.3.3 PARALLEL PORTMicro controller aduc7020 has 5 ports each of 8 bits which can be configured. IN thepresent system design three input lines from Port 1 are used. The port is configured so thatthe roll command can be switched to a particular value based on the switch position of Portnumbers 1.2, 1.3, 1.4 are used in the design. The following are the roll commands chosenarbitrary based on the three bit positionsP(1.4) P(1.3) P(1.2) Angle(in degree)0 0 0 1570 0 1 900 1 0 450 1 1 01 0 0 -451 0 1 -901 1 0 -157
1 1 1 67Table 4.1Parallel port commands configuration4.3.4 INTERRUPT SYSTEM:There are 23 interrupt sources on the ADuC7020, which are controlled by theinterrupt controller. Four additional interrupt sources are generated from external interruptrequest pins, IRQ0, IRQ1, IRQ2 and IRQ3.In the present design no external interrupts are proposed to be used. Internal timer interruptsand Serial communication transmitter and receiver interrupts are only to be used.Timer-0 interrupt is used to interrupt the system in every 5 sec to acquire/ process and controlthe motor using DAC.The serial interrupts can be used to command the AHRS i,e, transmit serial interrupt can beused when a command to AHRS to be sent i,e command AHRS to send Roll and roll rateangles Receive serial interrupt can used to receive every byte of data sent by AHRS.However this serial interrupt mechanism is not restored in the present design but pollingmechanism for the status bit is resorted to due to ease in its implementation Interrupt modeoption has been kept as an option if the job cannot be completed within the execution time of5m sec.4.3.5 UART SERIAL INTERFACE AND RS232 DRIVER:ADUC 7020 micro controller has a single UART port. A UART peripheral is a full-duplex, universal, asynchronous receiver/transmitter. It is fully compatible with the 16,450serial port standards. The UART performs serial-to-parallel conversions on data charactersreceived from a peripheral device or modem, and parallel to serial conversions on datacharacters received from the CPUUART port is used to AHRS sensor. As the serial output from Micro controller isLTLL 0 to 3.3V. A level translator is required to be used to make it compatible with RS 232standards i.e m signal from +/- 12 V. Hence a Level translator IC has been used for this
purpose. Available ICADM3202ARNZ (U9) has been chosen and used for this purposewhich meets this requirement.4.3.6 POWER SUPPLY COMPATIBILITY FOR MICROCONTROLLER:The power input to the micro controller is + 5 V DC inputs. As the microcontrolleroperates in 3.3 V, a voltage regular driver is required to be used. ADP3333-3.3RL7, voltageregulator, which takes 5V-DC as input and provides an output of 3.3V-DC.ADuC720 hasbeen selected and used. Required decoupling capacitors for all the components are also usedin the design. A transient absorber is also used in the design to above the transients on the5V line4.3.7ANALOG AND DIGITAL GROUND SCHEME:It is necessary to isolate the Digital ground of the digital peripherals with the analogsection. To isolate this inductor of the order of 10 µH is used.4.3.8 MONITORING POINTS:As AHRS is an important sensor used in the project, to monitor the functioning of theAHRS on say an oscilloscope the outputs of AHRS are terminated on a Connector. JumperJ1 FTSH-105-01-L-DV is used for this purpose.4.3.9 DAC:ADuC Microcontroller has internally four DAC with it. The signal level from this DAC isfrom 0 to 2.5 V. Same DAC from the micro controller is proposed to be used.The ADuC DAC outputs are terminated to the external world using a buffer. A four channelanalog Buffer IC is used to interface with the four DAC outputs from Micro controller.Buffer AD8064 IC is used for this purpose.4.3.10TERMINATION OF THE INPUTS AND OUTPUTS FROM THEBOARD:
All the necessary Inputs and outputs that are required to control the motor / AHRS areterminated on a 30 pin connector. Available connector TFM is used for this purpose.4.4 SIGNAL CONDITIONER INTERFACE / LEVELCONTROL CARDThe ADUC microcontroller has DAC which provides signal in the voltage range of 0to 2.5 V. The DAC is required to drive / control a motor in both directions in a closedloop. Hence a suitable level shifter to swing the voltage from 0 to 2.5 V to +/- 5 V hasbeen designed.4.4.1 LEVEL SHIFTER DESIGN:An operation amplifier is used to shift the level. OPa 07 a low noise amplifier hasbeen selected in the design. Basically the level shifter is a summer opamp. Description isgiven belw.Fig 4.5 Level shifter circuit diagramApplying KCL (Kirchoff’s Current Law) to the circuit shown below+ = (1)
= - (2)Proper choice of components such as resistors (R1, R2, Rf) to shift the output voltage levelfrom 0 to 2.5 V to +/- 5 VValue of V2 has been fixed at -5 V and resistor Rf = 4KΩ, R1 = 4KΩ,R2 = 4KΩ.This results in level shifted output of +/- 5V for input V1 varying from 0 to 2.5 V4.4.2 VOLTAGE TO CURRENT AMPLIFIER DESIGN:Motor requires controlled current to be driven at a required RPM. Voltage from the levelshifter is converted to appropriate current input to the motor using a V to I converter.A V to I converter is designed using a power amplifier OPA 501. Typical V to I converter isgiven below.Fig 4.4V-I Converter circuit diagram= (3)I = I1 – I2 (4)(5)I = (6)When both Level shifter and V to I converter are connected together then output of levelshifter is nothing but input to the V to I converter.4.4.3 MOTOR SELECTION:
A geared motor having sufficient torque has been chosen in our application. Swiss makeMini motor SA has been used. This motor selected requires a maximum current of 100mAwhen operated from a voltage up to 5 V. V to I converter has been designed such that therequired current is supplied.The resistance values chosen are R4 = 470Ω, R5 = 1KΩ, R6= 100ΩA current limit is also required to be added in any V to I converter design. The currentlimiting resistor value is chosen as per the equation Ilim= which works out to be4.7Ω considering the max current requirement to the motor of 100mA.4.5 HARDWARE SUMMARYBlock schematic with the interface of the designed cards are as shown in figure.1. AHRS is connected to the AHRS control card via the J2 connector pin numbers19[AHRS transmit/ Microcontroller receive], pin number 20[AHRS receive/microcontroller transmit]and common ground pin number 3 on J2 connector.2. Micro controller DAC 1 [ pin number 6 of J2 connector ] connected to T1 of the levelcontrol card and ground[ J2 connector pin number 3 ] to T33. DAC2 [pin number 7 of J2 connector] to oscilloscope to observe any waveform ifany.4. Motor between T3 and T4 of the level control card.Fig 4.6 The Overall Hardware Structure
Fig 4.8The detailed circuit diagram using DAC and SWITCH
Fig 4.9The circuit diagram of Level Shifter and VI converterSOFTWARE DESIGN
5.1 MICRO CONTROLLER REGISTER INITALIZATIONDuring power on of the micro controller the following registers are required to be initializedPLLKey1 followed by the PLLCON register and then followed by PLLKEY2PLLCON (Programmable Loop Logic Control): Controls the operating mode (Activemode)POWCON (Power Control Register): Controls the core clock frequency and power downmode.PLLCON value has initialized to 0x21 there by setting the PLL in the default configuration.In this configuration the internal clock is initialized1. Next the POWCON key is initialized by POWKEY1 = 0x01, POWCON andPOWKEY2/POWCON register is used to control the mode and set the clockfrequency. (POWCON register is set in active mode and set a clock frequency of41.78 MHz by setting POWCON register to 00)2. To be precisePLLCON and POWCONare written using the sequence.PLLCON POWCONPLLKEY1 = 0xaa POWKEY1 = 0x01PLLCON = 0x21 POWCON = 0x00PLLKEY2 = 0x55 POWKEY2 = 0xF4Table 5.1 Write sequence of PLLCON and POWCON5.2 GENERAL PURPOSE IO PINSThe ADuC 7020 provides 40 General Purpose bi-directional I/O pins. Many of theGPIO pins have multiple functions.In the present application GP1CON control register is set to 0x0000001 which initialise thefollowing port pins as given below
PIN VALUE NAME REASONP1.0 10 SIN Configure as serial input port [for microcontroller from AHRS ]P1.1 10 SOUT Configure as serial output port [ for AHRS from microcontrollerP1.2 00 GPIO Configure as input portP1.3 00 GPIO Configure as input portP1.4 00 GPIO Configure as input portTable 5.2 GP1CON (Reading the parallel port1 data)The data from the parallel port1 is used to read the switch positions by reading the registerGP1DAT.5.3 BAUD RATE SETTING FOR UART SERIAL INTERFACEMicro controller is programmed such that the transmission and reception from /to AHRS is ata baud rate of 115200. Micro controller is hence required to set registers COMCON0,COMDIV0,COMDIVI and COMDIV2.It is required to generate the precise baud rate byusing modes termed as normal mode and fractional modeCOMCON0 0x80COMDIV0 0x0BCOMDIV1 0x00COMDIV2 0x883ETable 5.3Values to be loaded in order to set baud rate of 115200The following data has been initialized in the following registers to set the baud rate to115200. The error has been reduced to 0% by using the fractional baud rate when comparedto 3 % if used only with normal baud rate.5.3.1 SETTING OF DATA LENGTHData length is set by initialising the COMCON0 Register to design the size of the informationpackets to be transmitted.
COMCON0 register has been initialised to a value of 0x83 which enables data transmissionof 8 bits, 1 start bit, one stop bit and no parity.5.3.2 TRANSMISSION AND RECEPTION OF DATAa. The data to be transmitted is loaded in the COMTX register so that data as initialized viaCOMCON0 register can be transmitted [to AHRS].b. The received data will be available in the COMRX register [from AHRS].c. The next data to be transmitted is initiated by checking the status of THRE bit of theCOMSTAT0 register.d. The data to be read is initiated by checking the status of DR(Data Ready) bit of theCOMSTAT0 register.5.4 DAC SYSTEMThe ADuC 7020 incorporates four, 12 – bit voltage output resistor string DAC’s on-chip. Each DAC has three selectable ranges: 0 V to VREF, 0 V to DACREF and 0 V to AVDD.Each DAC is independently configurable through a control register (DACxCON) anda data register (DACxDAT). The two registers are identical for the four DAC’s.DAC1CON and DAC2CON control register used DAC which are set to value 0X12.There by Enabling the DACto work in normal mode of operation and set the output voltage inthe range from 0 to 2.5V [VREF voltage].Data to be load for DAC operation is loaded in the register DAC1DAT (bits 27 to 16)for Output on DAC1It is necessary to set the reference voltage to a reference valueie. VREF 2.5V, this isaccomplished by loading 0x01 in REFCON register.5.5 INTERRUPT SYSTEMNo external interrupts are proposed to be used in the design. Only internal timer interrupt(timer 0) is required to be initialized.
Before initializing any interrupt, the interrupt is initialized using IRQEN register. Timer 0interrupt is enabled by loading the value of 0x 00000004 in IRQEN register5.6 TIMERSThe ADuC7020 has four general purpose Timer/Counters:Timer0, Timer1, Timer2 or Wake-up Timer. Only Timer 0 is used in the project.1. Timer0 is configured in periodic mode where the counterdecrements/increments from the value in the Load Register (T0LD MMR)until zero/full scale and starts again at the value stored in the Load Register. .The value loaded in T0LD register for timer0 is 0x0330 considering the sourceclock frequency of 41.78MHz and interval is 5m sec and pre scale chosen tobe 256.2. The pre scale is set to 256 and timer 0 enable in periodic mode by loadingvalue of 0x 00C8 to the TCON register.3. It is necessary to clear the timer 0 interrupt after each execution. This isaccomplished by writing any value say 0xFF in T0CLRI register.Reading the AHRS data:The AHRS is commanded in Active mode and the 32 bytes of data are read by themicrocontroller. The flow diagram is given in figure-5.7 FLOATING POINT CONVERSION ALGORITHMThe AHRS gives a 32 byte of data which are IEEE- 754 floating point format.Function: The3DM-GX3™ will output a data record containing EulerAnglesand AngularRates.Response:Byte1 0xCFBytes2-5 Roll (IEEE-754Floating Point)Bytes6-9 Pitch (IEEE-754Floating Point)Bytes10-13 Yaw (IEEE-754Floating Point)Bytes14-17 AngRateX (IEEE-754Floating Point)Bytes18-21 AngRateY (IEEE-754Floating Point)Bytes22-25 AngRateZ (IEEE-754Floating Point)
Bytes26-29 TimerBytes30-31 ChecksumTABLE 5.4 EULER ANGLES and ANGULAR RATESAs an example, let us consider there are four bytes say (2 to 5) i.e. 32 bits that isreceived from AHRS which is in IEEE-754 format which consists of sign, exponent andmantissaFig 5.1 Frame formatIn order to convert the received data from AHRS that is in IEEE-754 format to normalDecimal value four main steps are used. The first job is to separate the S E and M bits fromthe 32 bit data received. Once these values are obtained, the angle information [say roll anglefrom AHRS] is converted into decimal format by using the formula(7)STEP 1: TO FIND STo find Sign bit(S), as only the MSB bit of array is required a, Masking is done byfor the remaining 7bits by multiplying a with 0x80 and later shift by right shift by 7position to get value of SFlow diagram is as given belowa aa a
Fig 5.2Flowchart to find Sign bitSTEP2: TO FIND ETo get the exponent value, it is noted that the value is stored in 2 bytes, i.e. some part in aand some part in a.In the array a, as only 7bits are required, masking is done by multiplying a with0x7F and later left shift it by 1bit position and stored as d1.Similarly in order to get 1stbit of a, the data is masked by multiplying a with0x80 and later right shift it by 7bit positions and stored as d2.The two byte d1 and d2 available are combined together making it as a single byte toget the value of exponent (e) by performing Logical OR operation.Flow diagram is as given below
Fig 5.3Flowchart to find exponent partThen we subtract exponent value e with 127 and store it as e.STEP 3: TO FIND M and NFlow diagram is as given below:
Fig 5.4Flowchart to find mantissa part1. Only last 7 bits of a is required. The data is obtained by masking a with 0x7F.This is stored in t.2. To get the mantissa value after the decimal point the value if it is added with 0x80.a. If e value is negative, then eis multiplied with -1 and again stored it in e. tvalue is right shifted by e position and store it in fb.b. Else if e value is positive, then the value of tis left shifted by e positions andstored in fb. If the value of sign bit (s) is 1, then fb is multiplied with -1.
c. The value stored in fb is in decimal form. i.e., to convert the value intodecimal value in degrees, the fbvalue is multiplied with 57.3 and 0.087.d. Here fb value is the N value [say roll angle data in degrees].This may be noted that shift operation is performed instead of power operation asgiven in equation 7.5.8 ANGLE REPRESENTATION FROM AHRSAHRS data obtained as fb from the AHRS is a 32 bit data which is equal to 0 to 360 degrees.To be precise the value contained in hex isFFFFF800 for -180 deg00000000 for 0 deg0000007FF for +180 degDAC provided on the microcontroller is a 12 bit DAC and has an o/p voltage range from 0 to2.5 Volts.Hence the 32 bit angular data is to be reduced to 12 bit data by shifting this data to right by16 bits.5.9 READING THE PARALLEL PORTInput commands are read using Port 1 ie.,port 1.2, 1.3, 1.4 using GP1DAT register.Based on the bit positions the following roll command angles are derived as follows.P(1.4) P(1.3) P(1.2) Angle(in degree) Command0 0 0 157 0x6FF0 0 1 90 0x3FF0 1 0 45 0x1FF0 1 1 0 01 0 0 -45 0xFFFFFE031 0 1 -90 0xFFFFFBFF
1 1 0 -157 0xFFFFF9001 1 1 67 0x2FFTable5.5 List of CommandsHex value for the command is matched to the roll angle value command as described in theexplained in section22.214.171.124 PORTING DATA INTO DACIt is necessary to read the roll value on a DAC port for monitoring purpose. Formonitoring, data is loaded on DAC2DAT register having a value ranging from 000 to FFF.As the data coming from AHRS is having a negative value which cannot be loaded to theDAC, the AHRS value is offset by a value of 0x7FFi.e., The value of Roll -180 wouldbecome 0 and value of 0 deg angle becomes 7FF, and value +180deg becomes FFF.The DAC loaded with a value of 0 gives 0 V and the DAC loaded with vale of FFF gives 2.5V as discussed in the hardware sections. Hence an analog value of 0 volts corresponds to -180 deg and DAC analog value of 2.5 corresponds to +180 degrees.5.10.1 COMPUTATION OF ERRORThe roll command as determined based on the switch positions, is subtracted from thefeedback angle error [fb] to generate the roll error. The roll error is fed to the compensatorK1. The Compensator K1 assumed is only a gain of 0.2. The output of compensator k1 issubtracted with the roll rate to generate the roll rate error. The roll rate error is fed to thecompensator K2. The compensator K2 is a PI controller having gain (P) of 0.02 and Integralconstant (I) of 0.76. However these constants are arbitrarily based on trial and error whichmust be optimized.The equation for integrator is given byy[n]= y[n-1]+0.76 x[n] (8)Where,y[n] is the present integrated valuey[n-1] is previous 1 sample of y[n]
x[n] is the present output5.10.2 SATURATION LOGICIt is necessary to check for the overflow when any 2 values are summed or multiplied. Hencesaturation logic has been implemented. A subroutine is written such that the value in positiveis limited to +7FF and in negative direction by -7FF or 0xFFFFF801.SOFTWARE FLOW CHART
6.1 OVERVIEW OF SOFTWARE PROGRAMMINGFig 6.1 Overview of software programming6.2 OVERALL FLOWCHART
PI Controller Routine K1& K2Fig 6.6Flowchart of PI controller routine K1 and K2fb from AHRS (ROLL angle) Read Cmd selected as on (from parallel port)
RESULTSThe hardware has been realized and softwarehas been written to demonstrate the closed loopperformance of the system using AHRS.7.1 RESULTS TAKEN DURING DEVELOPMENT1. AHRS OUTPUT ON DACFig 7.1 shows the AHRS o/p as seen on a DAC when it is manually rotated from +/- 180degrees.It may be noted that for a rollangle of 100 deg a voltage equal to 0 is seen and for -180 degvoltage is 2.5 V.2. SAMPLING AT EVERY 10m secDuring the development stage timer 0 was loaded with a data equivalent to 10 msec tocheck whether the system was capable of acquiring the data in every 10 msec.
Fig 7.2 The update value from AHRS in every 10m sec3.WITHOUT ROLL RATEThe closed loop control without Roll rate was exercised during developmentstage and using a PI controller in the loop. It may be observed from fig 7.3 that therewere more oscillations and it took more time to settle, given a step command of 180degrees.Fig 7.3 The roll output of the AHRS on DAC
Fig 7.4 The output of the level shifter in the closed loop when seen on a oscilloscope4. WITH ROLL RATEThe closed loop control with Roll rate was exercised with the inclusion of PIcontroller [K2] in the inner loop and a simple Gain controller in the outer loopand usingthe roll rate during development stage. It may be observed that there were moreoscillations and it took more time to settle, given a step command of 180 degrees.Fig 7.5 the output of the Roll rate on DAC in the closed loop when seen on a oscilloscope.
Fig 7.6: The roll output of the AHRS on DAC for a step command of +90 degFig 7.7:The roll output of the AHRS on DAC for a step command of +157deg
Fig 7.8:The roll output of the AHRS on DAC for a step command of +45degFig 7.9: The roll output of the AHRS on DAC for a step command of 0deg
Fig 7.10: The roll output of the AHRS on DAC for a step command of -45degFig 7.11: The roll output of the AHRS on DAC for a step command of -90deg
Fig 7.12: The roll output of the AHRS on DAC for a step command of -157degFig 7.13: The roll output of the AHRS on DAC for a step command of +90 deg
7.2 PHOTOGRAPH OF THE HARDWARE SET UP1. AHRS usedFig 7.14 AHRS 3DM GX-252. AHRS fitted along with the motor which is mechanically coupledFig 7.15AHRS fitted along with the motor3. AHRS Control Card DesignedFig 7.16AHRS Control Card Design
4.Level control card designed and developedFig 7.17Level control card design5.Switch implementation on bread boardFig 7.18Switch implementation on bread board
6. Set up of the whole system and closed loop controlFig 7.19Set up of the whole system and closed loop controlFig 7.20Set up of the whole system and closed loop control
CONCLUSION AND FUTURE WORK8.1 CONCLUSIONA successful attempt was made to design a closed loop control system using available motorwith AHRS. AHRS is a miniaturized system which is proved to be a useful element to beused in macro UAVs (Unmanned Aerial Vehicles). The update rate of the senor, possesssome limitation on the control system bandwidth. As reading the data from AHRS, convert itto normal format from IEEE 754 and processing it using Micro controller could be achievedonly in every ~5ms.This project has also demonstrated its performance in using in any steering and stabilizationsystem in inertial space which requires less control accuracies, because it has been observedthat the line of sight of motor remains the same irrespective of the rotating motor .8.2 FUTURE WORKThe design of PI controller has not been optimized to get the best performance fromthe output. It is envisaged that the control system can be optimized/tuned to get obtain asettling within 50 m sec by proper control of proportional and integration constants..The mechanical interface can be rugged enough to enable better control.The system using AHRS can be used to control a 2 axis motion platform orthogonal to eachother, by providing necessary angle compensation algorithms which need to be devised.