![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CQ出版社セミナ "実習・Armマイコン内蔵ペリフェラルを活用するためのC++プログラミング" で使う外付け回路のテスト
Dependencies: mbed UIT_SetOutputPortType UIT_AQM1602 UIT_ADT7410
F446_ADDA/F446_Dac.hpp@0:8c850cf6285d, 2020-03-03 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Tue Mar 03 03:30:50 2020 +0000
- Revision:
- 0:8c850cf6285d
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:8c850cf6285d | 1 | //-------------------------------------------------------- |
MikamiUitOpen | 0:8c850cf6285d | 2 | // STM32F446 内蔵の DAC 用のクラス |
MikamiUitOpen | 0:8c850cf6285d | 3 | // 出力端子: A2 (PA_4) |
MikamiUitOpen | 0:8c850cf6285d | 4 | // |
MikamiUitOpen | 0:8c850cf6285d | 5 | // 2020/02/18, Copyright (c) 2020 MIKAMI, Naoki |
MikamiUitOpen | 0:8c850cf6285d | 6 | //-------------------------------------------------------- |
MikamiUitOpen | 0:8c850cf6285d | 7 | #include "mbed.h" |
MikamiUitOpen | 0:8c850cf6285d | 8 | |
MikamiUitOpen | 0:8c850cf6285d | 9 | #ifndef DAC_F446_SINGLE_HPP |
MikamiUitOpen | 0:8c850cf6285d | 10 | #define DAC_F446_SINGLE_HPP |
MikamiUitOpen | 0:8c850cf6285d | 11 | |
MikamiUitOpen | 0:8c850cf6285d | 12 | namespace Mikami |
MikamiUitOpen | 0:8c850cf6285d | 13 | { |
MikamiUitOpen | 0:8c850cf6285d | 14 | class DacF446 |
MikamiUitOpen | 0:8c850cf6285d | 15 | { |
MikamiUitOpen | 0:8c850cf6285d | 16 | public: |
MikamiUitOpen | 0:8c850cf6285d | 17 | // コンストラクタ, A2 に接続される CH1 のみを有効にする |
MikamiUitOpen | 0:8c850cf6285d | 18 | DacF446(); |
MikamiUitOpen | 0:8c850cf6285d | 19 | |
MikamiUitOpen | 0:8c850cf6285d | 20 | virtual ~DacF446() {} |
MikamiUitOpen | 0:8c850cf6285d | 21 | |
MikamiUitOpen | 0:8c850cf6285d | 22 | // -1.0f <= data <= 1.0f |
MikamiUitOpen | 0:8c850cf6285d | 23 | void Write(float data) { WriteDacCh1(ToUint16(data)); } |
MikamiUitOpen | 0:8c850cf6285d | 24 | |
MikamiUitOpen | 0:8c850cf6285d | 25 | // 0 <= data <= 4095 |
MikamiUitOpen | 0:8c850cf6285d | 26 | void Write(uint16_t data) { WriteDacCh1(__USAT(data, BIT_WIDTH_)); } |
MikamiUitOpen | 0:8c850cf6285d | 27 | |
MikamiUitOpen | 0:8c850cf6285d | 28 | private: |
MikamiUitOpen | 0:8c850cf6285d | 29 | static const int BIT_WIDTH_ = 12; |
MikamiUitOpen | 0:8c850cf6285d | 30 | DAC_TypeDef* const myDac_; // DA 変換器に対応するポインタ |
MikamiUitOpen | 0:8c850cf6285d | 31 | |
MikamiUitOpen | 0:8c850cf6285d | 32 | // DAC の CH1 へ右詰めで出力する |
MikamiUitOpen | 0:8c850cf6285d | 33 | void WriteDacCh1(uint16_t val) { myDac_->DHR12R1 = val; } |
MikamiUitOpen | 0:8c850cf6285d | 34 | |
MikamiUitOpen | 0:8c850cf6285d | 35 | // 飽和処理を行い uint16_t 型のデータを戻り値とする |
MikamiUitOpen | 0:8c850cf6285d | 36 | uint16_t ToUint16(float val) |
MikamiUitOpen | 0:8c850cf6285d | 37 | { return __USAT((val + 1.0f)*2048.0f, BIT_WIDTH_); } |
MikamiUitOpen | 0:8c850cf6285d | 38 | |
MikamiUitOpen | 0:8c850cf6285d | 39 | // DA 変換器に関係のある GPIO の設定 |
MikamiUitOpen | 0:8c850cf6285d | 40 | void SetGPIO(); |
MikamiUitOpen | 0:8c850cf6285d | 41 | |
MikamiUitOpen | 0:8c850cf6285d | 42 | // コピー・コンストラクタ,代入演算子禁止のため |
MikamiUitOpen | 0:8c850cf6285d | 43 | DacF446(const DacF446&); |
MikamiUitOpen | 0:8c850cf6285d | 44 | DacF446& operator=(const DacF446&); |
MikamiUitOpen | 0:8c850cf6285d | 45 | }; |
MikamiUitOpen | 0:8c850cf6285d | 46 | } |
MikamiUitOpen | 0:8c850cf6285d | 47 | #endif // DAC_F446_SINGLE_HPP |
MikamiUitOpen | 0:8c850cf6285d | 48 |