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
Diff: F446_ADC.hpp
- Revision:
- 0:c945b4fe9a48
- Child:
- 1:6b9f2af6613d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/F446_ADC.hpp Fri Nov 11 06:28:48 2016 +0000 @@ -0,0 +1,58 @@ +//---------------------------------------------------------- +// 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 +// +// 2016/11/10, Copyright (c) 2016 MIKAMI, Naoki +//---------------------------------------------------------- + +#include "mbed.h" + +#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 <= data1, data2 <= 1.0f + virtual void Read(float &ad1, float &ad2); + + // 0 <= data1, data2 <= 4095 + 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 \ No newline at end of file