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