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
ADC_Base.cpp
- Committer:
- MikamiUitOpen
- Date:
- 2014-11-10
- Revision:
- 6:6989472e84c4
- Parent:
- 4:6e228f373c6f
- Child:
- 8:f933fcd30408
File content as of revision 6:6989472e84c4:
//------------------------------------------------------ // Class for ADC using TIM2 trigger // To get bit definition for register in // peripheral, see "stm32f401xe.h" // // 2014/11/10, Copyright (c) 2014 MIKAMI, Naoki //------------------------------------------------------ #include "ADC_Base.hpp" namespace Mikami { ADC_Base::ADC_Base(PinName pin1, int frequency, PinName pin2, PinName pin3) : adc_(pin1), PIN1_(pin1), PIN2_(pin2), PIN3_(pin3), myAdc_(ADC1) { myAdc_->CR2 = ADC_EXTERNALTRIGCONVEDGE_RISING // External Trigger on the rising edge | ADC_EXTERNALTRIGCONV_T2_TRGO // Use Timer2 TRGO event | ADC_CR2_ADON; // Enable ADC if (pin2 != NC) adc2_ = new AnalogIn(pin2); if (pin3 != NC) adc3_ = new AnalogIn(pin3); SetTim2(frequency); Select1stChannel(); } void ADC_Base::SetTim2(int frequency) { __TIM2_CLK_ENABLE(); // Supply clock, See "stm32f4xx_hal_rcc.h" SystemInit(); // Set core clock (for F411RE) TIM_TypeDef* myTim = TIM2; myTim->CR2 = TIM_CR2_MMS_1; // Update event: as trigger out myTim->ARR = SystemCoreClock/frequency - 1; // Auto-reload myTim->PSC = 0; // Prescaler myTim->CR1 = TIM_CR1_CEN; // Enable TIM2 } }