Library for build-in ADC and DAC in STM32F446 mounted on Nucleo F446RE. Nucleo F446RE に搭載されている STM32F446 の内蔵 ADC, DAC 用のライブラリ.
Dependents: Demo_F446_AD_DA F446_MySoundMachine F446_ADF_Nlms F446_Spectrogram
F446_ADC.hpp
- Committer:
- MikamiUitOpen
- Date:
- 2016-11-12
- Revision:
- 1:6b9f2af6613d
- Parent:
- 0:c945b4fe9a48
- Child:
- 2:29f9831ce719
File content as of revision 1:6b9f2af6613d:
//---------------------------------------------------------- // Simultanuous AD Conversion by polling using // ADC2 and ADC3 on STM32F446 ---- Header // // STM32F446 の ADC2, ADC3 を使って同時に AD 変換を開始し, // ポーリングによりアナログ信号を入力するクラス(ヘッダ) // A0 (PA_0) : ADC2 CH0, 左 // A1 (PA_1) : ADC3 CH1, 右 // Read(), Write() の引数: // 第一引数:A0 (左),第二引数:A1 (右) // // 2016/11/12, Copyright (c) 2016 MIKAMI, Naoki //---------------------------------------------------------- #include "mbed.h" #include "F446_DAC.hpp" #ifndef STM32F446xx #error Select STM32F446. #endif #ifndef F446_ADC_DUAL_HPP #define F446_ADC_DUAL_HPP namespace Mikami { class AdcDual { public: // Constructor // frequency: 標本化周波数 explicit AdcDual(int frequency); // -1.0f <= ad1, ad2 <= 1.0f // ad1: left, ad2: right virtual void Read(float &ad1, float &ad2); // 0 <= ad1, ad2 <= 4095 // ad1: left, ad2: right virtual void Read(uint16_t &ad1, uint16_t &ad2); protected: float ToFloat(uint16_t x) { return AMP_*(x - 2048); } private: static const float AMP_ = 1.0f/2048.0f; static const uint32_t EOC23_ = ADC_CSR_EOC2 | ADC_CSR_EOC3; // AD 変換が完了するまで待つ void WaitDone() { while((ADC->CSR & EOC23_) != EOC23_); } // AD 変換器の外部トリガに使うタイマ (TIM8) の設定 void SetTim8(int frequency); // for inhibition of copy constructor AdcDual(const AdcDual&); // for inhibition of substitute operator AdcDual& operator=(const AdcDual&); }; } #endif // F446_ADC_DUAL_HPP