NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.

Dependencies:   mbed MODI2C

Files at this revision

API Documentation at this revision

Comitter:
maetugr
Date:
Thu Oct 25 19:27:56 2012 +0000
Parent:
12:67a06c9b69d5
Child:
14:cf260677ecde
Commit message:
Vor wechsel Comp -> Mag

Changed in this revision

InterruptControl/IntCtrl.cpp Show annotated file Show diff for this revision Revisions of this file
InterruptControl/IntCtrl.h Show annotated file Show diff for this revision Revisions of this file
InterruptControl/IntCtrl.lib Show annotated file Show diff for this revision Revisions of this file
Sensors/Comp/HMC5883.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/InterruptControl/IntCtrl.cpp	Thu Oct 25 19:27:56 2012 +0000
@@ -0,0 +1,110 @@
+// Funktionen zur Interruptkontrolle bei IO-Ports
+//---------------------------------------------------------------------------------------------------------------------------------------
+#include "mbed.h"                       //muss immer geladen werden
+#include "IntCtrl.h"
+
+
+
+// Enable GPIO Interrupt (nur fuer  P0.0..P0.30 und P2.0..P2.13)
+// PortNumber = 0 oder 2, BitPosition = 0..31, RiseFall: 0 = rise, 1 = fall, 2 = rise and fall
+//-------------------------------------------------------------------------------
+void GPIO_IntEnable(char PortNumber, char BitPosition, char RiseFall)
+    {
+    switch ( PortNumber )
+        case 0:
+            {
+            switch ( RiseFall )
+                {
+                case 0:
+                    LPC_GPIOINT->IO0IntEnR |= (0x1<<BitPosition);
+                break;
+                
+                case 1:
+                    LPC_GPIOINT->IO0IntEnF |= (0x1<<BitPosition);
+                break;
+                
+                case 2:
+                    LPC_GPIOINT->IO0IntEnR |= (0x1<<BitPosition);
+                    LPC_GPIOINT->IO0IntEnF |= (0x1<<BitPosition);
+                break;
+ 
+                default:
+                break;
+               }
+            
+        case 2:
+            {
+            switch ( RiseFall )
+                {
+                case 0:
+                    LPC_GPIOINT->IO2IntEnR |= (0x1<<BitPosition);
+                break;
+                
+                case 1:
+                    LPC_GPIOINT->IO2IntEnF |= (0x1<<BitPosition);
+                break;
+                
+                case 2:
+                    LPC_GPIOINT->IO2IntEnR |= (0x1<<BitPosition);
+                    LPC_GPIOINT->IO2IntEnF |= (0x1<<BitPosition);
+                break;
+
+                default:
+                break;
+                }
+            }
+        }
+    }
+            
+
+// Disable GPIO Interrupt (nur fuer  P0.0..P0.30 und P2.0..P2.13)
+// PortNumber = 0 oder 2, BitPosition = 0..31, RiseFall: 0 = rise, 1 = fall, 2 = rise and fall
+//-------------------------------------------------------------------------------
+void GPIO_IntDisable(char PortNumber, char BitPosition, char RiseFall)
+    {
+    switch ( PortNumber )
+        case 0:
+            {
+            switch ( RiseFall )
+                {
+                case 0:
+                    LPC_GPIOINT->IO0IntEnR &= ~(0x1<<BitPosition);
+                break;
+                
+                case 1:
+                    LPC_GPIOINT->IO0IntEnF &= ~(0x1<<BitPosition);
+                break;
+                
+                case 2:
+                    LPC_GPIOINT->IO0IntEnR &= ~(0x1<<BitPosition);
+                    LPC_GPIOINT->IO0IntEnF &= ~(0x1<<BitPosition);
+                break;
+ 
+                default:
+                break;
+               }
+            
+        case 2:
+            {
+            switch ( RiseFall )
+                {
+                case 0:
+                    LPC_GPIOINT->IO2IntEnR &= ~(0x1<<BitPosition);
+                break;
+                
+                case 1:
+                    LPC_GPIOINT->IO2IntEnF &= ~(0x1<<BitPosition);
+                break;
+                
+                case 2:
+                    LPC_GPIOINT->IO2IntEnR &= ~(0x1<<BitPosition);
+                    LPC_GPIOINT->IO2IntEnF &= ~(0x1<<BitPosition);
+                break;
+
+                default:
+                break;
+                }
+            }
+        }
+    }
+            
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/InterruptControl/IntCtrl.h	Thu Oct 25 19:27:56 2012 +0000
@@ -0,0 +1,36 @@
+#ifndef __INTCTRL_H
+#define __INTCTRL_H
+
+extern void GPIO_IntEnable(char PortNumber, char BitPosition, char RiseFall);
+extern void GPIO_IntDisable(char PortNumber, char BitPosition, char RiseFall);
+
+
+/* mbed DIP Pin     LPC1768 Pin
+        p5      =   P0_9
+        p6      =   P0_8
+        p7      =   P0_7
+        p8      =   P0_6
+        p9      =   P0_0
+        p10     =   P0_1
+        p11     =   P0_18
+        p12     =   P0_17
+        p13     =   P0_15
+        p14     =   P0_16
+        p15     =   P0_23
+        p16     =   P0_24
+        p17     =   P0_25
+        p18     =   P0_26
+        p21     =   P2_5
+        p22     =   P2_4
+        p23     =   P2_3
+        p24     =   P2_2
+        p25     =   P2_1
+        p26     =   P2_0
+        p27     =   P0_11
+        p28     =   P0_10
+        p29     =   P0_5
+        p30     =   P0_4
+*/
+
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/InterruptControl/IntCtrl.lib	Thu Oct 25 19:27:56 2012 +0000
@@ -0,0 +1,1 @@
+IntCtrl#000000000000
--- a/Sensors/Comp/HMC5883.cpp	Sat Oct 20 17:28:28 2012 +0000
+++ b/Sensors/Comp/HMC5883.cpp	Thu Oct 25 19:27:56 2012 +0000
@@ -3,6 +3,8 @@
 
 HMC5883::HMC5883(PinName sda, PinName scl) :  local("local"), i2c(sda, scl)
 {
+    i2c.frequency(400000); // zu testen!!
+    
     // load calibration values
     FILE *fp = fopen("/local/compass.txt", "r");
     for(int i = 0; i < 3; i++)
--- a/main.cpp	Sat Oct 20 17:28:28 2012 +0000
+++ b/main.cpp	Thu Oct 25 19:27:56 2012 +0000
@@ -1,24 +1,26 @@
 #include "mbed.h"       // Standard Library
 #include "LED.h"        // LEDs framework for blinking ;)
-#include "PC.h"         // Serial Port via USB for debugging in TeraTerm (driver needed: https://mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe)
+#include "PC.h"         // Serial Port via USB by Roland Elmiger for debugging with Terminal (driver needed: https://mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe)
 #include "L3G4200D.h"   // Gyro (Gyroscope)
 #include "ADXL345.h"    // Acc (Accelerometer)
 #include "HMC5883.h"    // Comp (Compass)
 #include "BMP085.h"     // Alt (Altitude sensor)
 #include "RC_Channel.h" // RemoteControl Chnnels with PPM
 #include "Servo.h"      // Motor PPM
-#include "PID.h"        // PID Library from Aaron Berk
+#include "PID.h"        // PID Library by Aaron Berk
+#include "IntCtrl.h"    // Interrupt Control by Roland Elmiger
 
 #define PI              3.1415926535897932384626433832795
 #define Rad2Deg         57.295779513082320876798154814105
 #define RATE            0.02 // speed of Ticker/PID
 
-//#define COMPASSCALIBRATE
+//#define COMPASSCALIBRATE decomment if you want to calibrate the Compass on start
 
 Timer GlobalTimer; // global time to calculate processing speed
 Ticker Datagetter; // timecontrolled interrupt to get data form IMU and RC
 PID controller(1.0, 0.0, 0.0, RATE); // test PID controller for throttle
 PID pid(1.0, 1.0, 0.0, RATE); // test PID controller for throttle
+//PID P:3,0 bis 3,5 I:0,010 und 0,050 D:5 und 25 
 
 // initialisation of hardware
 LED         LEDs;
@@ -27,7 +29,7 @@
 ADXL345     Acc(p28, p27);
 HMC5883     Comp(p28, p27);
 BMP085      Alt(p28, p27);
-RC_Channel  RC[] = {(p10), (p11), (p12), (p13)}; // noooo p19/p20!!!!
+RC_Channel  RC[] = {(p11), (p12), (p13), (p14)}; // noooo p19/p20!!!!
 Servo       Motor[] = {(p15), (p16), (p17), (p18)};
 
 // variables for loop
@@ -45,11 +47,21 @@
 {
     time_read_sensors = GlobalTimer.read_us();
     
+    GPIO_IntDisable(0, 18, 2); // abschalten der Pins 11-14 mit Göttis library
+    GPIO_IntDisable(0, 17, 2);
+    GPIO_IntDisable(0, 16, 2);
+    GPIO_IntDisable(0, 15, 2);
+    //__disable_irq(); // test, deactivate all interrupts, I2C working?
     // read data from sensors
-    Gyro.read();
+    Gyro.read(); // einzeln testen! mit LEDs
     Acc.read();
     Comp.read();
-    //Alt.Update();
+    //Alt.Update(); TODO braucht zu lange zum auslesen!
+    //__enable_irq();
+    GPIO_IntEnable(0, 18, 2); // schaltet enable wirklich wieder ein?? änderungsbedarf??
+    GPIO_IntEnable(0, 17, 2);
+    GPIO_IntEnable(0, 16, 2);
+    GPIO_IntEnable(0, 15, 2);
     
     dt_read_sensors = GlobalTimer.read_us() - time_read_sensors;