Home
i.MXS ARM BASED DIGITAL COMPASS
Contents
1. V ALO AR vi Ts INTRODUCTION eiee E A EAE EE E EE E DEENA 1 1 1 PROJECT AIM AND OBJECTIVE 55 3 nti Rep noe etu RR 1 1 2 pcc 1 1 2 1 TAHOE DEVELOPMENT KIT iicecnstetesiteueit uaa oat aoa Uo cmI E Sod e raii 1 1 2 2 TAROE A 2 1 2 3 E E E E A E E A 3 1 2 4 MAGNE SEINS OU icio tiennes citet Pes a Fusco iaa Pares aes adites 5 E 6 2 1 i c H 6 2 2 pea uaielcee 7 2 9 CONNECTING HARDWARE otra ettet tu tc Uva ceat puo b cud aie a i dE 9 MRCODCHTC 12 3 1 12 Bop 14 3 2 1 Class Compass nnn 15 3 2 2 class IMO STEE d RR ERI RETE ETT DT 19 20 IT E A E E 22 4 PROJECT TESTING AND WORKING seeeeseeereeneeennnnnn nnne nnn nennen nnne nins 24 5 RESULTS AND DISGUSSION ai onancicke crant ka naeo ctu EAAS EAA cto san NEEE 27
2. 21 Figure 26 Sensor cs showing address of register and sensor 5 22 Figure 27 Sensor cs Getting compass 6 1 22 Figure 28 IDE showing debug WINKOW cccccseesccceceeeeeeeecaeeseceeeceeeeceeesaeaueceeessaaeeeesessaeeeess 24 Figure 29 Compass intro screen displayed in LCD eeeseseeeessseeeeeennnn 25 Figure 30 Compass screen displayed on LCD ccceecccecceeeeceeeceeeeeceeeseeeeceeesaaaeeeesessaeeeees 25 Figure 31 Working compass intro screen eesseeeessseseeseeeeee nennen nnne nnn nnne nnn nnn 27 Figure 32 Working compass screen display ccccceesececeeeeeeeeeeeeeeeeeseeeeseeeeeneeeeeesaeseeesseeeesens 28 Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS V University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report GLOSSARY ARM It stands for Acorn RISC Machines which is a 32 bit RISC Reduced instruction set computer architecture developed by ARM Limited that is widely used by a number of embedded designs i MXS It is the name of microprocessor designed by Freescale and operates at speed of 100MHz SDRAM Synchronous Dynamic Random Access Memory type of solid state computer memory RISC Stands for Redu
3. 16 Figure 16 a Picture used for angle and direction seeseeessees 16 Figure 16 b Picture for analog compass display 16 Figure 17 LCD cs Calculating screen centre POINKS ccccccseeecceeceeseeceeecaeeeeceeesseaeeeeeeesaaeeees 17 Figure 18 LCD cs array method for direction cccccseeeeeceecaeeeeceeeeeeeeeceeeeaeeeeeeessaaaeeeeeesaaaeeeees 17 Figure 19 LCD cs Calculating 17 Figure 20 LCD cs Drawing compass needle 18 Figure 21 Intro screen TOF COMPASS snuexsuvinvex suinbhakurixt end ar bn xk rri 19 Figure 22 LCD cs Intro screen display ies vissens arias as s urixFedku iuba a Fri i rav 20 Figure 23 BuslO cs Declaration of variables and constants cccccccseeeeeeeeeeeeeeeeeeeeseeeenens 20 Figure 24 BuslO cs Read Operations cccccccssssscccccessseeccceeesececccseaseceeeseeseeeecsseasesessssaseeees 21 Figure 25 BuslO cs Write 5
4. IDE TOF VS INET 4 Figure 5 I2C Bus 8 Figure 6 Project Hardware Components 10 Figure 7 Project Block diagram cccsssccccssseecccsececceseecceaseeeceeececseeseeeseaeeeessagseeesegseessseeeeeeas 11 Figure 8 Class diagram for Program code ssessesssssessseseeeeneen nennen nennen nnns 12 Figure 9 Program cs code for main windOW ccccccsseeeeceeceeeeeeeeeeaaeseceeesaeaeeceeessaaeeeeeessaaeeeees 12 Figure 10 Program cs code for button definitions 19 Figure 11 LCD cs showing Private variables 14 Figure 12 LCD cs showing override event eessssesesessesseee nennen nnne nnns 14 Figure 13 LCD cs Reloading intro screen using else 15 Figure 14 Compass Screen cccccsesecccccceeseececceeeseececceauseeeecseeueeeecseaueceeesseaseeeeessaseeesessagseeees 15 Figure 15 LCD cs Compass screen 5
5. byte rray stopIndex Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 54
6. t I2Bus new BusIO DEFAULT ADDRESS azmuth value from the sensor board public float GetAzimuth Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 42 Universityof Hertfordshire i EI School of Electronic Communication and Electrical Engineering BEng Final Year Project Report read higher register into the buffer dataBuffer I2Bus ReadRegister REG AZIMUTH HIGH dataBurfer return GetValue dataBuffer ByteOrder BigEndian 116 function to convert bytes to float value public long GetValue byte byteArray ByteOrder byteOrder i if byteOrder ByteOrder BigEndian return FromBigEndian byteArray 0 byteArray Length throw new NotImplementedException Not Implemented function to be used by getValue function private long FromBigEndian byte byteArray int startIndex int length long retValue 0 int stopIndex startIndex length 1 for int i startIndex i lt stoplIndex i retValue byteArray i retValue retValue lt lt 8 return retValue byteArray stopIndex f public void Dispose I2Bus Dispose f enumrator for byte order types public enum ByteOrder 1 LittleEndian BigEndian f Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 43 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report APPENDIX 2 SAMPLE CODE 11 The part of the samp
7. 6 EVALUA TON 29 7 CONCLUSION amp FURTHER 30 PREFERENOE 31 BIBLIOGRAPHY m c 32 APPENDIX 1 PROJECT GOD rii ea ito peo pet rid p aa o0 0E sa xa 3 Fa epu pcs cra Ut Ia deoa eina 33 POO ANC S e mET E 33 Rope 34 zigr c D 40 SSS OCS q 42 APPENDIX 2 SAMPLE COD e ieses ret snn nie Rea EEUU denegat eo CUR o dme 44 Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS iii University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report GMP S0 COMPASS Ok eee ence en eee ee eee eee rere 44 NC CS 48 52 Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS IV Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report LIST OF FIGURES BOAO RM m 2 Figure 2 Block diagram Meridian CRU ccccccsccccssececcesseecseeseeeceauseeeseuseeessageeessaneeessanseesseaes 3
8. DirName Directions Dir Direction name dc DrawText Angle this TextFont Colors Green bmpAngle Width 2 25 Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 3 7 Universityof Hertfordshire i EI School of Electronic Communication and Electrical Engineering BEng Final Year Project Report dc DrawText DirName this TextFont Colors Green bmpAngle Width 2 70 25 int x0 dc Width 2 Center point int y0 dc Height 2 y0 y0 30 offset Use N to calibrate int N 90 int intAngle int fAngle N Calculating the compass needle length using X Fxsin a Y Fxueog a double sval double Microsoft SPOT Math Sin int ngle 1000 Sine value double cval double Microsoft SPOT Math Cos intAngle 1000 cosine value int ry ClockRadius sval int rx int ClockRadius cval to obtain full compass needle int ryl int ClockRadius sval int int ClockRadius cval int xl x0 rx int yl y ry int x2 x0 int y2 y DRAWS COMPASS NEEDLE white for North dc DrawLine new Pen Color White 5 x0 y0 xl yl draw pivot circle dc DrawEllipse this Background new Pen Color Black x0 y0 4 4 DRAWS COMPASS NEEDLE black for South dc DrawLine new Pen Color Black 5 x0 yO x2 y2 base OnRender dc Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 38 Universityof Her
9. Execute method will write read bytes on the I2C bus and returns number of bytes successfully on the bus int bytesCount I2531lave Execute xact I2C TIMEOUT if bytesCount readBuffer Length throw new System IGO IOException IO Error f f ummary Gereric Write Operation to write any data on any port on the bus lt summary gt lt param name writeBuffer param public void Write byte writeBuffer I2CDevice I2CTIransaction xact new I 2CDevice I2CTransaction I25lave CreateWriteTransaction writeBuffer E lock I251ave int bytesCount I25lave Execute xact I2C TIMEOUT if bytesCount lt writeBuffer Length Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 41 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report public void ReadRegister byte register byte readButtfer registerBufier 0 register Write registerBurfier Read readBurffter public void Dispose I251ave Dispose Sensor cs using System using Microsoft S5POT namespace DigiCompas class Sensor IDisposable addresss of the sensor bus const byte DEFAULT ADDRESS 0x60 parameter register number or adress of the register const byte REG AZIMUTH HIGH 2 private BusIO I2Bus private byte dataBurffer new byte 2 0x00 OxOO 7j constructor for sensor class public Sensor
10. The omnidirectional sensor measures the magnitude of the component of magnetization that lies along its sensitive axis The bidirectional sensor includes direction in its measurements The vector magnetic sensor incorporates two or three bidirectional detectors Some magnetic sensors have a built in threshold and produce an output only when it is surpassed 8 Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 2 HARDWARE The hardware part of the project involved connecting the suitable magnetic sensor to the Tahoe board The selection of magnetic sensor was not an easy job as there were a lot of varieties of magnetic sensor available The selection criteria were based on the sensor output whereas the required output for sensor was to be digital which means that an ADC Analog to Digital Converter was also required as a part of hardware As from the name it suggests that an ADC converts an analog signal into digital signal The magnetic sensor chosen for this project was the CMPS03 2 1 CMPS03 OVERVIEW The CMPSOS is a two axis compass module sensor board It is called a compass module as 9 itis SOC system on a chip itself The compass uses the Philips KMZ51 magnetic field sensor which is sensitive enough to detect the Earth s magnetic field The output from two of them mounted at rig
11. UH University of Hertfordshire School of Electronic Communication and Electrical Engineering BACHELOR OF ENGINEERING DEGREE WITH HONOURS IN ELECTRICAL AND ELECTRONIC ENGINEERING Final Year Project Report i MXS ARM BASED DIGITAL COMPASS Heport by Sheraz Khan Malik Supervisor Kate Williams APRIL 2008 DECLARATION STATEMENT 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 Section 2 Section on cheating and plagiarism Student Full Name Sheraz Khan Malik Student Registration Number 04106220 SIQGMECO Date 07 April 2008 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report ABSTRACT This report holds the detailed information about how to design an i MXS ARM BASED DIGITALL COMPASS To complete the task a Tahoe development platform was used which was provided by the university It operates with VS NET Micro Framework software and runs with an input of 5V To achieve the compass characteristic a magnetic sensor was used provided by the university It was interfaced with the I2C bus on the Tahoe board and to make the compass fully working a programme code was developed using VS NET Micro Framework software with the help of sample codes The output was obtained as a digital c
12. cs In this part of Program cs the buttons on the Tahoe board are accessed with the help of the program code It shows that the functioning button is the Select button which is named as SW7 and in the programe code it shows that it checks for all the buttons and gets value True Whereas on button SW it gets False this allows it to jump towards the next step It is not necessary to define all the buttons Only the required button can also be defined but it is done for demo purposes Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 13 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 3 2 LCD cs The LCD cs class inherits window class which is inbuilt class of the SDK This class is responsible to show any button activity and show different images and text GUI to be displayed on the screen The LCD class is further divided into two sub classes for different screens LCD class is important class as it holds all the GUI elements and is responsible to show all the text and image activity class LCD Window Private variables private Font SmallFont private Color bkgColor Color Black public LCD i Read resources file to get font this S5mallFont Resources GetFont Resources FontResources myfont create introscreen object IntroScreen intro new IntroScreen assign this view to lcd this Child intro start rendering this
13. public static long GetValue byte byteArray Byte rder byte rder if byte rder ByteOrder BigEndian return FromBigkndian byteArray 0 byteArray Length else throw new NotImplementedException Resources StringResources NotImplementedLittleEndian ToString Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 52 University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report lt summary gt Get value from the byte array lt summary gt jii param name bytelrray Byte array lt param gt lt param name startIndex gt Start index in array lt param gt param name length Number of bytes to parse lt param gt jii param name byteOrder gt Byte order lt param gt lt returns gt Long value lt returns gt public static long GetValue byte byteArray int startIndex int length ByteOrder byteOrder lf byteOrder Byte rder BigEndian return FromBigkndian byteArray startIndex length else throw new NotImplementedException Resources St ringResources NotImplementedLittleEndian ToString lt summary gt Splits number into the byte array lt summary gt param name number gt Value to split param lt param name outputlrray Array where the bytes be stored lt param gt param name byteOrder gt Byte order of the array lt param gt public static void GetBytes long number by
14. view intro StartRendering Figure 11 LCD cs code showing Private variables In figure 11 the LCD class window is defining variables which give the font size background colour and create a new intro screen on the LCD of the Tahoe board The intro StartRendering allows the text to be printed on the screen protected override void OnButronDown HMicrosoft S5POT Input ButtonEventArgs e i Detect button action and respond accordingly base OnButtonDown e if child is introscreen then load the compas view if this Child is IntroScreen i IntroScreen intro this Child as IntroScreen intro Destroy i intro Invalidate CompassElement compass new CompassElement bkgColor this S5mallFont this Child compass compass StartRendering Figure 12 LCD cs code showing override event Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 14 University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report The figure 12 shows the override event for the button activity using if else statements The override event is used in order to make changes into the start rendering event The start rendering event has a default method of printing text Override event provides user to play with the start rendering function and change it as required It shows that the override event detects the button action and responds accordingly if the rite button is pr
15. will be NE North East as it is the 2 number direction from the left hand side if you see figure 17 The calculated value is passed to array and the string then display s the direction that comes on that number which is 2 So that means the compass should be pointing at NE North East at an angle of 45 degrees Use N to calibrate int N 90 int intAngle int fAngle HN Calculating the compass needle length using X Fxsin a Y Fxcos a double sval double Microsoft 5POT Math Sin intA ngle 1000 5ine value double double Microsoft SPOT Math Cos intA ngle 1000 cosine value int ry int ClockEadius sval int rx int ClockRadius cval to obtain full compass needle int ryl int ClockRadius sval int ral int ClockRadius cval int xl x0 rz int yl ry int x2 x0 Cal int y2 DRAWS COMPASS NEEDLE white for North dc DrawLine new Pen Color White 5 x0 xl yi draw pivot circle dc DrawEllipse this Background new Pen Color Black x0 yO 4 4 DRAWS COMPASS NEEDLE black for South dc DrawLine new Pen Color Black 5 x0 yO X2 base OnRender dc Figure 20 LCD cs Drawing Compass needle The program code shown in above figure 20 is drawing the compass needle The compass needle was drawn using the Math function for drawing vector North was used to calibrate the compass it was given an off
16. 12C bandwidth Register 15 is used to calibrate the compass 2 3 CONNECTING HARDWARE The hardware connections were made according to the provided data sheet of the compass module and the user manual given with the Tahoe board The equipment used for the hardware connections were as follows 1 Soldering iron e 6 Coloured wires e 2 Connecting headers Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 9 University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report The compass module was not directly soldered on the I2C bus of the Tahoe board Two headers were used in order to prevent direct contact of the soldering iron to the Tahoe board and the compass module sensor board Different coloured wires were used to differentiate the connections Initially all the wires were soldered on to the connecting headers in order to avoid any damage to the sensor board or the Tahoe board Red coloured wire was used for 5V connection and black for the OV ground Pini 5V of the sensor board was connected to the 5V on the I2C bus and Pin9 OV ground was connected to the OV ground of the I2C bus Pins 2 SCL and 3 SDA of the compass module were connected to the SCL and SDA pins of the I2C bus on the Tahoe board Yellow colour wire was used for SCL and purple colour wire was used for SDA Pink and brown coloured wires were used for pin 5 and 6 but they were left un connected accord
17. ARM BASED DIGITAL COMPASS Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 20 communication Protocol with the Compass module is same as the popular EEPROM s The compass module has a 16 byte array of registers some of which double up as 16bit registers are as follows Register Software Revision number Compass Bearing as a byte i e 0 255 for a full circle Compass Bearing as a word i e 0 3599 for a full circle representing 0 359 9 degrees 45 Internal Test Sensor1 difference signal 16 bit signed word 6 7 Internal Test Sensor2 difference signal 16 bit signed word Internal Test Calibration value 1 16 bit signed word Internal Test Calibration value 2 16 bit signed word Unused Read as Zero o Unused Read as Zero 14 Unused Read as Undefined 15 Command Register Table showing functions of compass module registers Register O is Bi the Software revision number 8 at the time of writing Register 1 is the bearing converted to a 0 255 value This may be easier for some applications than 0 360 which requires two bytes For better resolution registers 2 and 3 high byte first are a 16 bit unsigned integer in the range 0 3599 This represents 0 359 9 Registers 4 to 11 are internal test registers and 12 13 are unused Register 14 is undefined There is no need to read them it would do nothing but waist the
18. Command register of the device lt param gt lt param name newAddress New bit address lt param gt public void Changel CAddress byte commandRegister byte newAddress byte changeCommand new byte 2 i commandRegister ADDRESS CHANGE 1 Write changeCommand changeCommand 1 ADDRESS CHANGE 2 Write changeCommand changeCommand 1 ADDRESS CHANGE 3 Write changeCommand Devantech hardware needs new address in bit 50 we need to shift changeCommand 1 byte newAddress lt lt 1 Write changeCommand I region IDisposable Members lt summary gt Dispose object lt summary gt public void Dispose Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 51 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report SslaveDevice Dispose Fendregion private I2CDevice slaveDevice private byte registerBuffer new byte 1 i Ox00 private byte writeButfer new byte 2 i 0x00 Ox00 Endianity cs using System namespace Devantech Hardware fii lt 3ummary gt Implements basic endianity operations lt summary gt public static class Endianity lt 3ummary gt Gets value from the byte array lt summary gt lt param name byteArray gt Byte array param lt param name byteOrder Byte order lt param gt lt returns Long value lt returns gt
19. Khan Malik i MXS ARM BASED DIGITAL COMPASS 28 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 6 EVALUATION The projects meets the requirements for i MXS ARM Based Digital Compass Project was completed within the specified time without facing any high level difficulties The project satisfies the requirement of an i MXS ARM Based Digital Compass The device created can be used in different applications such as aircrafts robots Navigation systems GPS receivers and etc Although the project did not exactly followed the time plan provided in the feasibility study due to some delays in the progress but it was completed before the given time Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 29 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 7 CONCLUSION amp FURTHER DEVELOPMENT The project satisfied the requirements of an i MXS ARM Based Digital Compass This project helped in improving learning skills and provided a chance of enhancing knowledge It helped in understanding the basic concepts of digital compasses and the background knowledge about the magnetic sensors and their operations It also improved the skills in learning c sharp programming language The projects requirements were e Todesign an i MXS ARM Based Digital Compass e To display di
20. SDE public BusIO byte Address d I251ave new I2CDevice new I2CDevice Configuration Address I2C SPEED Figure 23 BuslO cs Declaration of variables and constants All the variables and constants are defined in this piece of programe code shown in figure 23 The values used are default values The register 1 is used as it gives compass bearing as a byte i e 0 255 for a full circle The register numbers used for I2C communication are 2 and 3 as explained above that these registers get compass bearing as a word i e 0 3599 for a full circle representing 0 359 9 degrees in angle Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 20 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report public void Read byte readBuffer i I2CDevice I2CIransaction zact new I2CDevice I2CIransaction t I25lave CreateReadTransaction readBuffer i lock I2S5lave i int bytesCount I251ave Execute xact I2C TIMEOUT if bytesCount lt readButffer Length throw new System IO IOException IO Error Figure 24 BuslO cs Read operations In the above figure 24 part of the program code the BuslO class is to read any port on the I2C bus of the Tahoe board Execute method will read bytes on the 20 bus and returns the number of bytes successfully on the bus public void Write byte writeBuffer i IZ2CDevice I2CIransaction zact new I2CDevice I2CT
21. System using System Collections using Microsoft SFPOT using Microsoft SPOT Presentation Media using Microsoft SPOT Presentation using System Threading using EmbeddedFusion SPOT namespace DigiCompas LCD class inherits window class which is inbuilt class of SDE This class is responsible to detect any button activity and show different images and text GUI to be displayed on the screen LCD class has two sub classes for two different screens class LCD Window Private variables private Font SmallFont private Color bkgColor Color Black public LCD Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 34 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report Read resources file to get font this SmallFont Resources GetFont Resources FontResources myfont create introscreen object IntroScreen intro new IntroScreen assign this view to lcd this Child intro start rendering this view intro StartRendering override event for detecting the button activity protected override void OnButtonDown Microsoft SPOT Input ButtonEventA rgs e Detect button action and respond accordingly base OnButtonDown e if child is introscreen then load the compas view if this Child is IntroScreen IntroScreen intro this Child as IntroScreen intro Destroy intro Invalidate CompassElem
22. address of the sonarc param public CMP503Compass byte deviceAddress this slave new I2CSlave deviceAddress I endregion region CMP503Compass summary Returns actual azimuth lt summary gt lt returns gt Azimuth lt returns gt public float GetAzimuth _Slave ReadRegister CMPS03Compass REG AZIMUTH HIGH dataBuffer return Endianity GetValue dataBuifer ByteOrder BigEndian 105 summary Returns actual azimuth as the bearing of the byte lt summary gt lt returns gt Azimuth byte bearing lt returns gt public byte GetBearing i Slave ReadRegister CMPS503Compass REG BEARING dataBuifer Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 45 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report return databuftfer 0 fff lt summary gt Returns firmware revision of the device lt summary gt public byte Revision get Slave ReadRegister CMPS503Compass REG REVISION databurfer return dataBuffer 0 I I lt summary gt Restores factory calibration Works only for revision 14 and above lt summary gt public void FactoryCalibration byte data new byte 4 CHP503Compass FACTORY RESET 1 CMPS03Compass FACTORY RESET 2 CMPS03Compass FACTORY RESET 3 CMPS03Compass FACTORT RESET 4 fe _Slave WriteRegister CMPS0SComp
23. aders was damaged with the soldering iron which was then replaced with a new one Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 3 CODING This section of the report contains the detailed explanation of the programe code developed for the project For complete copy of the code as well as the sample code please refer to the Appendix The programe code was developed by looking at different examples of basic c language code regarding compassing and the sample code provided with the sensor board The programe code was divided into four main classes The class diagram shown below gives an overview about overall working of the programe code MAIN PROGRAM Program cs Sensor cs BuslO cs Class Class Class It implements functionality of sensor board to get compass heading in degrees LCD class is reponsible for GUI and all the display elements This class allows communication protocol with 2C bus This class runs the main application window and button definitions Figure 8 Class diagram for Programe code 3 1 Program cs The Program cs class runs the main window application and also checks for the button definitions namespace DigiCompas t lt Summary gt Core apllication object for the application lt public class App EmbeddedFu
24. alid token in dass struct or interface member declaration Sensor cs 26 9 DigiCompas E Q 2 Invalid token in dass struct or interface member declaration Sensor cs 28 31 DigiCompas Q 3 Invalid token in class struct or interface member declaration Sensor cs 28 48 DigiCompas lt mom al ic rni m Error List E Output Figure 28 IDE showing debug window After completing the testing process for hardware and software the whole project was then tested to get the required results Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 24 University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report The hardware was connected to the PC Laptop with the help of provided USB cable As soon as the cable is plugged in the power light of the Tahoe board turns green on The software is then run Once the debug button is pressed the program code is build and debugged completely After completing the debug process the intro screen appears on the LCD of the Tahoe board telling the user to press button SW7 to start Figure 29 Compass intro screen displayed on LCD As soon as the user hits the SW7 button or the select button on the Tahoe board it moves on to the next screen which is the compass screen The compass screen displays angle measured by the sensor board and the directions calculated through the program code It also displays the compass needle w
25. and also helped in understanding the c sharp language limitations DigiCompas Microsoft Visual Studio File Edit View Refactor Project Build Debug Data Tools Window Community Help l PFi gg i Ga E Er gt Debug Any CPU 8 5 9 96 Blo ESWE Y TERRENI FEP in Sensor cs Program cs LCD cs BusIO cs X Solution Explorer DigiCo 2 X DigiCompas Sensor vllo iw Bi PEE i const byte REG AZIMUTH HIGH 2 m M E a Solution DigiCompas 1 project Si 3 5 DigiCompas W 54 Properties private BusIO I2Bus H 3j References private byte dataBuffer new byte 2 0x00 Ea H gj Resources 8 BusIO cs constructor for sensor class 4 u e LCD cs public Sensor Program cs E Resources resx I2Bus new BusIO DEFAULT ADDRESS 3 Resources Designer cs byte Sensor DEFAULT ADDRESS c amp Sensor cs get azmuth value from the sensor board public float GetAzimuth read higher register into the buffer dataBuffer I2Bus ReadRegister REG AZIMUTH HIGH dataBuffer convert bytes to float value and return the value to calling GetValue dataBuffer ByteOrder BigEndian 105 Debug Window 5 function to convert bytes to float value public long GetValue byte byteArray ByteOrder bytg Order t v lt Error List vix 17 Errors fO Warnings i 0 Messages Description File Line Column Project Q 1 Inv
26. ass REG UNLOCK 1 data f endregion region IChangableAddress Members lt summary gt Changes address of the I2C device Works only for revision 14 and above lt summary gt lt param name newAddress New bit address lt param gt public void Changel2CAddress byte newAddressz Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 46 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report byte data new byte 4 1 T2CSlave ADDRESS CHANGE 1 T2CSlave ADDRESS CHANGE 2 T2CSlave ADDRESS CHANGE 3 byte newAddress lt lt 1 Ie _Slave WriteRegister CMP50SCompas3 REG UNLOCK 1 data Slave Dispose Wait a few miliseconds to make things asattle Thread Sleep 50 Create slave with new address Slave new I2051lave newAddres3 endregion region IDisposable Members lt summary gt Dispose object ii lt summary gt public void Dispose i _slave Dispose Fendredion private 2Cslave slave private byte databutfer new byte 2 i 0x00 Ox00 1 Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 47 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report I2CSlave cs using system using Microsoft SPOT using Microsoft SPOT Hardware namespace Devantech Hardware summary Implement
27. cations can be written directly in C for CPUs with the NET Micro Framework The Core Libraries provided in the SDK are an extended sub set of the framework available on the desktop The NET Micro Framework adds many specialized components designed for small low power embedded systems like and SPI The figure 3 shows a working view of the VS NET 2005 software used in the project 2 DigiCompas Microsoft Visual Studio File Edit View Project Build Debug Data Tools Window Community Help i g 3d Debu Any CPU z M i ACT E E LJ Program cs LCD cs BusIO cs Solution Explorer Solution 2 X Ex o8 e ERE Fusing System ge Solution DigiCompas 1 project Lusing Microsoft SPOT E DigiCompas w aa Properties H References Resources e BusIO cs e amp t LCD cs Program cs i gd Resources resx addresss of the sensor bus const byte DEFAULT ADDRESS 0x60 the default adres Jeun dx 3 1a 88 E namespace DigiCompas Class implements functionality of the sensor board to re class Sensor IDisposable narameter iregister number or adress of the reciste TIT Output Show output from Build Se Build started Project DigiCompas Configuration Debug Any CPU a Error List E Output Build started Figure 3 IDE for VS NET 2005 The Micro Framework offers embedded sys
28. ced Instruction Set Computer GUI Graphical user interface It allows people to interact with a computer and computer controlled devices GPS Global Positioning System is a navigation precise positioning tool uses satellites to determine position of the subject worldwide VS NET Visual Studio NET is software based programming language also known as c sharp it is used to develop console and GUI applications along with windows applications Console Console application is a computer program designed to be used by the text only computer interface P SDK Software development kit is a set of development tools which allow a user or a software engineer to create applications for a specific software package Emulator An emulator is the software used to perform emulation of the hardware used by a system Emulation is the simulation of silicon chips or integrated circuits used in a hardware system using computer software SPI Serial peripheral interface bus is a simple Master Slave 4 wire protocol one for synchronous clock SCL one for data transmitting one for data receive and another for chip select Chip Select It is a control line that selects one chip out of several connected to the same computer bus GPIO General purpose input output pins UART Universal Asynchronous Receiver Transmitter controller is the key component of the serial communications subsystem of a computer The UART takes bytes of data and transmits the individua
29. dStart TimerThreadPrac TimerThread Start Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 36 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report void TimerThreadProc while this TimerThread IhreadState ThreadState Running Stopped Dispatcher peration op this Dispatcher BeginInvoke new VoidProcDelegate base Invalidate op Wait Thread Sleep 100 Override default rendering method to paint a custom screen public override void OnRender DrawingContext dc fill the entire background with the background color de DrawRectangle this Background null 0 0 dc Width dc Height calcuate the center points of the screen int cx dc Width bmpCompass Width 2 int cy dc Height bmpCompass Height 2 points where Image for angle will be displayed int ax dc Width bmpAngle Width 2 int ay 2 paint compass image and angle text box de Drawlmage bmpAngle ax ay 15 dc DrawImage bmpCompass cx cy 30 calculate different values to be used to display angle and named directions float fAngle compass GetAzimuth fAngle 360 fAngle fangle value is given by the board precision to 2 desimal points fAngle float int fAngle 10 10 0 string Angle fAngle ToString Calulating the direction int Dir System Math Abs int fAngle 22 5 string
30. e application lt summary gt public static void Main Init and run the application main window App theApp new App theApp Run theApp MainWindow endregion region Constructor lt summary gt Constructor for the application object lt summary gt remarks Creates a new Full Screen LCD Window as the main window for the application X remarks App base App ButtonDefa this MainWindow new LCD this MainWindow Height SystemMetrics ScreenHeight this MainWindow Width SystemMetrics ScreenWidth Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 33 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report I fendregion region Button Definitions summary Button Definitions for this application lt summary gt f f remarks For Demo purposes defines all the directions and select button Currently the only one actually used in this application is the select button f f lt remarks gt static ButtonDefinition ButtonDefs dd button definitions for application new ButtonDefinition Button Up true Tahoe Pins 5W5 new ButtonDefinition Button Left true Tahoe Pins 5W6 new ButtonDefinition Button Select false Tahoe Pins 5W7 new ButtonDefinition Button Right true Iahoe Pins 5W8 new ButtonDefinition Button Down true TIahoe Pins 5W3 E fendregion LCD cs using
31. ed and assigned to specific categories of devices Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report The three less significant bits are programmable through hardware address pins allowing up to eight different I2C address combinations and therefore allowing up to eight of that type of device to operate on the same I2C bus These pins are held high to VCC 1 or held low to GND 0 7 bit addressing allows up to 128 devices on the same bus but some of these addresses are reserved for special commands so the practical limit is around 120 Shown below is the diagram of the 12C bus terminology SDA Slawe Receiver 10 Figure 5 26 Bus Terminology Master device controls the SCL starts and stops the data transfer and controls the addressing of the other devices Slave device itself is addressed by the Master In case of the data transmitting and receiving that Master transmitter sends data to the slave receiver and the Master receiver requires data from the Slave transmitter The data bits are transferred after start condition The data transmission is byte oriented where 1 byte 8bit one acknowledge bit The most significant bit MSB always comes first During the first byte transfer Master is transmitter and address slave is receiver Sheraz Khan Malik i MXS
32. ent compass new Compassklement bkgColor this SmallFont this Child compass compass otartRendering I else LOAD INTRO SCREEN AGAIN CompassElement compass this Child as CompassElement compass Destroy compass Invalidate IntroScreen intro new IntroScreen this Child intro Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 35 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report intro StartRendering This class is responsible to display compass reading and GUI class CompassElement UlElement Sensor compass new Sensor Bitmap bmpCompass Resources GetBitmap Resources BitmapResources Compas3s Bitmap bmpAngle Resources GetBitmap Resources BitmapResources Angle Initialize the array of named directions 16 string Directions N NNE NE ENE E ESE SE 55E 5 55W SW WSW W WNW NW NNW N Split Private variables of the class CompassElement SolidColorBrush Background Font TextFont int ClockRadius 50 private bool Stopped Thread TimerThread private delegate void VoidProcDelegate Constructor for CompassFlement public CompassElement Color BkgColor Font TextFont this Background new SolidColorBrush BkgColor this TextFont TextFont public void Destroy stopped true public void StartRendering TimerThread new Thread new Threa
33. essed it will exit the intro screen and load the compass view screen else LOAD INTRO SCREEN AGAIN i CompassElement compass this Child as CompassElement compass Destrovi compass Invalidate t Introscreen intro new IntroScreen t this Child 5 intro intro S5tartRendering i Figure 13 LCD cs Reloading intro screen using else statement In above figure 13 it is showed that if the wrong button is pressed the program will invalidate the compass view screen and load the intro screen again using the else statement The LCD class has further two sub classes explained below 3 2 1 Class Compass Element The class compass element displays the compass reading and compass screen on to the LCD of the Tahoe board In this class the different images are displayed on to the compass screen The compass screen obtained is shown below Figure 14 Compass Screen Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 15 University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report UIElement t Sensor compass new Sensor Bitmap bmpCompass Resources GetBitmap Resources BitmapResources Compasa Bitmap bmpAngle Resources GetBitmap Resources BitmapResources Angle Figure 15 LCD cs code compass screen display The figure 15 shows how to display any bitmap image Any Bitmap file can be displayed using these lines of code any bitmap
34. file present in the resource folder of the programe can be displayed by using this part of the program code The picture format can be Bitmap as well as JPEG The above piece of code is simply accessing the bitmap files from the resources and displaying them as image on the LCD for compass and angle The images used are shown below Figure 16 a Picture used for angle and direction The figure 16 a shows the picture used to display the angle of the compass as well as the direction Figure 16 b Picture for analog compass display Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 16 University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report The picture figure 16 b was used for analog compass display with the help of the program code explained above and showed in figure 15 Both these images 16a 16b were displayed on the screen but before doing that the centre points of the screen were calculated which can be shown in the figure 16 below calcuate the center points of the screen int cx dc Width bmpCompass Width 2 int cy dc Height bmpCompass Height 2 Figure 17 LCD cs Calculating screen centre points The compass direction was displayed by using array method The compass direction was divided in 16 directions between 0 to 360 which gives a value of 22 5 That means the compass direction must change after eve
35. follows Core gt Embedded Fusion Meridian CPU gt Itis a microprocessor mounted at the back of the Tahoe platform operates at 100MHz gt Ithas a2MB flash and 8MB SDRAM GPIO gt Most pins are configurable as GPIO if not used for other purposes gt Minimum of 16 GPIO Pins Available up to 64 Communication and expansion busses gt 1x UART RS 232 DB9 connector gt 126 for external peripherals gt SPI Bus can use GPIOs for chip selects if required gt USB Function for application download and debug Timers and clocks gt timer output Optional input for programmable timer can use internal clock Pulse width modulator PWM Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report Power supply gt input gt Allows powering direct from USB Function port no additional supply needed gt 3 3V outputs for peripherals Shown below is the block diagram for Meridian CPU 2 1 LCD Connector 16x GPIO PWM OUT 16 Bit LCD 7 SPI MISO LT SPI MOSI SPI CLK zz SPI FRAME MXS J TIMER IN 17 TIMER OUT rocessor TART Txo Lx JUART1 RXD UART1 RTS Usb D USB Function 1 UART1 CTS Transceivet UART2 TXD UART2 RXD UART2 RTS UART2 CTS Power Supply JTAG Figure 2 Block diagram for Meridian CPU 1 2 8 SOFTWARE T
36. gital compass output on the Tahoe board using magnetic sensor and VS NET Micro Framework software The project achievements were e Ani MXS ARM Based Digital Compass was designed e he output of Digital compass was displayed on LCD of Tahoe board using sensor board and VS NET Micro Framework software For future development it was decided that an off set window will be introduced in the digital compass The output window will allow any user to set their true north according to their requirement For example if a user thinks that the true north showed by the compass has an error of about 5 degrees The user will press the selected button for the off set window A new screen will appear asking the user to enter off set value This off set window will appear after the second screen which is the compass screen or it could be accessed any time while the compass is running by pressing the selected button After entering the off set value the user will be able set the true north as required Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 30 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report REFERENCES Reference Number Reference Link http scign jpl nasa gov learn gos1 htm http en wikipedia org wiki Vs net http en wikipedia org wiki Console application http www mameworld net easyemu emuwhatis htm http www freebsd org doc en US 1ISO8859 1 a
37. he same lines of code were used for this class as discussed before in figure 15 Shown below is the picture of the intro screen of the compass Figure 21 Intro Screen for compass Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 19 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report private members Drivate Bitmap myPic E private Font myFont Figure 22 LCD cs Intro Screen display The exact same code was used to display the intro screen elements The pictures were accessed through the resource files and were displayed by using the program code in figure 21 3 3 BuslO cs The BuslO cs class is responsible for 12C communication protocol between the software and the hardware The class allows the software to communicate with the 12C bus of the Tahoe board This class manipulates the functionality of the I2C slave class which is provided with the SDK This class performs the read write operation on the required registers class BusIO IDisposable i Declaration of variables and constants public const int I2C SPEED 100 I2C Bus speed in KHz const int I2C TIMEOUT 5000 Timeout for the I2C operations private I2CDevice I25lave private byte registerBuffer new byte 1 0x00 1 private byte writeBuffer new byte 2 0x00 Ox00 This class manupulates the functionality of I2Cslave class which is provided with
38. he software used for the project was VS NET Micro Frame Work Version 2005 the Tahoe board is compatible with this software The NET Micro Framework is Microsoft s latest implementation of the NET Common Language Runtime CLR The most notable aspect of the NET Micro Framework is that it does not need any underlying operating system The Micro Framework requires very little in the way of system resources thus reducing the overall cost of a system The minimum memory resources are about 384K of FLASH ROM and 256K of RAM The Micro Framework first appeared in the MSN Direct Smart Personal Object Technology SPOT watches and devices In May of 2006 Microsoft announced it would make the NET Micro Framework available to the general embedded community through hardware partners The most noticeable use of the Micro Framework so far is the Windows Sideshow compatible devices built into many new laptops for Windows Vista Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS Universityof Hertfordshire i EI School of Electronic Communication and Electrical Engineering BEng Final Year Project Report The NET Micro Framework consists of two parts the Common Language Runtime and the Core Libraries The Common Language Run time is a system designed by Microsoft that executes Microsoft Intermediate Language or MSIL instructions The software is provided with an SDK called Tahoe SDK that plugs directly into Visual Studio 2005 and appli
39. hich changes direction with respect to the changing angle The angle changes with the change in direction of sensor board i e right or left Shown below is the picture of the compass screen displaying angle direction and compass needle Figure 30 Compass screen displayed on LCD Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 20 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report The direction name and compass needle direction showed in figure 30 is correct with respect to the angle measured by the sensor board It can be proved as follows Number of compass direction 360 16 22 5 Angle measured by the sensor board 119 8 Direction appearing on the display ESE East South East Measured angle compass direction 119 8 22 5 5 3 Approx 5 Whereas the divided direction names are N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW N Hence out of these directions starting from 0 ESE is the 5 number direction which has been displayed on the LCD screen and even the compass needle is pointing towards the same direction Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 26 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 5 RESULTS AND DISCUSSION This section of the report contains all the results obtained at the testing and implementat
40. ht angles to each other is used to compute the direction of the horizontal component of the Earth s magnetic field The compass also has an ADC which converts the analog signal into digital signal Shown below is the figure for CMPSO03 showing direction for its true north and its connections Pin 9 Ov Ground Pin 8 No Connect Pin 7 No Connect Pin 6 Calibrate Pin 5 Calibrating Pin 4 PAM Pin3 SDA Pin2 SCL Pin 1 KMZ51 M z aa ar mer L snl m NE Figure 4 CMPS03 connections 5 Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report PIN CONNECTIONS Pin 1 5 V The compass module requires a 5v power supply at a nominal 15mA There are two ways of getting the bearing from the module A PWM signal is available on pin 4 or an 120 interface is provided on pins 2 3 P Pin 2 3 are an 12C interface and can be used to get a direct readout of the bearing If the 12C interface is not used then these pins should be pulled high to 5v via a couple of resistors Around 47k is ok the values are not at all critical Pin 4 The PWM signal is a pulse width modulated signal with the positive width of the pulse representing the angle The pulse width varies from 1mS 0 to 36 99mS 359 9 in other words 100uS with a 1mS offset The signal goes
41. ing to the given connections The pin 6 was to be calibrated but it was left un connected as the calibration was done through the software Shown below is the picture of all the hardware components involved gt AAA ALL RENE LE COMPASS MODULE TAHOE PLATORM CONNECTING HEADERS Figure 6 Project Hardware components It was made sure that all the connections were accurate according to the data sheet before powering the board as it could result in damaging the board Extra care was taken while handling the compass module as it was sensitive to static charge In order to avoid that anti static wrist band was used which was provided in the laboratory to avoid the hazard of static charge Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 10 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report Shown below is the block diagram of the project hardware part showing all the connections from the sensor board to the I2C bus on the Tahoe board Input 5 V DB9 Connector USB 0 V Ground No Connect No Connect Calibrate No Connect Magnetic Sensor 5V CMPS03 5 5 gt Hard Buttons Figure 7 Project Block Diagram Problems faced during the hardware connection were as follows e Lose connection due to weak soldering An inverted connection SDA of the sensor board was connected to the SCL of the Tahoe board e One of the he
42. ion stage f the project The results obtained were as expected and were satisfying the objective of the project i i 1 e l Figure 31 Working Compass intro screen The figure 29 is showing the picture of the whole project running and displaying the intro screen which shows that the software and the hardware are working correctly Also it can be seen that the sensor board is connected to the Tahoe board The button labelled as SW7 is the select button which allows the user to move on to compass screen by pressing it These pictures were taking at the project demonstration time Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report Figure 32 Working Compass screen displayed Figure 30 shows the working display of the project as Digital Compass It can be seen that the angle is displayed in degrees and the name of the direction is also displayed Also the compass needle is pointing in the direction displayed From the results it can be seen that the project was a success in terms of achieving the required task It meets the brief of developing an i MXS ARM Based Digital Compass device that directs the user towards the wanted direction based on its true north The results also justify all the details explained above in the report regarding the project Sheraz
43. l bits in a sequential fashion At the destination a second UART re assembles the bits into complete bytes P IDE Integrated development environment EEPROM Electronically Erasable Programmable Read Only Memory Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS vi Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 1 INHODUCTION The project involves designing an i MXS ARM Based Digital Compass Digital compasses have a great importance in today s world The modern technology has empowered mankind to travel distant places Compasses have played a vital role in many ways and are still being used with a great importance The people from the old age used different ways to direct them towards their destinations Compasses have made this job easier for today s generation They are being used in aircrafts robots navigation systems GPS receivers sports watches submarines and etc This report contains various stages of work involved in designing the digital compass and all the techniques and methodology used to achieve the required result 1 1 PROJECT AIMS AND OBJECTIVES The project aim was to design an I MXS ARM Based Digital Compass with the help of the provided Tahoe development kit and selecting a suitable magnetic sensor The objective of the project was to display output of the digital compass on the Tahoe board by interfacing it with a suitable mag
44. le code used has been highlighted CMPSO03Compass cs using System using Microsoft SP0T using Microsoft S5POT Hardware using Devantech Hardware using System Threading namespace Devantech Hardware CMP503 lt summary gt Implements functionality of the Devantech CMP503 Compass lt summary gt lt example gt fff lt code gt using CMPSO3Compass compass new CMPS03Compass 1 ii Gets actual azimuth ffi float azimuth compass GetAzimuth fff lt code gt example public class CMPSO0SCompass IDisposable IChangableAddress i region Constants const byte DEFAULT ADDRESS 0x60 const byte REG REVISION 0 const byte REG BEARING 1 const byte REG AZIMUTH HIGH 2 const byte REG UNLOCK 1 12 const byte REG COMMAND 15 const byte FACTORY RESET 1 0x55 const byte FACTORY RESET 2 0x54A const byte FACTORY RESET 3 xA 5 const byte FACTORY RESET 4 OxF 2 Fendregion Sheraz Khan Malik 5 ARM BASED DIGITAL COMPASS 44 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report fregion Constructors summary CMP503 Compass Module on default address OxCO 0x60 summary public CMPS03Compass this CMPS503Compass DEFAULT ADDRESS CMP503 Compass Module lt summary gt lt param name deviceAddress gt 7bit
45. low for 65mS between pulses so the cycle time is 65mS the pulse width i e 66ms 102ms The pulse is generated by a 16 bit timer in the processor giving a 1uS resolution It was to be made sure that the 20 pins SCL and SDA were connected to the 5v supply if PWM was used as there are no pull up resistors on these pins P Pin 5 is used to indicate calibration is in progress active low An LED can be connected from this pin to 5v via a 390 ohm resistor if user wishes Pin 6 is one of two ways to calibrate the compass the other is writing 255 OxFF to the command register The calibrate input has an on board pull up resistor and can be left unconnected after calibration P Pins 7 and 8 are left unconnected as they have on board pull up resistors Pin 9 is ground OV power supply 2 2 12C INTERFACING The I2C bus is a two wired bus serial data line SDA and serial clock line SCL usually to interact within small number of divisions It can operate at different speeds 100kbps standard mode 400kbps fast mode and 3 4Mbps high speed mode The data transfer in I2C bus is bi directional and is 8 bit oriented and is in form of serial data On an I2C bus any 20 device can be attached and every device can talk with any master passing information forward and backward Each device has a unique 7 bit I2C address so that the master knows specifically whom they are communicating with Typically the four most significant bits are fix
46. netic sensor and using the VS NET Micro Framework software 1 2 RESEARCH The project research stage was to develop understanding for the steps involved in design and working of digital compasses The research process was carried out in order to understand the working of the hardware as well as designing the software which was achieved by using internet and web based data The main purpose of research stage was to get all the basic information about the project and understand the steps involved in developing a digital compass using the provided components 1 2 1 TAHOE DEVELOPMENT KIT The Tahoe development kit was provided by the university The Tahoe platform provides an ideal development system for Meridian CPU and NET Micro Framework The Tahoe platform includes e 1 Tahoe Board e 1 USB cable e A VS NET 2005 installation disk e SDK with customise emulator for NET Micro Framework Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 1 2 2 TAHOE BOARD The Tahoe board is a fully functional system allowing an infinite variety of expansion via support for serial SPI and 12C communications Shown below is the Figure of the Tahoe board BibeddedFusion 2006 TAHOE v2 0 Poivered by Fusion Ware Figure 1 Tahoe Board 8 The technical specifications of the board are as
47. ompass and to make it look even better a GUI was created by making modifications to the same code Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS i University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report ACKNOWLEDGEMENTS would like to express my gratitute and appreciation to my project supervisor Kate Williams for encouraging me for my work with her advice and moral support would also like to thank Mr John Willmort in Lab c 460 who provided peaceful working environment and helped me regarding general problems in the project lab Finally would like to thank my parents as well as my friends Owais Tafseer Saad Bilal and Gurpreet who encouraged me throughout my project Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS i Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report TABLE OF CONTENTS DECLARATION STATEMENT reseed i ABSTRAC i TABLE See gu Ipo satan iii PSU MIC
48. public Il2CSlave byte deviceAddress this deviceAddress I2C SPEED fendregion region Read Operations lt 3ummary gt Generic read operation from I2C slave lt summary gt lt param name readBuffer Buffer for output lt param gt public void Read byte readBuffer I2CDevice I2CTransaction xact new I2CDevice I2CTransaction slavebDevice CreateReadTransaction readBuffer lock slaveDevice i int bytesCount slaveDevice Execute xact I2051ave I12C TIMEOUT if bytesCount readBuffer Length throw new system 10 IOException Resources StringResources Errorl2CCommunication ToString i i summary fii Reads register from I2C slave Ii lt summary gt Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 49 Universityof Hertfordshire i EI School of Electronic Communication and Electrical Engineering BEng Final Year Project Report lt param name register Register address lt param gt lt param name readBuffer Buffer for output lt param gt public void ReadRegister byte register byte readBuffer _registerBuffer 0 register Write registerBuffer Read readBuffer fendregion amp region Write Operations lt summary gt Generic write operation from I 2C slave jii lt summary gt lt param name writeBuffer Buffer for input lt param gt public void Write byte writeBuffer i I2CDevice I2CTransaction
49. ransaction l ft I25lave CreateWritelransaction writeBurtfer H lock I25lave i int bytesCount I251lave Execute xact I2C TIMEOUT it bytesCount lt writeBuffer Length throw new 5ystem IO IOException IO Error Figure 25 BuslO cs Write operations In figure 25 the program code writes the port on the I2C bus The Execute method here will write bytes on the I2C bus and returns the number of bytes successfully on the bus The process taking place in this part of code is similar to the one explained for code in figure 24 the only difference is that this time the code is performing the write operation instead of read operation Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 21 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 3 4 Sensor cs The sensor class implements the functionality of the sensor board to read the compass values in degrees class S5Sensor IDisposable t const byte DEFAULT ADDRESS 0x60 const byte REG AZIMUTH HIGH 2 private BusIO I2Bus private byte _dataBuffer new byte 2 0x00 0x00 1 Figure 26 Sensor cs showing address of register and sensor bus This part of the program code Figure 26 assigns address to the sensor bus The address used is 60 as it was the default address given for the sensor board In the next step the compass heading is taken from the register 2 As explained above
50. rticles serial uart index html http www embeddedfusion com uploadedFiles products TahoeDetailSheet pdf http www embeddedfusion com default aspx id 76 http www sensorsmag com articles 0399 0399 18 http www robot electronics co uk htm cmpsStech htm http www nxp com products interface control i2c facts http www robot electronics co uk acatalog examples html Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 31 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report BIBLIOGRAPHY BOOKS TITLE AUTHOR X Visual 2005 a developer s notebook JESSE LIBERTY mE Programming C Jesse Liberty JESSE LIBERTY IP Professional CZ 2005 with NET 3 0 CHRISTIAN NAGEL Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 32 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report APPENDIX 1 PROJECT CODE Program cs using System using Microsoft SPOT using Microsoft SPOT Input using Microsoft SPOT Hardware using Microsoft SPOT Presentation using Microsoft SPOT Presentation Media using EmbeddedFusion SPOT Hardware namespace DigiCompas lt summary gt Core apllication object for the application lt s3ummary gt public class App EmbeddedFusion SPOT A pplication region Application Entry Point aummary Main entry point for th
51. ry 22 5 degrees The array was assigned with 16 numbers Initialize the array of named directions 16 atring Directions N NNE NE ENE E ESE SE 55E 5 53 5W WSW W WNW NW N Split Figure 18 LCD cs array method for direction The process was very simple On getting the angle value from the sensor board the value was then divided with the calculated value 22 5 It gives a number between 1 16 and depending on the number the array displays the direction The figure 18 below shows the piece of code for the process explained Calulating the direction int Dir System Math Abs int fAngle 22 5 string DirName Directions Dir Direction name dc DrawText Angle this TextFont Colors Green bmpA ngle Width 2 25 dc DrawText DirName this TextFont Colors Green bmpAngle Width 2 70 25 Figure 19 LCD cs Calculating directions The last two lines of the code in figure 19 are drawing text for angle and direction on the screen with a selected green colour and also calculating the points where the text should be displayed or in other words the parameters for the text and angle The direction calculation can be shown for example if we assume the angle value to be 45 degrees Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 17 Universityof Hertfordshire We have 45 Calculated value for directions 22 5 8 4 225 22 5 2 Hence the calculated direction
52. s I2C functionality for the Devantech hardware lt summary gt public class I2CS5lave IDisposable lt summary gt KHz speed of the I2C bus lt summary gt public const int I2C SPEED 100 summary Address change command 1 for Devantech devices lt summary gt public const byte ADDRESS CHANGE 1 lt summary gt Address change command 2 for Devantech devices lt summary gt public const byte ADDRESS CHANGE 2 xAA lt summary gt Address change comme lt summary gt public const byte ADDRESS CHANGE 3 XAS nd 3 for Devantech devices summary I2C operations timeout lt summary gt const int I2C TIMEOUT 5000 region Constructors lt summary gt Creates instance of the slave lt summary gt lt param name deviceAddress 7bit device addressc paranb lt param name busSpeed gt Speed of the I2C buse param public I2CSlave byte deviceAddress int busSpeed Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 48 University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report this slaveDevice new 2CDevice new I2CDevice Configuration deviceAddress busSpeed I lt 3ummary gt Creates instance of the I2C slave lt summary gt lt param name deviceAddress 7bit device address lt param gt
53. set value of 90 So the default position of the compass angle was 90 The compass needle was to be drawn according to the clock radius of the blue circle in the compass picture shown in figure 16 b It was approximately 50 pixels Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 18 University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report The value of the clock radius was first defined at the top of the program code in Private variables The compass needle was then drawn by taking Cos and Sine of the compass angle Initially it resulted in a big value giving the compass needle an abnormal length To avoid this calculated value was then divided by 1000 to get it to unity As we know that the value for Sine and Cos is between 0 1 after that it was then multiplied by 50 clock radius which controlled the length of the compass needle according to the clock radius of the blue circle To obtain the full length of the compass needle the same code was used by adding a negative sign to it which gave a compass needle of similar length but on the opposite direction To differentiate the opposite side its colour was changed to black 3 2 2 Class Intro Screen As from the name it shows that this class is responsible for loading the intro screen onto the LCD screen of the Tahoe board T
54. sion S5SPOT Application i PAR in Application Entry Point T lt summary gt Main entry point for the application c summar ere static void Main t Init and run the application main window App theApp new App theApp Run theApp MainWindow fendregion Figure 9 Program cs code for main window Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 12 University of Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report It shows in figure 9 that this class allows to initiate and run the main window application The main window application is like a starting point for the class fregion Button Definitions lt summary gt Button Definitions for this application lt summary gt zremarks For Demo purposes defines all the directions and select button Currently the only one actually used in this application is the select button c remarks static ButtonDefinition ButtonDefs t Add button definitions for application BucttonDefinition Button Up true Tahoe Pins 5W5 BurttonDefinition Button Left true Tahoe Pins 5W6 ButcttonDefinition Button Select false Tahoe Pins SwWT ButtonDefinition Button Right true Tahoe Pins 5W8 ButtonDefinition Button Down true Tahoe Pins 5W9 e 1 fendregion Figure 10 Program cs code for button definitions The above figure 10 is showing the button definition part of the class Program
55. tart TimerThreadProc TimerThread Start t0 DateTime Now void TimerThreadProc loop while thread stop flag is not set or while thread state is not changed while this TimerThread ThreadState ThreadState Running Stopped Dispatcher peration op this Dispatcher BeginInvoke new VoidProcDelegate base Invalidate op Wait Thread Sleep 100 BuslO cs using System using Microsotft SPOT using Microsoft 5POT Hardware namespace DigiCompas class BusIO IDisposable i Declaration of variables and constants public const int I2C SPEED 100 I2C Bus speed in KHz const int I2C TIMEOUT 5000 Timeout for the I2C operations private I2CDevice I25lave private byte registerBurfer new byte 1 i 0x00 1 private byte writeBuffer new byte 2 0x00 0x00 1 Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 40 Universityof Hertfordshire i EI School of Electronic Communication and Electrical Engineering BEng Final Year Project Report public BuslO byte Address I251ave new I2CDevice new I2CDevice Configuration Address I2C SPEED summary Geniric Read Operation to read any port on the bus i summary lt param name readBuffer gt lt param gt public void Read byte readBuffer I2CDevice I2CTransaction xact new I2CDevice I2CTransaction I251ave CreateReadTransaction readBuffer E lock I251ave
56. te output rray ByteOrder byte rder if byteOrder Byte rder BigEndian ToBigEndian number output rray else throw new NotImplementedException Resources StringResources NotImplementedLittleEndian ToStringl lt summary gt Splits number into the byte array in Big Endian lt summary gt lt param name number Number to split lt param gt lt param name outputlrray Array where the bytes be stored lt param gt public static void ToBigEndian long number byte outputArray int length outputArray Length Sheraz Khan Malik 5 ARM BASED DIGITAL COMPASS o3 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report Qutput rray length 1 byte number for int 1 length 2 1 0 1 outputArray 1 byte number gt gt 8 111 lt summary gt Gets value from array byte organized as Big Endian lt summary gt lt param name bytedrray gt Byte array parau lt param name startIndex Start index param lt param name length Number of bytes to parse lt param gt returns Long value lt returns gt private static long FrouBighndian byte byteArray int startIndex int length long retValue 0 int stopIndex startIndex length 1 for int 1 startIndex 1 stopIndex 1H retValue byteArray i retValue retValue lt lt 8 return retValue
57. tems developers a line of CPUs that essentially directly execute MSIL There is no need for low level assembly language or other proprietary languages You can use the standardized C language to implement a complete embedded system from handling interrupts to displaying a rich Graphical User Interface GUI u Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS Universityof Hertfordshire i EI School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 1 2 4 MAGNETIC SENSOR In the project one of the important tasks was to decide which magnetic sensor must be used for compassing as there were a lot of magnetic sensors available in market There was a variety of magnetic sensors available for compassing depending upon their output including 1 axis two axis and three axis magnetic sensors Magnetic sensors 9l detect changes or disturbances in magnetic fields that have been created or modified and from them derive information on properties such as direction presence rotation angle or electrical currents The output signal of these sensors requires some signal processing for translation into the desired parameter Although magnetic detectors are somewhat more difficult to use they do provide accurate and reliable data without physical contact A magnetic field is a vector quantity with both magnitude and direction The scalar sensor measures the field s total magnitude but not its direction
58. tfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report summary this class displays the intro screen on lcd 44 lt summary gt class IntroScreen UlElement private members private Bitmap myPic Resources GetBitmap Resources BitmapResources myPic private Font myFont Resources GetFont Resources FontResources myfont private string myIext caption private bool Stopped stopping flag for thread Thread TimerThread rendering thread DateTime t0 int frames 0 Color clr Colors Green private delegate void VoidProcDelegate public override void OnRender DrawingContext dc draw background image and the blinking text on top int px dc Width myPic Width 2 left of the image int py dc Height myPic Height 2 top of the image dc DrawImage myPic px py if frames gt 2 togge color of caption and reset the framecount frames 0 clr clr Colors Red Colors Green Colors Red framest increment framecount draw the blinking caption dc Drawlext mylext myFont clr 5 150 I public void Destroy stopped true Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 39 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report public void StartRendering create and start the rendering thread TimerThread new Thread new ThreadS
59. the register 2 and 3 get compass bearing as a word i e 0 3599 for a full circle representing 0 359 9 degrees of angle public float GetAzimuth i read higher register into the buffer dataBuffer I2Bus ReadRegister REG AZIMUTH HIGH dataBurrer convert bytes to float value and return the value to calling function return GetValue dataBuffer ByteOrder BigEndian y Xl function to convert bytes to float value public long GetValue byte byteArray ByteOrder byteOrder i if byteOrder ByteOrder BigEndian return FromBigEndian byteArray 0 byteArray Length else throw new NotlImplementedException Not Implemented Figure 27 Sensor cs getting compass heading This section of program code Figure 27 gets the Azimuth value from the sensor board and then reads the register value when it is high into the data buffer The next step it shows that the byte order is set using Big Endian Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 22 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report The Big Endian means the big end first which means that the high order bytes are stored first into the low memory location Then it converts the receiving bytes into float decimal type and returns the value to the calling function If the condition is not satisfied then it uses the else statement to display an error message Shera
60. xact new I 2CDevice I2CTransaction SlaveDevice CreateWriteTransaction writeBuffer H lock slaveDevice int bytesCount slaveDevice Execute xact I2C5lave I C TIMEOUT if bytesCount writeBuffer Length throw new System IO IGOException Resources StringResources Ekrrorl2CCommunication ToString lt summary gt Writes data into register lt summary gt lt param name register Register address lt param gt lt param name value gt Data to write lt param gt public void WriteRegister byte register byte value writeBuffer O register Sheraz Khan Malik i MXS ARM BASED DIGITAL COMPASS 50 Universityof Hertfordshire School of Electronic Communication and Electrical Engineering BEng Final Year Project Report writeBuffer 1 value Write writeBulfer I summary Writes data into register lt summary gt lt param name register Register address lt param gt lt param name writeBuffer Buffer for input lt param gt public void WriteRegister byte register byte writeBuffer byte data new byte writeBuffer Length 1 Array Copy writeBuffer 0 data 1 writeBuffer Length Set first byte as the register address data 0 register Write data I endregion summary Chnange I2C address of the slave Note Suitable for most Devantech devices f f lt summary gt lt param name commandRegister
61. z Khan Malik i MXS ARM BASED DIGITAL COMPASS 23 Universityof Hertfordshire i EI School of Electronic Communication and Electrical Engineering BEng Final Year Project Report 4 PROJECT TESTING AND WORKING This section of the report contains the project testing on hardware as well as software basis and the problems faced during the software and hardware testing The hardware was tested with the help of software All the communication and expansion buses of the Tahoe board were tested at very initial stage to confirm that the board itself was working perfectly This was done by running default test programs provided with the software for the each communication bus It helped in understanding the nature of the hardware as well as the software In hardware there were problems faced during testing of the SPI bus it kept on showing error messages which was then rectified by making changes to the test program code It helped in understanding the debugging process which later on helped in software testing After connecting the sensor board with Tahoe board the software was then tested before the final testing of the whole project The software testing was carried throughout the program code development process Initially there were errors in the program code Debugging was carried out constantly to make sure that the program code was correctly working before testing it with the hardware The debugging process helped in error diagnosis
Download Pdf Manuals
Related Search
Related Contents
ePOS-Print SDK for Android ユーザーズマニュアル ラダー415530表紙 [更新済み] Kanex TBOLT1M Apparatus for monitoring and/or controlling a medical device MP-252 WDNB All-In-One Integrated Access Device Release Notes COBY electronic MP-C855 User's Manual Triarch 32315 User's Manual HUVUDRUBRIK 1 Monacor MMC-300/SW AOC e2425Swd Copyright © All rights reserved.
Failed to retrieve file