Class library for internal ADC and DAC connected by SPI. 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. Validated for ST Nucleo F401RE, F411RE. 内蔵 ADC と,SPI 接続の DAC のためのクラスライブラリ.DAC の出力信号を平滑化するためのスイッチトキャパシタフィルタ用のクロックは TIM3 を使用.ST Nucleo F401RE,F411RE で動作を確認.
Dependents: UITDSP_ADDA_Example UIT2_MovingAv_Intr UIT2_VariableFIR UIT2_VowelSynthesizer ... more
tim4_slaveSelect.hpp@5:ff25db28bc64, 2015-03-26 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Thu Mar 26 12:41:31 2015 +0000
- Revision:
- 5:ff25db28bc64
- Parent:
- 4:03c4518de836
6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 4:03c4518de836 | 1 | //------------------------------------------------------ |
MikamiUitOpen | 4:03c4518de836 | 2 | // Class for generate SPI slave select using TIM4 |
MikamiUitOpen | 4:03c4518de836 | 3 | // |
MikamiUitOpen | 4:03c4518de836 | 4 | // Default pin assignments: PB_6 (D10) |
MikamiUitOpen | 4:03c4518de836 | 5 | // PB_7, PB_8 (D15), and PB_9 (D14) also can be used |
MikamiUitOpen | 5:ff25db28bc64 | 6 | // 2015/03/26, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 4:03c4518de836 | 7 | //------------------------------------------------------ |
MikamiUitOpen | 4:03c4518de836 | 8 | |
MikamiUitOpen | 4:03c4518de836 | 9 | #ifndef TIM4_SLAVESELECT_HPP |
MikamiUitOpen | 4:03c4518de836 | 10 | #define TIM4_SLAVESELECT_HPP |
MikamiUitOpen | 4:03c4518de836 | 11 | |
MikamiUitOpen | 4:03c4518de836 | 12 | #include "mbed.h" |
MikamiUitOpen | 4:03c4518de836 | 13 | |
MikamiUitOpen | 4:03c4518de836 | 14 | namespace Mikami |
MikamiUitOpen | 4:03c4518de836 | 15 | { |
MikamiUitOpen | 4:03c4518de836 | 16 | class Tim4_ss |
MikamiUitOpen | 4:03c4518de836 | 17 | { |
MikamiUitOpen | 4:03c4518de836 | 18 | public: |
MikamiUitOpen | 4:03c4518de836 | 19 | Tim4_ss(uint16_t psc, // prescaler |
MikamiUitOpen | 5:ff25db28bc64 | 20 | uint16_t arr, // auto-reload register |
MikamiUitOpen | 4:03c4518de836 | 21 | PinName pin = PB_6) // pin name |
MikamiUitOpen | 4:03c4518de836 | 22 | : myTim_(TIM4) |
MikamiUitOpen | 4:03c4518de836 | 23 | { |
MikamiUitOpen | 4:03c4518de836 | 24 | PwmOut css(pin); |
MikamiUitOpen | 4:03c4518de836 | 25 | myTim_->CR1 |= TIM_CR1_OPM; // one-pulse mode |
MikamiUitOpen | 4:03c4518de836 | 26 | myTim_->PSC = psc; // prescaler |
MikamiUitOpen | 4:03c4518de836 | 27 | myTim_->ARR = arr; // pulse width |
MikamiUitOpen | 4:03c4518de836 | 28 | if (pin == PB_6) myTim_->CCR1 = 1; |
MikamiUitOpen | 4:03c4518de836 | 29 | if (pin == PB_7) myTim_->CCR2 = 1; |
MikamiUitOpen | 4:03c4518de836 | 30 | if (pin == PB_8) myTim_->CCR3 = 1; |
MikamiUitOpen | 4:03c4518de836 | 31 | if (pin == PB_9) myTim_->CCR4 = 1; |
MikamiUitOpen | 4:03c4518de836 | 32 | if ( (pin != PB_6) && (pin != PB_7) |
MikamiUitOpen | 4:03c4518de836 | 33 | &&(pin != PB_8) && (pin != PB_9) ) |
MikamiUitOpen | 4:03c4518de836 | 34 | { |
MikamiUitOpen | 4:03c4518de836 | 35 | fprintf(stderr, "\r\nIllegal pin name in Tim4_ss class\r\n"); |
MikamiUitOpen | 4:03c4518de836 | 36 | while (true) {} |
MikamiUitOpen | 4:03c4518de836 | 37 | } |
MikamiUitOpen | 4:03c4518de836 | 38 | } |
MikamiUitOpen | 4:03c4518de836 | 39 | // Generate slave select |
MikamiUitOpen | 4:03c4518de836 | 40 | void SlaveSelect() |
MikamiUitOpen | 4:03c4518de836 | 41 | { |
MikamiUitOpen | 4:03c4518de836 | 42 | myTim_->CNT = 0; // Set counter 0 |
MikamiUitOpen | 4:03c4518de836 | 43 | myTim_->CR1 |= TIM_CR1_CEN; // Enable TIM4 |
MikamiUitOpen | 4:03c4518de836 | 44 | __NOP(); |
MikamiUitOpen | 4:03c4518de836 | 45 | __NOP(); |
MikamiUitOpen | 4:03c4518de836 | 46 | __NOP(); |
MikamiUitOpen | 4:03c4518de836 | 47 | __NOP(); |
MikamiUitOpen | 4:03c4518de836 | 48 | #ifdef __STM32F411xE_H |
MikamiUitOpen | 4:03c4518de836 | 49 | __NOP(); |
MikamiUitOpen | 4:03c4518de836 | 50 | __NOP(); |
MikamiUitOpen | 4:03c4518de836 | 51 | #endif // __STM32F411xE_H |
MikamiUitOpen | 4:03c4518de836 | 52 | } |
MikamiUitOpen | 4:03c4518de836 | 53 | private: |
MikamiUitOpen | 4:03c4518de836 | 54 | TIM_TypeDef* myTim_; |
MikamiUitOpen | 4:03c4518de836 | 55 | |
MikamiUitOpen | 4:03c4518de836 | 56 | // Forbid to use copy constructor |
MikamiUitOpen | 4:03c4518de836 | 57 | Tim4_ss(const Tim4_ss&); |
MikamiUitOpen | 4:03c4518de836 | 58 | // Forbid to use substitution operator |
MikamiUitOpen | 4:03c4518de836 | 59 | Tim4_ss operator=(const Tim4_ss&); |
MikamiUitOpen | 4:03c4518de836 | 60 | }; |
MikamiUitOpen | 4:03c4518de836 | 61 | } |
MikamiUitOpen | 4:03c4518de836 | 62 | #endif // TIM4_SLAVESELECT_HPP |