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:
11:a764fe59d343
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tim4_slaveSelect.hpp	Mon Oct 20 03:01:11 2014 +0000
@@ -0,0 +1,54 @@
+//------------------------------------------------------
+//  Class for generate SPI slave select using TIM4
+//
+//  Default pin assignments: PB_6 (D10)
+//  PB_7, PB_8 (D15), and PB_9 (D14) also can be used
+//  2014/09/28, Copyright (c) 2014 MIKAMI, Naoki
+//------------------------------------------------------
+
+#ifndef TIM4_SLAVESELECT_HPP
+#define TIM4_SLAVESELECT_HPP
+
+#include "mbed.h"
+
+namespace Mikami
+{
+    class Tim4_ss
+    {
+    public:
+        Tim4_ss(uint16_t psc,       // prescaler
+                uint16_t arr = 18,  // auto-reload register
+                PinName pin = PB_6) // pin name
+                : myTim_(TIM4)
+        {
+            PwmOut css(pin);
+            myTim_->CR1 |= TIM_CR1_OPM; // one-pulse mode
+            myTim_->PSC = psc;          // prescaler
+            myTim_->ARR = arr;          // pulse width
+            if (pin == PB_6) myTim_->CCR1 = 1;
+            if (pin == PB_7) myTim_->CCR2 = 1;
+            if (pin == PB_8) myTim_->CCR3 = 1;
+            if (pin == PB_9) myTim_->CCR4 = 1;
+            if ( (pin != PB_6) && (pin != PB_7)
+               &&(pin != PB_8) && (pin != PB_9) )
+            {
+                fprintf(stderr, "\r\nIllegal pin name\r\n");
+                while (true) {}
+            }
+        }
+        // Generate slave select
+        void SlaveSelect()
+        {
+            myTim_->CNT = 1;            // Set counter 1
+            myTim_->CR1 |= TIM_CR1_CEN; // Enable TIM4
+        }
+    private:
+        TIM_TypeDef* myTim_;
+
+        // Forbid to use copy constructor
+        Tim4_ss(const Tim4_ss&);
+        // Forbid to use substitution operator
+        Tim4_ss operator=(const Tim4_ss&);
+    };
+}
+#endif  // TIM4_SLAVESELECT_HPP