Added one channel mode
Dependents: CW_Decoder_using_FFT_on_F446
Fork of F446_AD_DA by
F446_ADC.hpp@1:6b9f2af6613d, 2016-11-12 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Nov 12 04:08:31 2016 +0000
- Revision:
- 1:6b9f2af6613d
- Parent:
- 0:c945b4fe9a48
- Child:
- 2:29f9831ce719
2
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 | 1:6b9f2af6613d | 7 | // A0 (PA_0) : ADC2 CH0, 左 |
MikamiUitOpen | 1:6b9f2af6613d | 8 | // A1 (PA_1) : ADC3 CH1, 右 |
MikamiUitOpen | 1:6b9f2af6613d | 9 | // Read(), Write() の引数: |
MikamiUitOpen | 1:6b9f2af6613d | 10 | // 第一引数:A0 (左),第二引数:A1 (右) |
MikamiUitOpen | 0:c945b4fe9a48 | 11 | // |
MikamiUitOpen | 1:6b9f2af6613d | 12 | // 2016/11/12, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:c945b4fe9a48 | 13 | //---------------------------------------------------------- |
MikamiUitOpen | 0:c945b4fe9a48 | 14 | |
MikamiUitOpen | 0:c945b4fe9a48 | 15 | #include "mbed.h" |
MikamiUitOpen | 1:6b9f2af6613d | 16 | #include "F446_DAC.hpp" |
MikamiUitOpen | 0:c945b4fe9a48 | 17 | |
MikamiUitOpen | 0:c945b4fe9a48 | 18 | #ifndef STM32F446xx |
MikamiUitOpen | 0:c945b4fe9a48 | 19 | #error Select STM32F446. |
MikamiUitOpen | 0:c945b4fe9a48 | 20 | #endif |
MikamiUitOpen | 0:c945b4fe9a48 | 21 | |
MikamiUitOpen | 0:c945b4fe9a48 | 22 | #ifndef F446_ADC_DUAL_HPP |
MikamiUitOpen | 0:c945b4fe9a48 | 23 | #define F446_ADC_DUAL_HPP |
MikamiUitOpen | 0:c945b4fe9a48 | 24 | |
MikamiUitOpen | 0:c945b4fe9a48 | 25 | namespace Mikami |
MikamiUitOpen | 0:c945b4fe9a48 | 26 | { |
MikamiUitOpen | 0:c945b4fe9a48 | 27 | class AdcDual |
MikamiUitOpen | 0:c945b4fe9a48 | 28 | { |
MikamiUitOpen | 0:c945b4fe9a48 | 29 | public: |
MikamiUitOpen | 0:c945b4fe9a48 | 30 | // Constructor |
MikamiUitOpen | 0:c945b4fe9a48 | 31 | // frequency: 標本化周波数 |
MikamiUitOpen | 0:c945b4fe9a48 | 32 | explicit AdcDual(int frequency); |
MikamiUitOpen | 0:c945b4fe9a48 | 33 | |
MikamiUitOpen | 1:6b9f2af6613d | 34 | // -1.0f <= ad1, ad2 <= 1.0f |
MikamiUitOpen | 1:6b9f2af6613d | 35 | // ad1: left, ad2: right |
MikamiUitOpen | 0:c945b4fe9a48 | 36 | virtual void Read(float &ad1, float &ad2); |
MikamiUitOpen | 0:c945b4fe9a48 | 37 | |
MikamiUitOpen | 1:6b9f2af6613d | 38 | // 0 <= ad1, ad2 <= 4095 |
MikamiUitOpen | 1:6b9f2af6613d | 39 | // ad1: left, ad2: right |
MikamiUitOpen | 0:c945b4fe9a48 | 40 | virtual void Read(uint16_t &ad1, uint16_t &ad2); |
MikamiUitOpen | 0:c945b4fe9a48 | 41 | |
MikamiUitOpen | 0:c945b4fe9a48 | 42 | protected: |
MikamiUitOpen | 0:c945b4fe9a48 | 43 | float ToFloat(uint16_t x) |
MikamiUitOpen | 0:c945b4fe9a48 | 44 | { return AMP_*(x - 2048); } |
MikamiUitOpen | 0:c945b4fe9a48 | 45 | |
MikamiUitOpen | 0:c945b4fe9a48 | 46 | private: |
MikamiUitOpen | 0:c945b4fe9a48 | 47 | static const float AMP_ = 1.0f/2048.0f; |
MikamiUitOpen | 0:c945b4fe9a48 | 48 | static const uint32_t EOC23_ = ADC_CSR_EOC2 | ADC_CSR_EOC3; |
MikamiUitOpen | 0:c945b4fe9a48 | 49 | |
MikamiUitOpen | 0:c945b4fe9a48 | 50 | // AD 変換が完了するまで待つ |
MikamiUitOpen | 0:c945b4fe9a48 | 51 | void WaitDone() |
MikamiUitOpen | 0:c945b4fe9a48 | 52 | { while((ADC->CSR & EOC23_) != EOC23_); } |
MikamiUitOpen | 0:c945b4fe9a48 | 53 | |
MikamiUitOpen | 0:c945b4fe9a48 | 54 | // AD 変換器の外部トリガに使うタイマ (TIM8) の設定 |
MikamiUitOpen | 0:c945b4fe9a48 | 55 | void SetTim8(int frequency); |
MikamiUitOpen | 0:c945b4fe9a48 | 56 | |
MikamiUitOpen | 0:c945b4fe9a48 | 57 | // for inhibition of copy constructor |
MikamiUitOpen | 0:c945b4fe9a48 | 58 | AdcDual(const AdcDual&); |
MikamiUitOpen | 0:c945b4fe9a48 | 59 | // for inhibition of substitute operator |
MikamiUitOpen | 0:c945b4fe9a48 | 60 | AdcDual& operator=(const AdcDual&); |
MikamiUitOpen | 0:c945b4fe9a48 | 61 | }; |
MikamiUitOpen | 0:c945b4fe9a48 | 62 | } |
MikamiUitOpen | 1:6b9f2af6613d | 63 | #endif // F446_ADC_DUAL_HPP |