Interface 2015年4月号 第1部 第5章および第6章のプログラム

Dependencies:   USBDevice mbed

Information

FilterTest - Interface 2015年4月号 第1部 第5章 第6章 のソフトウェア

Program for Section 5 and 6 in April 2015 issue of Interface
(Japanese electronics magazine)

概要

このプログラムは、

  • ハイパスフィルタ、ローパスフィルタ、ノッチフィルタ

を行うFilterTestクラスと、波形をUSBシリアル通信でホストへ送信するmain関数で構成されています。

FilterTest.h, FilterTest.cpp

  • A-Dサンプリング - 1 kSPS
  • ハイパスフィルタ(遮断周波数 0.5 Hz、1次バターワース)
  • ローパスフィルタ(遮断周波数 30 Hz、2次バターワース)
  • ノッチフィルタ(中心周波数 50 Hz、2次)

main.cpp

  • データ送信レート - 1 kSPS
  • FilterTestクラスのインスタンスを生成
  • 処理開始メソッドを実行
  • メインループ - ポーリングにより、サンプリング、フィルタ処理完了フラグがセットされたら、
    USBシリアル通信経由で、ホストへ送信する

シリアル通信フォーマット

 (※)誌面ではパケットサイズ 64 byteとなっていますが、
    64 byteでは、PCのUSBドライバが 4096 byteまで保持し、波形が滑らかに描画できないため、
    Ver.1.0.2で、32 byteに変更しています。

  • 34byte固定長パケット方式
  • 波形データパケット1種類
波形データパケット
0x00パケットヘッダ(固定値0xAA)
0x01データ種別ID(0x01: 波形データ)
0x02パケット番号(0 - 99繰り返し)
0x03ペイロードサイズ(固定値30)
0x04 - 0x21波形データ(short, big endian)

Description

This contains FilterTest class and main function.

FilterTest class:

  • High pass filter, Low pass, Notch filter

Main function:

  • Send waveform to host via USB serial class.

FilterTest.h, FilterTest.cpp

  • A-D sampling - 1 kSPS
  • High pass filter - Cut off frequency 0.5 Hz, first order butterworth
  • Low pass filter - Cut off frequency 30 Hz, second order butterworth
  • Notch filter - Center frequency 50 Hz, second order

main.cpp

  • Data sending rate - 1 kSPS
  • Executing start procedure method
  • Main loop - sending waveform data via USB serial interface when detecting ready flag.

Packet format for USB serial interface

  • Packet size: 34 bytes(fixed)
  • One type of packet waveform packet
Waveform packet
0x00Packet header (0xAA (fixed))
0x01Data type ID (0x01: Waveform ID)
0x02Packet number (0 - 99)
0x03Payload size (30 (fixed))
0x04 - 0x21Waveform data (short, big endian)
Revision:
1:4172c4324c2d
Parent:
0:7a4d80e7ea81
--- a/main.cpp	Sat Feb 21 19:28:57 2015 +0000
+++ b/main.cpp	Sat Feb 21 19:45:49 2015 +0000
@@ -2,7 +2,7 @@
  *  @file       Main.cpp
  *  @brief      Send 1ch waveform data to PC via USB serial
  *  @date       2015.02.22
- *  @version    1.0.1
+ *  @version    1.0.2
  */
 #include "mbed.h"
 #include "USBSerial.h"
@@ -22,8 +22,8 @@
 
 #define PACKET_HEADER (0xAA)
 #define WAVEFORM_ID   (0x01)
-#define PACKET_SIZE   (64)
-#define DATA_NUM      (60)
+#define PACKET_SIZE   (34)
+#define DATA_NUM      (30)
 #define BUF_NUM       (2)
 #define CNTR_SIZE     (100)
 /*  [ Packet format ]                                           */
@@ -31,10 +31,10 @@
 /*  0x00 | Header byte    | Fixed value (PACKET_HEADER:0xAA)    */
 /*  0x01 | Data type      | ID value    (0x01:Waveform)         */
 /*  0x02 | Packet counter | Count value (0to99 < CNTR_SIZE:100) */
-/*  0x03 | Payload size   | Fixed value (DATA_NUM:60)           */
+/*  0x03 | Payload size   | Fixed value (DATA_NUM:30)           */
 /*  0x04 | Data0 (MSBside)| Short type  (signed, big endian)    */
 /*  ...  | ...            |                                     */
-/*  0x3F | Data29(LSBside)|                                     */
+/*  0x21 | Data29(LSBside)|                                     */
 /*        ----------------                                      */
 
 Ticker      sampling;           /* Interval timer for A/D sampling */