Example programs of AD and DA using classes in UITDSP_ADDA for ST Nucleo F401RE. UITDSP_ADDA に含まれるクラスを使った AD および DA のためのプログラムの例.ST Nucleo F401 用.

Dependencies:   UITDSP_ADDA mbed

Revision:
2:7706df2df05a
Parent:
1:a5792f051953
Child:
3:d7128a3520ac
--- a/main.cpp	Mon Feb 23 13:39:29 2015 +0000
+++ b/main.cpp	Tue Mar 17 00:00:16 2015 +0000
@@ -1,41 +1,39 @@
 //------------------------------------------------------------------------------
-//  "UITDSP_ADDA" に含まれるライブラリの使用例
+//  "UITDSP_ADDA2" に含まれるライブラリの使用例
 //
 //      アナログ入力
 //          A0: ライン
 //          A1: マイク
 //          A2: 可変抵抗器
 //
-//  2015/02/23, Copyright (c) 2015 MIKAMI, Naoki
+//  2015/03/14, Copyright (c) 2015 MIKAMI, Naoki
 //------------------------------------------------------------------------------
 
-#include "InternalADC.hpp"      // かならず必要 
+#include "ADC_BuiltIn.hpp"      // かならず必要
 
 // 以下の "#define" 文を一つだけ有効にし,他はコメントとすること
-#define POLLING_1_CHANNEL
+//#define POLLING_1_CHANNEL
 //#define POLLING_SW_CHANNEL
 //#define INTERRUPT_1_CHANNEL
 //#define INTERRUPT_2_CHANNELS
-//#define POLLING_DA_2_CHANNELS
+#define POLLING_DA_2_CHANNELS
 
-using namespace Mikami;         // かならず必要 
+using namespace Mikami;         // かならず必要
 
 //------------------------------------------------------------------------------
 // 基本的な使い方:ポーリング,1チャンネル
 
 #ifdef POLLING_1_CHANNEL
-#include "DAC_MCP4921.hpp"
+#include "DAC_MCP4922.hpp"      // DAC MCP4922 用
 
-const int TS_ = 100;    // 標本化間隔: 0.1 [ms]
-InternalADC adc_(A0);   // A0 からの入力を使うように設定
-DAC_MCP4921 myDac_;     // DAC を使うための設定
+const int FS_ = 10000;          // 標本化周波数: 10 kHz
+ADC_BuiltIn adc_(A0, FS_);      // A0 からの入力を使うように設定
+DAC_MCP4922 myDac_;             // DAC を使うための設定
 
 int main()
 {
     printf("\r\nPOLLING_1_CHANNEL\r\n");
-    
-    adc_.SetSamplingPeriod(TS_);    // 標本化間隔の設定
-    myDac_.ScfClockTim3(420000);    // 出力の LPF の遮断周波数を 4.2 kHz に設定
+    myDac_.ScfClockTim3(420000);    //  出力の LPF の遮断周波数を 4.2 kHz に設定
 
     while (true)
     {
@@ -55,19 +53,17 @@
 // ポーリングで入力の切り替えを行う場合
 
 #ifdef POLLING_SW_CHANNEL
-#include "DAC_MCP4921.hpp"
+#include "DAC_MCP4922.hpp"
 
-const int TS_ = 100;    // Sampling period: 0.1 ms
-InternalADC adc_(A0, A1);   // for AD
-DAC_MCP4921 myDac_;         // for DA
+const int FS_ = 10000;          // Sampling frequency: 10 kHz
+ADC_BuiltIn adc_(A0, FS_, A1);  // for AD using channel A0 and A1
+DAC_MCP4921 myDac_;             // for DA
 
 DigitalIn sw_(D2, PullDown);
 
 int main()
 {
     printf("\r\nPOLLING_SW_CHANNEL\r\n");
-
-    adc_.SetSamplingPeriod(TS_);
     myDac_.ScfClockTim3(420000);    // cutoff frequency: 4.2 kHz
 
     int swBefore = 0;
@@ -98,9 +94,9 @@
 #include "ADC_Interrupt.hpp"    // for ADC not using ADC interrupt
 #include "DAC_MCP4922.hpp"
 
-const int TS_ = 100;    // Sampling period: 0.1 ms
-ADC_Intr adc_(A0);  // for AD
-DAC_MCP4922 myDac_; // for DA
+const int FS_ = 10000;  // Sampling frequency: 10 kHz
+ADC_Intr adc_(A0, FS_); // for AD
+DAC_MCP4922 myDac_;     // for DA
 
 // Interrupt service routine for ADC
 void AdcIsr()
@@ -113,7 +109,6 @@
 {
     printf("\r\nINTERRUPT_1_CHANNEL\r\n");
 
-    adc_.SetSamplingPeriod(TS_);
     myDac_.ScfClockTim3(420000);    // cutoff frequency: 4.2 kHz
 
     adc_.SetIntrVec(AdcIsr);        // Assign ISR for ADC interrupt
@@ -133,8 +128,8 @@
 //      A0: Line input
 //      A1: Not used
 //      A2: VR (controls volume of output signal)
-const int TS_ = 100;    // Sampling period: 0.1 ms
-ADC_Intr adc_(A0, A1, A2);   // for AD
+const int FS_ = 10000;  // Sampling frequency: 10 kHz
+ADC_Intr adc_(A0, FS_, A1, A2);   // for AD
 DAC_MCP4922 myDac_(DAC_MCP4922::DAC_A, D11, D13, D10, D12);     // for DA
 
 uint16_t a2_ = 0;
@@ -147,7 +142,7 @@
     float xn = adc_.Read();     // Read from A0
 
     adc_.Select3rdChannel();    // Enable A2   
-    adc_.SoftStartDisableIRQ(); // ADC start for A2 input
+    adc_.SoftStart();           // ADC start for A2 input
     
     float yn = vol_*xn; // Volume control by VR
     myDac_.Write(yn);   // to DAC
@@ -162,8 +157,6 @@
 int main()
 {
     printf("\r\nINTERRUPT_2_CHANNELS\r\n");
-
-    adc_.SetSamplingPeriod(TS_);
     myDac_.ScfClockTim3(420000);    // cutoff frequency: 4.2 kHz
 
     adc_.SetIntrVec(AdcIsr);        // Assign ISR for ADC interrupt
@@ -187,13 +180,13 @@
 #ifdef POLLING_DA_2_CHANNELS
 #include "DAC_MCP4922Dual.hpp"
 
-InternalADC adc_(A0);   // for AD
-DAC_MCP4922Dual myDac_; // for DA
+const int FS_ = 10000;      // Sampling frequency: 10 kHz
+ADC_BuiltIn adc_(A0, FS_);  // for AD
+DAC_MCP4922Dual myDac_;     // for DA of 2 channels
 
 int main()
 {
     printf("\r\nPOLLING_DA_2_CHANNELS\r\n");
-    adc_.SetSamplingPeriod(20); // 20 micro seconds
 
     while (true)
     {
@@ -201,10 +194,8 @@
         //-----------------------------------------------
         float yn = xn;
         //-----------------------------------------------
-        myDac_.Write(yn, yn);       // Write to DAC
+        myDac_.Write(yn, -yn);       // Write to DAC
     }
 }
 #endif  // POLLING_DA_2_CHANNEL
 //------------------------------------------------------------------------------
-
-