2016 Rotary Encoder program

Dependencies:   QEI i2cslave mbed

Fork of 2016_slave_rorikon_2 by hidaka sato

not used

Files at this revision

API Documentation at this revision

Comitter:
sgrsn
Date:
Tue Aug 16 05:24:27 2016 +0000
Commit message:
2016 Rotary Encoder program
;

Changed in this revision

QEI.lib Show annotated file Show diff for this revision Revisions of this file
define.h Show annotated file Show diff for this revision Revisions of this file
i2cslave.lib 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r f6b9d01fdda6 QEI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Tue Aug 16 05:24:27 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/sgrsn/code/QEI/#b9a5e2d6fbb9
diff -r 000000000000 -r f6b9d01fdda6 define.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/define.h	Tue Aug 16 05:24:27 2016 +0000
@@ -0,0 +1,27 @@
+/*Registar group*************************************/
+
+#define motor1_state    0x01
+#define motor2_state    0x02
+#define motor1_pwm      0x03
+#define motor2_pwm      0x04
+
+/*Address group*************************************/
+
+//MD : MotorDriver
+#define MD1_addr 0x12
+#define MD2_addr 0x14
+#define MD3_addr 0x16
+#define MD4_addr 0x18
+//RE : RotaryEncoder
+#define RE1_addr 0x10
+#define RE2_addr 0x20
+#define RE3_addr 0x30
+#define RE4_addr 0x40
+//PM : PotentioMeter
+#define PM1_addr 0x50
+#define PM2_addr 0x60
+#define PM3_addr 0x70
+#define PM4_addr 0x80
+//SE : Sensor
+#define SE1_addr 0x90
+#define SE2_addr 0xA0
\ No newline at end of file
diff -r 000000000000 -r f6b9d01fdda6 i2cslave.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/i2cslave.lib	Tue Aug 16 05:24:27 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sgrsn/code/i2cslave/#69b088a9899b
diff -r 000000000000 -r f6b9d01fdda6 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 16 05:24:27 2016 +0000
@@ -0,0 +1,71 @@
+#include "mbed.h"
+#include "QEI.h"
+#include "i2cslave.h"
+#include "define.h"
+
+union UNION
+{
+    int i;
+    char c[6];
+};
+
+UNION obj;
+
+DigitalOut led(dp28);
+void Func()
+{
+    obj.c[5]++;
+    //printf(" %d", obj.c[5]);
+    if(obj.c[5] > 2)
+    {
+        //obj.c[4] = 1;
+        NVIC_SystemReset();
+    }
+}
+
+
+QEI rorikon(dp1, dp2, NC, 50, QEI::X4_ENCODING);
+BusOut leds(dp26, dp24);
+Serial slave(dp16, dp15);
+
+int main()
+{
+    Ticker t;
+    t.attach(Func, 0.1);
+    i2cslave i2c(dp5, dp27, obj.c);
+    i2c.frequency(1000000);
+    /*change address every micon***********/
+    i2c.address(RE1_addr);
+    /**************************************/
+    double data = 0;
+    
+    NVIC_SetPriority(TIMER_16_0_IRQn, 5);
+    NVIC_SetPriority(TIMER_16_1_IRQn, 5);
+    NVIC_SetPriority(TIMER_32_0_IRQn, 5);
+    NVIC_SetPriority(TIMER_32_1_IRQn, 5);
+    NVIC_SetPriority(EINT3_IRQn, 20);
+    NVIC_SetPriority(EINT2_IRQn, 20);
+    NVIC_SetPriority(EINT1_IRQn, 20);
+    NVIC_SetPriority(EINT0_IRQn, 20);
+    NVIC_SetPriority(I2C_IRQn, 10);
+    
+    obj.c[4] = 1;
+    led = 0;
+
+    while(1)
+    {
+        data = rorikon.getSumangle();
+        if(data < 0.000)
+        {
+            obj.i = (int)(data*10)*(-1);
+            obj.c[4] = 0;
+            leds = 3;
+        }
+        else
+        {
+            obj.i = (int)(data*10);
+            obj.c[4] = 2;
+            leds = 0;
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r f6b9d01fdda6 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Aug 16 05:24:27 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/f9eeca106725
\ No newline at end of file