Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: F446_DSP_Oscilloscope Demo_DSP_ADDA_Dual TrG_Oscilloscope
DSP_DacDual.hpp
00001 //-------------------------------------------------------- 00002 // STM32F446 内蔵の DAC 用のクラス(ヘッダ) 00003 // A2 (PA_4): 左 00004 // D13 (PA_5): 右 00005 // 00006 // 2020/09/22, Copyright (c) 2020 MIKAMI, Naoki 00007 //-------------------------------------------------------- 00008 00009 #include "mbed.h" 00010 #include "PeripheralPins.h" // pin_function() で使用 00011 // PeripheralPins.c が含まれるディレクトリ: 00012 // mbed-dev\targets\TARGET_STM\TARGET_STM32F4\ 00013 // TARGET_STM32F446xE\TARGET_NUCLEO_F446RE 00014 00015 #ifndef STM32F446xx 00016 #error Select NUCLEO-F446RE. 00017 #endif 00018 00019 #ifndef F446_DAC_DUAL_HPP 00020 #define F446_DAC_DUAL_HPP 00021 00022 namespace Mikami 00023 { 00024 class DspDacDual 00025 { 00026 public: 00027 // コンストラクタ 00028 DspDacDual(); 00029 00030 virtual ~DspDacDual() {} 00031 00032 // -1.0f <= data1, data2 <= 1.0f 00033 void Write(float data1, float data2) 00034 { WriteDac(ToUint16(data1), ToUint16(data2)); } 00035 00036 // 0 <= data1, data2 <= 4095 00037 void Write(uint16_t data1, uint16_t data2) 00038 { WriteDac(__USAT(data1, BIT_WIDTH_), 00039 __USAT(data2, BIT_WIDTH_)); } 00040 00041 private: 00042 static const int BIT_WIDTH_ = 12; 00043 DAC_TypeDef* const DAC_; // DA 変換器に対応する構造体のポインタ 00044 00045 // float 型のデータを uint16_t 型に変換,飽和処理付き 00046 uint16_t ToUint16(float val) 00047 { return __USAT((val + 1.0f)*2047.0f, BIT_WIDTH_); } 00048 00049 // 2チャンネル分を同時に DAC に書き込む 00050 void WriteDac(uint16_t val1, uint16_t val2) 00051 { DAC->DHR12RD = __PKHBT(val1, val2, 16); } 00052 00053 // コピー・コンストラクタ,代入演算子の禁止のため 00054 DspDacDual(const DspDacDual&); 00055 DspDacDual& operator=(const DspDacDual&); 00056 }; 00057 } 00058 #endif // F446_DAC_DUAL_HPP
Generated on Tue Jul 19 2022 03:14:12 by
