Goertek_Mito_Lab / Mbed 2 deprecated ServoTensionerV3

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
tkry
Date:
Sun May 10 19:51:15 2020 +0000
Parent:
0:cd74549e4be2
Commit message:
1st complete

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun May 10 18:10:57 2020 +0000
+++ b/main.cpp	Sun May 10 19:51:15 2020 +0000
@@ -107,6 +107,14 @@
     sw1.mode(PullUp);                           // スイッチのプルアップ
     sw2.mode(PullUp);                           // スイッチのプルアップ
 
+    // EEPROMの読み込み
+    ZeroVoltage = RomRead_address(min_address);
+    stp = RomRead_address(stp_address);             // stpの代入
+    t1 = RomRead_address(t1_address);               // t1の代入
+    t2 = RomRead_address(t2_address);               // t2の代入
+    f1 = RomRead_address(f1_address);               // f1の代入
+    f2 = RomRead_address(f2_address);               // f2の代入
+
     // 起動後の処理
     Rled = 0;                                   // 動作チェック用の赤LED点灯
     Gled = 1;                                   // 動作チェック用の緑LED点灯,外部電源駆動の場合シリアル割り込み内のgetcで処理が止まる?
@@ -124,14 +132,6 @@
     double lpf_data = 0.0;                      // LPF用の一時変数
     double pre_data = 0.0;                      // LPF用の一時変数
 
-    // EEPROMの読み込み
-    ZeroVoltage = RomRead_address(min_address);
-    stp = RomRead_address(stp_address);             // stpの代入
-    t1 = RomRead_address(t1_address);               // t1の代入
-    t2 = RomRead_address(t2_address);               // t2の代入
-    f1 = RomRead_address(f1_address);               // f1の代入
-    f2 = RomRead_address(f2_address);               // f2の代入
-
     int offset = loadcell.read();               // ロードセルの初期値取得
 
     while (true) {
@@ -141,8 +141,7 @@
         if(rewrite == 1) {
             eeprom_update();
             rewrite = 0;
-        }
-        else {
+        } else {
             if( ReadSign2 == 0 ) {                  // LEDの出力処理後に実行(LEDの出力処理中(データ送信中)に実行されない)
                 raw_data = (float)(loadcell.read()-offset)*0.003525f;      // 実測で調節した方が良さそう?(4.2987/16777216.0/128)/(0.001*8.9/2000.0)
                 lpf_data = (1.0f - lpf)*raw_data + lpf*pre_data;
@@ -151,7 +150,6 @@
                 Data = (int)lpf_data;
             }
             ReadSign1 = 0;                          // 読み込み完了で圧力計変数をfalse(読み込み後)にする
-
             //Arduino Serial plotterでのLPFの比較用
             //pc.printf("%f", raw_data);
             //pc.printf(",");
@@ -219,7 +217,6 @@
                 }
                 break;
         }
-
         // 出力完了でLED変数をfalse(読み込み後)にする
         ReadSign2 = 0;
     }
@@ -228,7 +225,7 @@
 // DACの切り替え
 void DAC_switch()
 {
-    if(stp=='1') {
+    if(stp==1) {
         DAC_linear();
     } else {
         DAC_step();
@@ -288,8 +285,8 @@
             Scnt = false;
         }
     }
-    // 電圧範囲の設定(範囲はgain:1.0で調節可能)
-    TargetVoltage = gain*(ZeroVoltage-1.692) + 1.692;                // 全範囲の電圧
+    // 電圧範囲の設定(範囲1.0で設定)
+    TargetVoltage = 1.0*(ZeroVoltage-1.692) + 1.692;                // 全範囲の電圧
     CommandVoltage = (1.539*TargetVoltage - 2.360) - BiasVoltage;   // 最大値の電圧
     Voltage = Voltage + CommandVoltage*a;
     aout3.write((Voltage+BiasVoltage)/3.3);
@@ -318,7 +315,6 @@
 
 void eeprom_update()
 {
-
     // minの変更
     if (data[0]=='z' && data[1]=='e' && data[2]=='r' && data[3]=='o') {
         pc.puts("Calibration done\n");
@@ -344,6 +340,7 @@
     // stpの変更
     if (data[0]=='s' && data[1]=='t' && data[2]=='p' && data[3]=='=') {
         float cmd = cmd2num(data);
+        stp=cmd;
         if(cmd<=0) {
             pc.puts("Error 0 < stp\n");
         } else {
@@ -351,11 +348,15 @@
             pc.puts("change stp=");
             pc.printf("%f\n",RomRead_address(stp_address));
         }
+        Voltage = 0;
+        Tcnt = 0;
+        a = 0;
     }
 
     // t1の変更
     if (data[0]=='t' && data[1]=='1' && data[2]=='=') {
         float cmd = cmd2num(data);
+        t1=cmd;
         if(cmd<=0.01f) {
             pc.puts("Error 0.01 <= t1\n");
         } else {
@@ -368,6 +369,7 @@
     // t2の変更
     if (data[0]=='t' && data[1]=='2' && data[2]=='=') {
         float cmd = cmd2num(data);
+        t2=cmd;
         if(cmd<=0.01f) {
             pc.puts("Error 0.01 <= t2\n");
         } else {
@@ -380,6 +382,7 @@
     // f1の変更
     if (data[0]=='f' && data[1]=='1' && data[2]=='=') {
         float cmd = cmd2num(data);
+        f1=cmd;
         if(cmd<=0.01f || cmd>=0.99f) {
             pc.puts("Error 0.01 <= f1 <= 0.99\n");
         } else {
@@ -392,6 +395,7 @@
     // f2の変更
     if (data[0]=='f' && data[1]=='2' && data[2]=='=') {
         float cmd = cmd2num(data);
+        f2=cmd;
         if(cmd<=0.01f || cmd>=0.99f) {
             pc.puts("Error 0.01 <= f2 <= 0.99\n");
         } else {
@@ -522,10 +526,9 @@
 char RomRead(int address)
 {
     char data[3];
-    data[0] = 0;                   // MSB address
-    data[1] = address;                   // LSB address
+    data[0] = 0;                       // MSB address
+    data[1] = address;                 // LSB address
     eeprom.write(0xA0, data, 2);
-
     char response[1];
     eeprom.read(0xA0, response, 1);
     return response[0];