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
tim4_slaveSelect.hpp@11:a764fe59d343, 2014-11-27 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Thu Nov 27 08:42:59 2014 +0000
- Revision:
- 11:a764fe59d343
- Parent:
- 0:6e0ed5adfe47
- Child:
- 12:479d18a09e87
12
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:6e0ed5adfe47 | 1 | //------------------------------------------------------ |
MikamiUitOpen | 0:6e0ed5adfe47 | 2 | // Class for generate SPI slave select using TIM4 |
MikamiUitOpen | 0:6e0ed5adfe47 | 3 | // |
MikamiUitOpen | 0:6e0ed5adfe47 | 4 | // Default pin assignments: PB_6 (D10) |
MikamiUitOpen | 0:6e0ed5adfe47 | 5 | // PB_7, PB_8 (D15), and PB_9 (D14) also can be used |
MikamiUitOpen | 11:a764fe59d343 | 6 | // 2014/11/22, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:6e0ed5adfe47 | 7 | //------------------------------------------------------ |
MikamiUitOpen | 0:6e0ed5adfe47 | 8 | |
MikamiUitOpen | 0:6e0ed5adfe47 | 9 | #ifndef TIM4_SLAVESELECT_HPP |
MikamiUitOpen | 0:6e0ed5adfe47 | 10 | #define TIM4_SLAVESELECT_HPP |
MikamiUitOpen | 0:6e0ed5adfe47 | 11 | |
MikamiUitOpen | 0:6e0ed5adfe47 | 12 | #include "mbed.h" |
MikamiUitOpen | 0:6e0ed5adfe47 | 13 | |
MikamiUitOpen | 0:6e0ed5adfe47 | 14 | namespace Mikami |
MikamiUitOpen | 0:6e0ed5adfe47 | 15 | { |
MikamiUitOpen | 0:6e0ed5adfe47 | 16 | class Tim4_ss |
MikamiUitOpen | 0:6e0ed5adfe47 | 17 | { |
MikamiUitOpen | 0:6e0ed5adfe47 | 18 | public: |
MikamiUitOpen | 0:6e0ed5adfe47 | 19 | Tim4_ss(uint16_t psc, // prescaler |
MikamiUitOpen | 0:6e0ed5adfe47 | 20 | uint16_t arr = 18, // auto-reload register |
MikamiUitOpen | 0:6e0ed5adfe47 | 21 | PinName pin = PB_6) // pin name |
MikamiUitOpen | 0:6e0ed5adfe47 | 22 | : myTim_(TIM4) |
MikamiUitOpen | 0:6e0ed5adfe47 | 23 | { |
MikamiUitOpen | 0:6e0ed5adfe47 | 24 | PwmOut css(pin); |
MikamiUitOpen | 0:6e0ed5adfe47 | 25 | myTim_->CR1 |= TIM_CR1_OPM; // one-pulse mode |
MikamiUitOpen | 0:6e0ed5adfe47 | 26 | myTim_->PSC = psc; // prescaler |
MikamiUitOpen | 0:6e0ed5adfe47 | 27 | myTim_->ARR = arr; // pulse width |
MikamiUitOpen | 0:6e0ed5adfe47 | 28 | if (pin == PB_6) myTim_->CCR1 = 1; |
MikamiUitOpen | 0:6e0ed5adfe47 | 29 | if (pin == PB_7) myTim_->CCR2 = 1; |
MikamiUitOpen | 0:6e0ed5adfe47 | 30 | if (pin == PB_8) myTim_->CCR3 = 1; |
MikamiUitOpen | 0:6e0ed5adfe47 | 31 | if (pin == PB_9) myTim_->CCR4 = 1; |
MikamiUitOpen | 0:6e0ed5adfe47 | 32 | if ( (pin != PB_6) && (pin != PB_7) |
MikamiUitOpen | 0:6e0ed5adfe47 | 33 | &&(pin != PB_8) && (pin != PB_9) ) |
MikamiUitOpen | 0:6e0ed5adfe47 | 34 | { |
MikamiUitOpen | 0:6e0ed5adfe47 | 35 | fprintf(stderr, "\r\nIllegal pin name\r\n"); |
MikamiUitOpen | 0:6e0ed5adfe47 | 36 | while (true) {} |
MikamiUitOpen | 0:6e0ed5adfe47 | 37 | } |
MikamiUitOpen | 0:6e0ed5adfe47 | 38 | } |
MikamiUitOpen | 0:6e0ed5adfe47 | 39 | // Generate slave select |
MikamiUitOpen | 0:6e0ed5adfe47 | 40 | void SlaveSelect() |
MikamiUitOpen | 0:6e0ed5adfe47 | 41 | { |
MikamiUitOpen | 11:a764fe59d343 | 42 | myTim_->CNT = 0; // Set counter 0 |
MikamiUitOpen | 0:6e0ed5adfe47 | 43 | myTim_->CR1 |= TIM_CR1_CEN; // Enable TIM4 |
MikamiUitOpen | 11:a764fe59d343 | 44 | __NOP(); |
MikamiUitOpen | 11:a764fe59d343 | 45 | __NOP(); |
MikamiUitOpen | 11:a764fe59d343 | 46 | __NOP(); |
MikamiUitOpen | 11:a764fe59d343 | 47 | __NOP(); |
MikamiUitOpen | 11:a764fe59d343 | 48 | #ifdef __STM32F411xE_H |
MikamiUitOpen | 11:a764fe59d343 | 49 | __NOP(); |
MikamiUitOpen | 11:a764fe59d343 | 50 | __NOP(); |
MikamiUitOpen | 11:a764fe59d343 | 51 | #endif // __STM32F411xE_H |
MikamiUitOpen | 0:6e0ed5adfe47 | 52 | } |
MikamiUitOpen | 0:6e0ed5adfe47 | 53 | private: |
MikamiUitOpen | 0:6e0ed5adfe47 | 54 | TIM_TypeDef* myTim_; |
MikamiUitOpen | 0:6e0ed5adfe47 | 55 | |
MikamiUitOpen | 0:6e0ed5adfe47 | 56 | // Forbid to use copy constructor |
MikamiUitOpen | 0:6e0ed5adfe47 | 57 | Tim4_ss(const Tim4_ss&); |
MikamiUitOpen | 0:6e0ed5adfe47 | 58 | // Forbid to use substitution operator |
MikamiUitOpen | 0:6e0ed5adfe47 | 59 | Tim4_ss operator=(const Tim4_ss&); |
MikamiUitOpen | 0:6e0ed5adfe47 | 60 | }; |
MikamiUitOpen | 0:6e0ed5adfe47 | 61 | } |
MikamiUitOpen | 0:6e0ed5adfe47 | 62 | #endif // TIM4_SLAVESELECT_HPP |