Nucleo-F446RE 内蔵の AD/DA を使うためのライブラリ.DA からの出力は,標本化周波数の4倍のレートで行う.AD の読み込みにはソフトウェア割り込みを使用. このライブラリを登録した際のプログラム: Demo_F446_AD_DA_MultirateSWI. Library for built-in ADC and DAC in Nucleo-F446RE using software interrupt for reading ADC. Sampling rate for DAC is four times of that for ADC.
Dependents: F446_UpSampling_LPF_HPF_Variable Demo_F446_AD_DA_MultirateSWI
F446_DAC.hpp
- Committer:
- MikamiUitOpen
- Date:
- 2020-02-09
- Revision:
- 2:c8aa7ae0012c
- Parent:
- 1:ea2fb701744d
File content as of revision 2:c8aa7ae0012c:
//-------------------------------------------------------- // Class for buit-in single DAC on STM32F446 ---- Header // // STM32F446 内蔵の DAC 用のクラス(ヘッダ) // 選択可能な入力端子: // A2 (PA_4): ---- デフォルト // D13 (PA_5): このポートはマイコンボードの LED もドライブするので // このポートは使わない方がよい // // 2018/11/28, Copyright (c) 2018 MIKAMI, Naoki //-------------------------------------------------------- #include "mbed.h" #ifndef STM32F446xx #error Not NUCLEO-F446RE. #endif #ifndef F446_DAC_SINGLE_HPP #define F446_DAC_SINGLE_HPP namespace Mikami { class DacF446 { public: // Constructor explicit DacF446(PinName pin = A2); virtual ~DacF446() {} // -1.0f <= data <= 1.0f void Write(float data) { WriteDac(ToUint16(data)); } // 0 <= data <= 4095 void Write(uint16_t data) { WriteDac(__USAT(data, BIT_WIDTH_)); } private: void (DacF446::*fpWriteDac)(uint16_t); static const int BIT_WIDTH_ = 12; AnalogOut da_; // DAC の片方のチェンネルへ出力する void WriteDac1(uint16_t val) { DAC->DHR12R1 = val; } // CH1 へ void WriteDac2(uint16_t val) { DAC->DHR12R2 = val; } // CH2 へ void WriteDac(uint16_t val) { (this->*fpWriteDac)(val); } // 飽和処理を行い uint16_t 型のデータを戻り値とする uint16_t ToUint16(float val) { return __USAT((val + 1.0f)*2048.0f, BIT_WIDTH_); } // for inhibition of copy constructor DacF446(const DacF446&); // for inhibition of substitute operator DacF446& operator=(const DacF446&); }; } #endif // F446_DAC_SINGLE_HPP