Added one channel mode
Dependents: CW_Decoder_using_FFT_on_F446
Fork of F446_AD_DA by
F446_ADC.hpp@0:c945b4fe9a48, 2016-11-11 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Fri Nov 11 06:28:48 2016 +0000
- Revision:
- 0:c945b4fe9a48
- Child:
- 1:6b9f2af6613d
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:c945b4fe9a48 | 1 | //---------------------------------------------------------- |
MikamiUitOpen | 0:c945b4fe9a48 | 2 | // Simultanuous AD Conversion by polling using |
MikamiUitOpen | 0:c945b4fe9a48 | 3 | // ADC2 and ADC3 on STM32F446 ---- Header |
MikamiUitOpen | 0:c945b4fe9a48 | 4 | // |
MikamiUitOpen | 0:c945b4fe9a48 | 5 | // STM32F446 の ADC2, ADC3 を使って同時に AD 変換を開始し, |
MikamiUitOpen | 0:c945b4fe9a48 | 6 | // ポーリングによりアナログ信号を入力するクラス(ヘッダ) |
MikamiUitOpen | 0:c945b4fe9a48 | 7 | // A0 (PA_0) : ADC2 CH0 |
MikamiUitOpen | 0:c945b4fe9a48 | 8 | // A1 (PA_1) : ADC3 CH1 |
MikamiUitOpen | 0:c945b4fe9a48 | 9 | // |
MikamiUitOpen | 0:c945b4fe9a48 | 10 | // 2016/11/10, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:c945b4fe9a48 | 11 | //---------------------------------------------------------- |
MikamiUitOpen | 0:c945b4fe9a48 | 12 | |
MikamiUitOpen | 0:c945b4fe9a48 | 13 | #include "mbed.h" |
MikamiUitOpen | 0:c945b4fe9a48 | 14 | |
MikamiUitOpen | 0:c945b4fe9a48 | 15 | #ifndef STM32F446xx |
MikamiUitOpen | 0:c945b4fe9a48 | 16 | #error Select STM32F446. |
MikamiUitOpen | 0:c945b4fe9a48 | 17 | #endif |
MikamiUitOpen | 0:c945b4fe9a48 | 18 | |
MikamiUitOpen | 0:c945b4fe9a48 | 19 | #ifndef F446_ADC_DUAL_HPP |
MikamiUitOpen | 0:c945b4fe9a48 | 20 | #define F446_ADC_DUAL_HPP |
MikamiUitOpen | 0:c945b4fe9a48 | 21 | |
MikamiUitOpen | 0:c945b4fe9a48 | 22 | namespace Mikami |
MikamiUitOpen | 0:c945b4fe9a48 | 23 | { |
MikamiUitOpen | 0:c945b4fe9a48 | 24 | class AdcDual |
MikamiUitOpen | 0:c945b4fe9a48 | 25 | { |
MikamiUitOpen | 0:c945b4fe9a48 | 26 | public: |
MikamiUitOpen | 0:c945b4fe9a48 | 27 | // Constructor |
MikamiUitOpen | 0:c945b4fe9a48 | 28 | // frequency: 標本化周波数 |
MikamiUitOpen | 0:c945b4fe9a48 | 29 | explicit AdcDual(int frequency); |
MikamiUitOpen | 0:c945b4fe9a48 | 30 | |
MikamiUitOpen | 0:c945b4fe9a48 | 31 | // -1.0f <= data1, data2 <= 1.0f |
MikamiUitOpen | 0:c945b4fe9a48 | 32 | virtual void Read(float &ad1, float &ad2); |
MikamiUitOpen | 0:c945b4fe9a48 | 33 | |
MikamiUitOpen | 0:c945b4fe9a48 | 34 | // 0 <= data1, data2 <= 4095 |
MikamiUitOpen | 0:c945b4fe9a48 | 35 | virtual void Read(uint16_t &ad1, uint16_t &ad2); |
MikamiUitOpen | 0:c945b4fe9a48 | 36 | |
MikamiUitOpen | 0:c945b4fe9a48 | 37 | protected: |
MikamiUitOpen | 0:c945b4fe9a48 | 38 | float ToFloat(uint16_t x) |
MikamiUitOpen | 0:c945b4fe9a48 | 39 | { return AMP_*(x - 2048); } |
MikamiUitOpen | 0:c945b4fe9a48 | 40 | |
MikamiUitOpen | 0:c945b4fe9a48 | 41 | private: |
MikamiUitOpen | 0:c945b4fe9a48 | 42 | static const float AMP_ = 1.0f/2048.0f; |
MikamiUitOpen | 0:c945b4fe9a48 | 43 | static const uint32_t EOC23_ = ADC_CSR_EOC2 | ADC_CSR_EOC3; |
MikamiUitOpen | 0:c945b4fe9a48 | 44 | |
MikamiUitOpen | 0:c945b4fe9a48 | 45 | // AD 変換が完了するまで待つ |
MikamiUitOpen | 0:c945b4fe9a48 | 46 | void WaitDone() |
MikamiUitOpen | 0:c945b4fe9a48 | 47 | { while((ADC->CSR & EOC23_) != EOC23_); } |
MikamiUitOpen | 0:c945b4fe9a48 | 48 | |
MikamiUitOpen | 0:c945b4fe9a48 | 49 | // AD 変換器の外部トリガに使うタイマ (TIM8) の設定 |
MikamiUitOpen | 0:c945b4fe9a48 | 50 | void SetTim8(int frequency); |
MikamiUitOpen | 0:c945b4fe9a48 | 51 | |
MikamiUitOpen | 0:c945b4fe9a48 | 52 | // for inhibition of copy constructor |
MikamiUitOpen | 0:c945b4fe9a48 | 53 | AdcDual(const AdcDual&); |
MikamiUitOpen | 0:c945b4fe9a48 | 54 | // for inhibition of substitute operator |
MikamiUitOpen | 0:c945b4fe9a48 | 55 | AdcDual& operator=(const AdcDual&); |
MikamiUitOpen | 0:c945b4fe9a48 | 56 | }; |
MikamiUitOpen | 0:c945b4fe9a48 | 57 | } |
MikamiUitOpen | 0:c945b4fe9a48 | 58 | #endif // F446_ADC_DUAL_HPP |