不韋 呂
/
SDR_AM_Rx_CIC
AM中波放送用SDR.CICフィルタのみを使用.CQ出版社「トランジスタ技術」誌,2021年4月号に掲載
SDR_Library/F446_DAC.hpp@3:878a48f15e89, 2021-12-01 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Wed Dec 01 00:37:44 2021 +0000
- Revision:
- 3:878a48f15e89
- Parent:
- 2:4bec6b2be809
4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:6906f8616429 | 1 | //-------------------------------------------------------- |
MikamiUitOpen | 2:4bec6b2be809 | 2 | // STM32F446 内蔵の DAC 用のクラス(ヘッダ) |
MikamiUitOpen | 2:4bec6b2be809 | 3 | // 出力端子: A2 (PA_4) に固定 |
MikamiUitOpen | 0:6906f8616429 | 4 | // |
MikamiUitOpen | 2:4bec6b2be809 | 5 | // 2020/07/23, Copyright (c) 2020 MIKAMI, Naoki |
MikamiUitOpen | 0:6906f8616429 | 6 | //-------------------------------------------------------- |
MikamiUitOpen | 1:30d9fb51dec1 | 7 | |
MikamiUitOpen | 0:6906f8616429 | 8 | #include "mbed.h" |
MikamiUitOpen | 0:6906f8616429 | 9 | |
MikamiUitOpen | 0:6906f8616429 | 10 | #ifndef DAC_F446_SINGLE_HPP |
MikamiUitOpen | 0:6906f8616429 | 11 | #define DAC_F446_SINGLE_HPP |
MikamiUitOpen | 0:6906f8616429 | 12 | |
MikamiUitOpen | 0:6906f8616429 | 13 | namespace Mikami |
MikamiUitOpen | 0:6906f8616429 | 14 | { |
MikamiUitOpen | 0:6906f8616429 | 15 | class DacF446 |
MikamiUitOpen | 0:6906f8616429 | 16 | { |
MikamiUitOpen | 0:6906f8616429 | 17 | public: |
MikamiUitOpen | 0:6906f8616429 | 18 | // コンストラクタ, A2 に接続される CH1 のみを有効にする |
MikamiUitOpen | 2:4bec6b2be809 | 19 | DacF446(); |
MikamiUitOpen | 0:6906f8616429 | 20 | |
MikamiUitOpen | 0:6906f8616429 | 21 | virtual ~DacF446() {} |
MikamiUitOpen | 0:6906f8616429 | 22 | |
MikamiUitOpen | 0:6906f8616429 | 23 | // -1.0f <= data <= 1.0f |
MikamiUitOpen | 0:6906f8616429 | 24 | void Write(float data) { WriteDac1(ToUint16(data)); } |
MikamiUitOpen | 0:6906f8616429 | 25 | |
MikamiUitOpen | 0:6906f8616429 | 26 | private: |
MikamiUitOpen | 0:6906f8616429 | 27 | static const int BIT_WIDTH_ = 12; |
MikamiUitOpen | 2:4bec6b2be809 | 28 | DAC_TypeDef* const DAC_; // DA 変換器に対応する構造体のポインタ |
MikamiUitOpen | 0:6906f8616429 | 29 | |
MikamiUitOpen | 0:6906f8616429 | 30 | // DAC の CH1 へ右詰めで出力する |
MikamiUitOpen | 2:4bec6b2be809 | 31 | void WriteDac1(uint16_t val) { DAC_->DHR12R1 = val; } |
MikamiUitOpen | 0:6906f8616429 | 32 | |
MikamiUitOpen | 0:6906f8616429 | 33 | // 飽和処理を行い uint16_t 型のデータを戻り値とする |
MikamiUitOpen | 0:6906f8616429 | 34 | uint16_t ToUint16(float val) |
MikamiUitOpen | 0:6906f8616429 | 35 | { return __USAT((val + 1.0f)*2048.0f, BIT_WIDTH_); } |
MikamiUitOpen | 0:6906f8616429 | 36 | |
MikamiUitOpen | 2:4bec6b2be809 | 37 | // コピー・コンストラクタ,代入演算子の禁止のため |
MikamiUitOpen | 0:6906f8616429 | 38 | DacF446(const DacF446&); |
MikamiUitOpen | 0:6906f8616429 | 39 | DacF446& operator=(const DacF446&); |
MikamiUitOpen | 0:6906f8616429 | 40 | }; |
MikamiUitOpen | 0:6906f8616429 | 41 | } |
MikamiUitOpen | 2:4bec6b2be809 | 42 | #endif // DAC_F446_SINGLE_HPP |