Class library for internal ADC and DAC connected by SPI. ADC is triggered by TIM2. This library support clock generator using TIM3 for switched-capacitor filter to smooth output signal of DAC. This library includes derivative class to support interrupt occured in end of AD conversion. Slave select of SPI for DAC is generated using TIM4. Validated for ST Nucleo F401RE, F411RE. New version. 内蔵 ADC と,SPI 接続の DAC のためのクラスライブラリ.ADC の変換開始トリガは TIM2 で発生.DAC の出力信号を平滑化するためのスイッチトキャパシタフィルタ用のクロックは TIM3 を使用.DAC の SPI 用スレーブ選択信号は TIM4 で発生.ST Nucleo F401RE,F411RE で動作を確認.新バージョン

Dependents:   UIT2_MovingAverage UIT2_AllpassReverb UIT2_CombReverb UIT2_FIR_LPF_Symmetry ... more

Revision:
0:6e0ed5adfe47
Child:
5:651809e96a2d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADC_Base.hpp	Mon Oct 20 03:01:11 2014 +0000
@@ -0,0 +1,83 @@
+//------------------------------------------------------
+// Class for ADC using TIM2 trigger -- Header
+//
+// 2014/10/04, Copyright (c) 2014 MIKAMI, Naoki
+//------------------------------------------------------
+
+#ifndef ADC_BASE_HPP
+#define ADC_BASE_HPP
+
+#include "mbed.h"
+
+namespace Mikami
+{
+    class ADC_Base
+    {
+    private:
+        // Using mbed library for ADC
+        AnalogIn adc_;
+        // Default constructor is not defined in AnalogIn class
+        AnalogIn* adc2_;
+        AnalogIn* adc3_;
+        
+        // Pins for Analog input
+        const PinName PIN1_, PIN2_, PIN3_;
+
+        // Set timer to generate sampling pulse for ADC
+        void SetTim2(int frequency);
+        
+        // for inhibition of copy constructor
+        ADC_Base(const ADC_Base&);
+        // for inhibition of substitute operator
+        ADC_Base& operator=(const ADC_Base&);
+
+    protected:
+        // for normalize   
+        static const float AMP_ = 1.0f/2048.0f;
+
+        ADC_TypeDef* const myAdc_;     
+        
+        // Wait until completion of AD conversion
+        void WaitDone()
+        { while((myAdc_->SR & ADC_SR_EOC) == RESET); }
+
+    public:
+        // Constructor
+        //      pin1:       Pin Name for input as A0, A1, etc.
+        //      frequency:  Sampling frequency
+        //      pin2:       If use 2nd channel set this parameter
+        //      pin3:       If use 3rd channel set this parameter
+        ADC_Base(PinName pin1, int frequency,
+                 PinName pin2 = NC, PinName pin3 = NC);  
+        
+        // Read ADC with waiting, range: [0, 0x0FFF]
+        virtual uint16_t Read_u16()
+        {
+            WaitDone();
+            return myAdc_->DR;   
+        }
+
+        // Read ADC with waiting, range: [-1.0f, 1.0f]
+        virtual float Read()
+        {
+            WaitDone();
+            return AMP_*((int16_t)myAdc_->DR - 2048);
+        }
+
+        // Select channel
+        void Select1stChannel() { myAdc_->SQR3 = PIN1_; }
+        void Select2ndChannel() { myAdc_->SQR3 = PIN2_; }
+        void Select3rdChannel() { myAdc_->SQR3 = PIN3_; }
+        
+        // Software start
+        virtual void SoftStart()
+        { myAdc_->CR2 |= ADC_CR2_SWSTART; }
+        
+        uint32_t ReadSQR3() { return myAdc_->SQR3; }
+    };
+}
+#endif  // ADC_BASE_HPP
+
+
+
+