Nucleo-F446RE 内蔵の AD/DA を使うためのライブラリ.DA からの出力は,標本化周波数の4倍のレートで行う.出力の補間フィルタには直線位相の FIR フィルタを使用. このライブラリを登録した際のプログラム: Demo_F446_AD_DA_MultirateLinearPhase. Library for built-in ADC and DAC in Nucleo-F446RE. Sampling rate for DAC is four times of that for ADC. Interpolation filter for output is linear-phase FIR filter.
Dependents: Demo_F446_AD_DA_MultirateLinearPhase
Diff: F446_DAC.cpp
- Revision:
- 0:ad30ac2b412b
- Child:
- 1:cd42ecc1e174
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/F446_DAC.cpp Tue Jul 03 01:29:13 2018 +0000 @@ -0,0 +1,46 @@ +//-------------------------------------------------------- +// Class for buit-in single DAC on STM32F446 +// +// STM32F446 内蔵の DAC 用のクラス +// DAC_OUT1: A2 (PA_4) +// DAC_OUT2: D13 (PA_5) +// +// 2018/04/16, Copyright (c) 2018 MIKAMI, Naoki +//-------------------------------------------------------- + +#include "F446_DAC.hpp" + +namespace Mikami +{ + DacF446::DacF446(PinName pin) : da_(pin) + { + if ( (pin != A2) && (pin != D13) ) + { + fprintf(stderr, "Invalid pin name\r\n"); + while (true) {} + } + if (pin == A2) + { + DAC->CR = DAC_CR_EN1 | DAC_CR_TEN1 | DAC_CR_TSEL1; + fpWriteDac = &DacF446::WriteDac1; + } + else + { + DAC->CR = DAC_CR_EN2 | DAC_CR_TEN2 | DAC_CR_TSEL2; + fpWriteDac = &DacF446::WriteDac2; + } + } + + // DAC の CH1 へ出力する + void DacF446::WriteDac1(uint16_t val) + { + DAC->DHR12R1 = val; + DAC->SWTRIGR = DAC_SWTRIGR_SWTRIG1; + } + // DAC の CH2 へ出力する + void DacF446::WriteDac2(uint16_t val) + { + DAC->DHR12R2 = val; + DAC->SWTRIGR = DAC_SWTRIGR_SWTRIG2; + } +}