acquisition de la position du AS5311

Dependencies:   C12832 SWSPI mbed

Fork of IonScan_DO_SPI by Noël Esnault

Files at this revision

API Documentation at this revision

Comitter:
Esnault
Date:
Wed Apr 11 14:53:34 2018 +0000
Commit message:
Version du 11/04/2018

Changed in this revision

C12832.lib Show annotated file Show diff for this revision Revisions of this file
SWSPI.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Wed Apr 11 14:53:34 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/askksa12543/code/C12832/#990d5eec2ef6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SWSPI.lib	Wed Apr 11 14:53:34 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Projets-S4-IUT-de-Cachan/code/SWSPI/#b16213e09287
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Apr 11 14:53:34 2018 +0000
@@ -0,0 +1,96 @@
+#include "mbed.h"
+#include "C12832.h"
+#include "SWSPI.h"
+#include <cmath>
+
+SWSPI spi(PC_4,PC_12,PA_13); // MOSI"bidon" / MISO /CLK
+
+C12832 lcd(D11, D13, D12, D7, D10);
+
+DigitalOut CS(PA_14);
+
+DigitalIn DO(PC_12);
+
+InterruptIn index(PA_15);
+
+double cpt_fall=0;
+
+float distance=0,cpt_rise=0,compteur_index=0;
+
+short cpt=0;
+
+long x=0,x1=0,pas,RAZ = 0,pos_finale=0, pos_initiale=0;
+
+
+
+void pressed()
+{
+    if (x >= 3000) {
+        cpt_rise++;
+    }
+    if (x <= 1000) {
+        cpt_rise--;
+    }
+
+}
+
+void released()
+{
+    cpt_fall++;
+}
+
+int main ()
+{
+    spi.format(18,3); //////////////////////////////////////
+    spi.frequency(100000);          // Initialisation SPI software
+    CS=1;
+    lcd.cls();/////////////////////////////////////////////
+
+    wait_ms(100);///////////////////////////////////////////
+    CS=0;
+    wait_us(50);
+
+    pos_initiale=spi.write(0);       //Determination pos_initialetion initiale
+
+    wait_us(50);
+    CS=1;
+    pos_initiale = pos_initiale>>5;/////////////////////////////////////////////
+
+    pos_finale=x-pos_initiale;
+
+    //pas = (abs(x-x1))%4095;
+    distance=((pos_finale*(0.000488)+(cpt_rise*2)));
+
+    while(1) {
+        pos_finale=x-pos_initiale;
+
+        index.fall(&pressed);
+        index.rise(&released);
+
+        wait_ms(100);
+        CS=0;
+        wait_us(50);
+
+        x1=x;
+        x=spi.write(0);
+
+        //pas = (abs(x-x1))%4095;
+        distance=((pos_finale*(0.000488)+(cpt_rise*2))); // Calcul de la distance parcouru depuis le 0 en mm
+
+        wait_us(50);
+        CS=1;
+        x = x>>5;
+
+        lcd.locate(0,3);
+        lcd.printf("DIST= %.5f",distance);
+        lcd.locate(0,14);
+        lcd.printf("POS= %5ld", x);
+
+        /*
+        lcd.locate(0,3);
+        lcd.printf("pos_initiale= %ld",pos_initiale);
+        lcd.locate(0,14);
+        lcd.printf("POS= %5ld", x);
+        */
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Apr 11 14:53:34 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/aa5281ff4a02
\ No newline at end of file