realtime process control with RTOS

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Files at this revision

API Documentation at this revision

Comitter:
ykuroda
Date:
Thu Oct 18 07:14:46 2018 +0000
Parent:
23:bc5ad77d56bb
Commit message:
???;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r bc5ad77d56bb -r e414c7234bcc main.cpp
--- a/main.cpp	Sun Oct 07 12:51:03 2018 +0000
+++ b/main.cpp	Thu Oct 18 07:14:46 2018 +0000
@@ -12,7 +12,6 @@
 int qbits = 6;            // 量子化シフト値
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
-//PwmOut led3(LED3);
 DigitalOut led4(LED4);
 
 // p11,12 サンプリング周期設定ピン(デフォルトは0)
@@ -56,9 +55,9 @@
         Thread::signal_wait(SIG_ST);   // シグナルを待つ
 
         // ピンの状態を読み取り,2ビット値に変換
-        int s_msb = 0, s_lsb = 0;
-        int q_msb = 0, q_lsb = 0;
-        const int RETRY = 1000;
+        int s_msb = 10, s_lsb = 10;
+        int q_msb = 10, q_lsb = 10;
+        const int RETRY = 100;  // 100回調べて9割以上1なら1,それ以下なら0とする.
         for(int i=0; i<RETRY; i++) {
             s_msb += samplingtime_MSB;
             s_lsb += samplingtime_LSB;
@@ -85,8 +84,7 @@
         qbits = 6+quantization*4;   // 量子化サイズの決定
         // (デジタル出力時の量子化サイズは 0:1024, 1:256, 2:64, 3:16 steps)
 
-
-        queue.cancel(id);
+        queue.cancel(id);   // 前回のプロセスキューをキャンセル
         printf("delta_t = %d, qbits = %d\n", delta_t, qbits);
         id = queue.call_every(delta_t, sampling_job, (void*)0);
     }