航空研究会 / Mbed 2 deprecated L6470_2

Dependencies:   mbed L6470

Files at this revision

API Documentation at this revision

Comitter:
imanomadao
Date:
Thu Feb 20 03:48:30 2020 +0000
Parent:
1:4944d8b2d813
Commit message:
a

Changed in this revision

L6470.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
--- a/L6470.lib	Thu Feb 20 03:26:34 2020 +0000
+++ b/L6470.lib	Thu Feb 20 03:48:30 2020 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/1519026547/code/L6470/#2f3be153718a
+https://os.mbed.com/teams/1519026547/code/L6470/#6cd6cd00aabe
--- a/main.cpp	Thu Feb 20 03:26:34 2020 +0000
+++ b/main.cpp	Thu Feb 20 03:48:30 2020 +0000
@@ -1,33 +1,29 @@
 #include"mbed.h"
+#include"L6470.h"
 
 
 //SPI l6470_R();
-SPI R(PA_7, PA_6, PA_5);
-DigitalOut cs_R(D10);
+//SPI R(PA_7, PA_6, PA_5);
+//DigitalOut cs_R(D10);
+
 
 RawSerial pc(USBTX, USBRX, 9600);
 
 Timer t;
 
-void L6470_init();
-void L6470_run(long);
-void writeByte();
-void write();
 
 int main()
 {
     pc.printf("****start_spi_test_program****\r\n");
     
-    R.format(8,2);
-    R.frequency(4960000);
-    
+    L6470 R(PA_7, PA_6, PA_5, D10);
     
-    L6470_init();
+    R.init();
     
-    t.start();
+    //t.start();
     int i = 0;
     do{
-    L6470_run(200);
+    R.L6470_run(200);
     i++;
     } while(i<100);
     //write(0xB8);
@@ -44,153 +40,3 @@
     
     }
     
-void writeBytes(int add, int bytes, long value)
-{
-    int data[3];
-    for (int i = 0; i < bytes; i++){
-        data[i] = value & 0xff;
-        value = value >> 8;
-    }
-    if(bytes == 3){
-        cs_R = 1;
-        R.write(add);
-        R.write(data[2]);
-        R.write(data[1]);
-        R.write(data[0]);
-        cs_R = 0;
-        }
-    else if ( bytes == 2 ) {
-            R.write( add );
-            R.write( data[1] ) ;
-            R.write( data[0] ) ;
-    }
-    else if ( bytes == 1 ) {
-        R.write( add );
-        R.write( data[0] ) ;
-    }
-}
-    
-    
-void write(unsigned char data)
-{
-    cs_R = 1;
-    R.write(data);
-    cs_R = 0;
-}
-
-
-
-void L6470_init()
-{
-        // nopを送ることで残留している命令を排除
-        cs_R = 1;
-        R.write(0x00);
-        R.write(0x00);
-        R.write(0x00);
-        R.write(0x00);
-        cs_R = 0;
-        
-        //リセット
-        cs_R = 1;
-        R.write(0xC0);
-        cs_R = 0;
-        
-        // MAX_SPEED設定。
-        /// レジスタアドレス。
-        cs_R = 1;
-        R.write(0x07);
-        // 最大回転スピード値(10bit) 初期値は 0x41
-        R.write(0x00);
-        R.write(0x23);
-        cs_R = 0;
-
-        // KVAL_HOLD設定。
-        /// レジスタアドレス。
-        cs_R = 1;
-        R.write(0x09);
-        // モータ停止中の電圧設定(8bit)
-        R.write(0xFF);
-        cs_R = 0;
-        
-        // KVAL_RUN設定。
-        /// レジスタアドレス。
-        cs_R = 1;
-        R.write(0x0A);
-        // モータ定速回転中の電圧設定(8bit)
-        R.write(0xFF);
-        cs_R = 0;
-        
-        // KVAL_ACC設定。
-        /// レジスタアドレス。
-        cs_R = 1;
-        R.write(0x0B);
-        // モータ加速中の電圧設定(8bit)
-        R.write(0xFF);
-        cs_R = 0;
-        
-        // KVAL_DEC設定。
-        /// レジスタアドレス。
-        cs_R= 1;
-        
-        R.write(0x0C);
-        // モータ減速中の電圧設定(8bit) 初期値は 0x8A
-        R.write(0x40);
-        cs_R = 0;
-        
-        // OCD_TH設定。
-        /// レジスタアドレス。
-        cs_R = 1;
-        R.write(0x13);
-        // オーバーカレントスレッショルド設定(4bit)
-        R.write(0x0F);
-        cs_R = 0;
-        
-        // STALL_TH設定。
-        /// レジスタアドレス。
-        cs_R = 1;
-        R.write(0x14);
-        // ストール電流スレッショルド設定(4bit)
-        R.write(0x7F);
-        cs_R = 0;
-}
-
-    
-void L6470_run(long speed)
-{
-        unsigned short dir;
-        unsigned long spd;
-        unsigned char spd_h;
-        unsigned char spd_m;
-        unsigned char spd_l;
-
-        // 方向検出。
-        if (speed < 0)
-        {
-                dir = 0x50;
-                spd = -1 * speed;
-        }
-        else
-        {
-                dir = 0x51;
-                spd = speed;
-        }
-
-        // 送信バイトデータ生成。
-        spd_h = (unsigned char)((0x0F0000 & spd) >> 16);
-        spd_m = (unsigned char)((0x00FF00 & spd) >> 8);
-        spd_l = (unsigned char)(0x00FF & spd);
-        // コマンド(レジスタアドレス)送信。
-        //cs_R = 1;
-        write(dir);
-        // データ送信。
-        write(spd_h);
-        write(spd_m);
-        write(spd_l);
-        //cs_R = 0;
-}    
-    
-
-    
-    
-    
-