![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CQエレクトロニクス・セミナ「実習・マイコンを動かしながら学ぶディジタル・フィルタ」で使うプログラム.1次IIRフィルタの係数をターミナルから変更できる. http://seminar.cqpub.co.jp/ccm/ES18-0020
Dependencies: mbed Array_Matrix BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG
MyFiles/LcdPanelFrq.hpp@0:47718d3154d9, 2017-10-09 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Oct 09 02:36:11 2017 +0000
- Revision:
- 0:47718d3154d9
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:47718d3154d9 | 1 | //----------------------------------------------------------- |
MikamiUitOpen | 0:47718d3154d9 | 2 | // ディジタルフィルタ実験のためのプラットフォームの |
MikamiUitOpen | 0:47718d3154d9 | 3 | // LCD パネル表示と入力信号の周波数設定で使う |
MikamiUitOpen | 0:47718d3154d9 | 4 | // |
MikamiUitOpen | 0:47718d3154d9 | 5 | // 2017/08/21, Copyright (c) 2017 MIKAMI, Naoki |
MikamiUitOpen | 0:47718d3154d9 | 6 | //----------------------------------------------------------- |
MikamiUitOpen | 0:47718d3154d9 | 7 | |
MikamiUitOpen | 0:47718d3154d9 | 8 | #ifndef PANEL_MANIPULATOR_HPP |
MikamiUitOpen | 0:47718d3154d9 | 9 | #define PANEL_MANIPULATOR_HPP |
MikamiUitOpen | 0:47718d3154d9 | 10 | |
MikamiUitOpen | 0:47718d3154d9 | 11 | #include "F746_GUI.hpp" |
MikamiUitOpen | 0:47718d3154d9 | 12 | #include "NumericUpDown.hpp" |
MikamiUitOpen | 0:47718d3154d9 | 13 | #include "Zoom.hpp" |
MikamiUitOpen | 0:47718d3154d9 | 14 | #include "WaveformDisplay.hpp" |
MikamiUitOpen | 0:47718d3154d9 | 15 | #include "Trigger.hpp" |
MikamiUitOpen | 0:47718d3154d9 | 16 | |
MikamiUitOpen | 0:47718d3154d9 | 17 | namespace Mikami |
MikamiUitOpen | 0:47718d3154d9 | 18 | { |
MikamiUitOpen | 0:47718d3154d9 | 19 | class LcdPanel |
MikamiUitOpen | 0:47718d3154d9 | 20 | { |
MikamiUitOpen | 0:47718d3154d9 | 21 | public: |
MikamiUitOpen | 0:47718d3154d9 | 22 | // ts : 標本化間隔(単位:μs) |
MikamiUitOpen | 0:47718d3154d9 | 23 | LcdPanel(float ts) |
MikamiUitOpen | 0:47718d3154d9 | 24 | : TS_(ts), lcd_(GuiBase::GetLcd()), |
MikamiUitOpen | 0:47718d3154d9 | 25 | xnD_(N_DISP_BUF_), ynD_(N_DISP_BUF_), frq_(1000), |
MikamiUitOpen | 0:47718d3154d9 | 26 | dPhi_(PI2_*frq_*TS_), phi_(0), factor_(1) |
MikamiUitOpen | 0:47718d3154d9 | 27 | { |
MikamiUitOpen | 0:47718d3154d9 | 28 | Label title(240, 10, "Digital Filter LAB", Label::CENTER, Font16); |
MikamiUitOpen | 0:47718d3154d9 | 29 | |
MikamiUitOpen | 0:47718d3154d9 | 30 | const uint16_t Y0 = 170; |
MikamiUitOpen | 0:47718d3154d9 | 31 | // 凡例 |
MikamiUitOpen | 0:47718d3154d9 | 32 | lcd_.SetTextColor(LINE_COLOR1_); |
MikamiUitOpen | 0:47718d3154d9 | 33 | lcd_.DrawHLine(360, Y0+6, 50); |
MikamiUitOpen | 0:47718d3154d9 | 34 | Label label1(420, Y0, "Input"); |
MikamiUitOpen | 0:47718d3154d9 | 35 | lcd_.SetTextColor(LINE_COLOR2_); |
MikamiUitOpen | 0:47718d3154d9 | 36 | lcd_.DrawHLine(360, Y0+26, 50); |
MikamiUitOpen | 0:47718d3154d9 | 37 | Label label2(420, Y0+20, "Output"); |
MikamiUitOpen | 0:47718d3154d9 | 38 | |
MikamiUitOpen | 0:47718d3154d9 | 39 | waveDisp_ = new WaveformDisplay(lcd_, 30, 90, xnD_, ynD_, 400, 8, |
MikamiUitOpen | 0:47718d3154d9 | 40 | AXIS_COLOR_, |
MikamiUitOpen | 0:47718d3154d9 | 41 | LINE_COLOR1_, LINE_COLOR2_, |
MikamiUitOpen | 0:47718d3154d9 | 42 | BACK_COLOR_); |
MikamiUitOpen | 0:47718d3154d9 | 43 | |
MikamiUitOpen | 0:47718d3154d9 | 44 | // GUI 設定 |
MikamiUitOpen | 0:47718d3154d9 | 45 | ud_ = new NumericUpDown(4, 0, 271, frq_, 9999, 100, "Hz"); |
MikamiUitOpen | 0:47718d3154d9 | 46 | bar_ = new SeekBar(230, 250, 230, |
MikamiUitOpen | 0:47718d3154d9 | 47 | log10f(MIN_FRQ_), log10f(MAX_FRQ_), log10f(1000), |
MikamiUitOpen | 0:47718d3154d9 | 48 | "0.1", "1.0", "10.0"); |
MikamiUitOpen | 0:47718d3154d9 | 49 | // 時間軸の拡大率は 8 倍まで |
MikamiUitOpen | 0:47718d3154d9 | 50 | zmButton_ = new ZoomButton(240, Y0, 40, 30, 8); |
MikamiUitOpen | 0:47718d3154d9 | 51 | } |
MikamiUitOpen | 0:47718d3154d9 | 52 | |
MikamiUitOpen | 0:47718d3154d9 | 53 | // 正弦波の発生で使う値の更新し,取得する |
MikamiUitOpen | 0:47718d3154d9 | 54 | float GetPhi() |
MikamiUitOpen | 0:47718d3154d9 | 55 | { |
MikamiUitOpen | 0:47718d3154d9 | 56 | if ((phi_ += dPhi_) > PI2_) phi_ -= PI2_; |
MikamiUitOpen | 0:47718d3154d9 | 57 | return phi_; |
MikamiUitOpen | 0:47718d3154d9 | 58 | } |
MikamiUitOpen | 0:47718d3154d9 | 59 | |
MikamiUitOpen | 0:47718d3154d9 | 60 | // 周波数設定の更新とズームイン/アウト・ボタンの処理 |
MikamiUitOpen | 0:47718d3154d9 | 61 | void Update() |
MikamiUitOpen | 0:47718d3154d9 | 62 | { |
MikamiUitOpen | 0:47718d3154d9 | 63 | if (bar_->Slide()) // SeekBar をスライドした場合の処理 |
MikamiUitOpen | 0:47718d3154d9 | 64 | { |
MikamiUitOpen | 0:47718d3154d9 | 65 | frq_ = (int)(powf(10, bar_->GetValue())+0.5f); |
MikamiUitOpen | 0:47718d3154d9 | 66 | if (frq_ >= MAX_FRQ_) frq_ = MAX_FRQ_ - 1; |
MikamiUitOpen | 0:47718d3154d9 | 67 | ud_->Set(frq_); // SeekBar の数値を NumericUpDown に表示する |
MikamiUitOpen | 0:47718d3154d9 | 68 | dPhi_ = PI2_*frq_*TS_; |
MikamiUitOpen | 0:47718d3154d9 | 69 | } |
MikamiUitOpen | 0:47718d3154d9 | 70 | |
MikamiUitOpen | 0:47718d3154d9 | 71 | if (ud_->Touched()) // NumericUpDown をタッチした場合の処理 |
MikamiUitOpen | 0:47718d3154d9 | 72 | { |
MikamiUitOpen | 0:47718d3154d9 | 73 | frq_ = ud_->Get(); |
MikamiUitOpen | 0:47718d3154d9 | 74 | bar_->Draw(log10f(frq_)); // NumericUpDown の数値で SeekBar のツマミの位置を設定 |
MikamiUitOpen | 0:47718d3154d9 | 75 | dPhi_ = PI2_*frq_*TS_; |
MikamiUitOpen | 0:47718d3154d9 | 76 | } |
MikamiUitOpen | 0:47718d3154d9 | 77 | |
MikamiUitOpen | 0:47718d3154d9 | 78 | zmButton_->Touched(factor_); // ズームインとズームアウト |
MikamiUitOpen | 0:47718d3154d9 | 79 | } |
MikamiUitOpen | 0:47718d3154d9 | 80 | |
MikamiUitOpen | 0:47718d3154d9 | 81 | // 入出力信号のデータを表示用バッファへ格納 |
MikamiUitOpen | 0:47718d3154d9 | 82 | void Store(int16_t xn, int16_t yn, int n) |
MikamiUitOpen | 0:47718d3154d9 | 83 | { |
MikamiUitOpen | 0:47718d3154d9 | 84 | if (n >= N_DISP_BUF_) return; |
MikamiUitOpen | 0:47718d3154d9 | 85 | |
MikamiUitOpen | 0:47718d3154d9 | 86 | xnD_[n] = xn; |
MikamiUitOpen | 0:47718d3154d9 | 87 | ynD_[n] = yn; |
MikamiUitOpen | 0:47718d3154d9 | 88 | } |
MikamiUitOpen | 0:47718d3154d9 | 89 | |
MikamiUitOpen | 0:47718d3154d9 | 90 | // 入出力信号の波形の表示 |
MikamiUitOpen | 0:47718d3154d9 | 91 | void Display() { waveDisp_->Execute(Trigger(xnD_, 1), factor_); } |
MikamiUitOpen | 0:47718d3154d9 | 92 | |
MikamiUitOpen | 0:47718d3154d9 | 93 | private: |
MikamiUitOpen | 0:47718d3154d9 | 94 | static const float PI_ = 3.1415926536f; |
MikamiUitOpen | 0:47718d3154d9 | 95 | static const float PI2_ = 2.0f*PI_; |
MikamiUitOpen | 0:47718d3154d9 | 96 | static const int MIN_FRQ_ = 100; // 発生する周波数の最小値 |
MikamiUitOpen | 0:47718d3154d9 | 97 | static const int MAX_FRQ_ = 10000; // 発生する周波数の最大値 |
MikamiUitOpen | 0:47718d3154d9 | 98 | static const uint32_t BACK_COLOR_ = GuiBase::ENUM_BACK; |
MikamiUitOpen | 0:47718d3154d9 | 99 | static const uint32_t AXIS_COLOR_ = 0xFFCCFFFF; |
MikamiUitOpen | 0:47718d3154d9 | 100 | static const uint32_t LINE_COLOR1_ = LCD_COLOR_CYAN; |
MikamiUitOpen | 0:47718d3154d9 | 101 | static const uint32_t LINE_COLOR2_ = LCD_COLOR_MAGENTA; |
MikamiUitOpen | 0:47718d3154d9 | 102 | static const int N_DISP_BUF_ = 1000; // 波形表示用のバッファのサイズ |
MikamiUitOpen | 0:47718d3154d9 | 103 | |
MikamiUitOpen | 0:47718d3154d9 | 104 | const float TS_; // 標本化間隔 |
MikamiUitOpen | 0:47718d3154d9 | 105 | |
MikamiUitOpen | 0:47718d3154d9 | 106 | LCD_DISCO_F746NG &lcd_; |
MikamiUitOpen | 0:47718d3154d9 | 107 | WaveformDisplay *waveDisp_; |
MikamiUitOpen | 0:47718d3154d9 | 108 | NumericUpDown *ud_; // 入力信号の周波数設定用(1 Hz 単位での設定用) |
MikamiUitOpen | 0:47718d3154d9 | 109 | SeekBar *bar_; // 入力信号の周波数設定用(概略の設定用) |
MikamiUitOpen | 0:47718d3154d9 | 110 | ZoomButton *zmButton_; // 波形表示:ズームイン/アウト用 |
MikamiUitOpen | 0:47718d3154d9 | 111 | |
MikamiUitOpen | 0:47718d3154d9 | 112 | Array<int16_t> xnD_; // 波形表示で使うバッファ(入力信号用) |
MikamiUitOpen | 0:47718d3154d9 | 113 | Array<int16_t> ynD_; // 波形表示で使うバッファ(出力信号用) |
MikamiUitOpen | 0:47718d3154d9 | 114 | int frq_; // 現在の入力信号の周波数,初期値は 1 kHz |
MikamiUitOpen | 0:47718d3154d9 | 115 | float dPhi_, phi_; // 入力信号の生成で使う変数 |
MikamiUitOpen | 0:47718d3154d9 | 116 | int factor_; // 波形表示の際の標本化間隔に対応するピクセル数 |
MikamiUitOpen | 0:47718d3154d9 | 117 | }; |
MikamiUitOpen | 0:47718d3154d9 | 118 | } |
MikamiUitOpen | 0:47718d3154d9 | 119 | #endif // PANEL_MANIPULATOR_HPP |