Cutoff frequency variable LPF by IIR 6th-order Butterworth filter for ST Nucleo F401RE.

Dependencies:   UIT_IIR_Filter UIT_ACM1602NI UITDSP_ADDA mbed UIT_AQM1602

Revision:
6:116f72cda0f4
Parent:
5:b291c4653eb9
Child:
7:34eced3597bb
--- a/main.cpp	Sun Dec 07 05:45:07 2014 +0000
+++ b/main.cpp	Sat Jul 25 06:41:36 2015 +0000
@@ -1,27 +1,34 @@
 //--------------------------------------------------------------
-// Cutoff frequency variable LPF by IIR 6th-order filter
+// Cutoff frequency variable LPF by IIR 8th-order filter
 //      A0: Signal to be filtered
 //      A2: Value which controls cutoff frequency
 //
-// 2014/11/15, Copyright (c) 2014 MIKAMI, Naoki
+// 2015/07/25, Copyright (c) 2015 MIKAMI, Naoki
 //--------------------------------------------------------------
 
-#include "mbed.h"
-
 #include "ADC_Interrupt.hpp"    // for ADC using interrupt
-#include "DAC_MCP4922.hpp"      // for DAC MCP4922
-#include "ACM1602NI.hpp"        // for LCD display
+#include "DAC_MCP4921.hpp"      // for DAC MCP4921, MCP4922
+using namespace Mikami;
 
 #include "BilinearDesignLH.hpp" // for design of IIR filter
 #include "IIR_Cascade.hpp"      // for IIR filter of cascade structure
 
-using namespace Mikami;
+// ACM1602Ni を使う場合は次の define 文をコメントにすること
+#define AQM1602
+
+#ifdef AQM1602
+#include "AQM1602.hpp"
+Aqm1602 Lcd_;
+#else
+#include "ACM1602NI.hpp"
+Acm1602Ni Lcd_;
+#endif
 
 const int FS_ = 24000;          // Sampling frequency: 24 kHz
 ADC_Intr myAdc_(A0, FS_, A1, A2);
-DAC_MCP4922 myDac_;
+DAC_MCP4921 myDac_;
 
-const int ORDER_ = 6;
+const int ORDER_ = 8;
 IirCascade<ORDER_/2> iirLpf_;   // IIR filter object
 
 DigitalIn sw1_(D2, PullDown);   // 0: disable filter
@@ -53,11 +60,9 @@
 
 int main()
 {
-    const int ORDER = 6;
     myDac_.ScfClockTim3(1000000);   // cutoff frequency: 10 kHz
 
-    BilinearDesign lpfDsgn(ORDER, FS_, BilinearDesign::LPF);
-    Acm1602Ni lcd;  // objetc for display using LCD
+    BilinearDesign lpfDsgn(ORDER_, FS_, BilinearDesign::LPF);
 
     myAdc_.SetIntrVec(AdcIsr);  // Assign ISR for ADC interrupt
 
@@ -70,9 +75,9 @@
         if (sw1_ == 0)
         {
             printf("Through\r\n");
-            lcd.WriteStringXY("Through         ", 0, 0);
+            Lcd_.WriteStringXY("Through         ", 0, 0);
             wait(0.2f);
-            lcd.ClearLine(0);
+            Lcd_.ClearLine(0);
             fc1 = 0;
         }
         else
@@ -82,17 +87,17 @@
                 printf("fc = %4d\r\n", int(fc+0.5f));
                 char str[18];
                 sprintf(str, "fc = %4d Hz", int(fc+0.5f));
-                lcd.WriteStringXY(str, 0, 0);
+                Lcd_.WriteStringXY(str, 0, 0);
                 fc1 = fc;
 
                 // Design new coefficients based on new fc
-                BilinearDesign::Coefs coefsLpf[ORDER/2];
+                BilinearDesign::Coefs coefsLpf[ORDER_/2];
                 float g0;
                 lpfDsgn.Execute(fc, coefsLpf, g0);
 
                 // Update new coefficients
-                Biquad::Coefs coefsIir[ORDER/2];
-                for (int n=0; n<ORDER/2; n++)
+                Biquad::Coefs coefsIir[ORDER_/2];
+                for (int n=0; n<ORDER_/2; n++)
                 {
                     coefsIir[n].a1 = coefsLpf[n].a1;
                     coefsIir[n].a2 = coefsLpf[n].a2;