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
F446_DAC.cpp@0:ad30ac2b412b, 2018-07-03 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Tue Jul 03 01:29:13 2018 +0000
- Revision:
- 0:ad30ac2b412b
- Child:
- 1:cd42ecc1e174
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:ad30ac2b412b | 1 | //-------------------------------------------------------- |
MikamiUitOpen | 0:ad30ac2b412b | 2 | // Class for buit-in single DAC on STM32F446 |
MikamiUitOpen | 0:ad30ac2b412b | 3 | // |
MikamiUitOpen | 0:ad30ac2b412b | 4 | // STM32F446 内蔵の DAC 用のクラス |
MikamiUitOpen | 0:ad30ac2b412b | 5 | // DAC_OUT1: A2 (PA_4) |
MikamiUitOpen | 0:ad30ac2b412b | 6 | // DAC_OUT2: D13 (PA_5) |
MikamiUitOpen | 0:ad30ac2b412b | 7 | // |
MikamiUitOpen | 0:ad30ac2b412b | 8 | // 2018/04/16, Copyright (c) 2018 MIKAMI, Naoki |
MikamiUitOpen | 0:ad30ac2b412b | 9 | //-------------------------------------------------------- |
MikamiUitOpen | 0:ad30ac2b412b | 10 | |
MikamiUitOpen | 0:ad30ac2b412b | 11 | #include "F446_DAC.hpp" |
MikamiUitOpen | 0:ad30ac2b412b | 12 | |
MikamiUitOpen | 0:ad30ac2b412b | 13 | namespace Mikami |
MikamiUitOpen | 0:ad30ac2b412b | 14 | { |
MikamiUitOpen | 0:ad30ac2b412b | 15 | DacF446::DacF446(PinName pin) : da_(pin) |
MikamiUitOpen | 0:ad30ac2b412b | 16 | { |
MikamiUitOpen | 0:ad30ac2b412b | 17 | if ( (pin != A2) && (pin != D13) ) |
MikamiUitOpen | 0:ad30ac2b412b | 18 | { |
MikamiUitOpen | 0:ad30ac2b412b | 19 | fprintf(stderr, "Invalid pin name\r\n"); |
MikamiUitOpen | 0:ad30ac2b412b | 20 | while (true) {} |
MikamiUitOpen | 0:ad30ac2b412b | 21 | } |
MikamiUitOpen | 0:ad30ac2b412b | 22 | if (pin == A2) |
MikamiUitOpen | 0:ad30ac2b412b | 23 | { |
MikamiUitOpen | 0:ad30ac2b412b | 24 | DAC->CR = DAC_CR_EN1 | DAC_CR_TEN1 | DAC_CR_TSEL1; |
MikamiUitOpen | 0:ad30ac2b412b | 25 | fpWriteDac = &DacF446::WriteDac1; |
MikamiUitOpen | 0:ad30ac2b412b | 26 | } |
MikamiUitOpen | 0:ad30ac2b412b | 27 | else |
MikamiUitOpen | 0:ad30ac2b412b | 28 | { |
MikamiUitOpen | 0:ad30ac2b412b | 29 | DAC->CR = DAC_CR_EN2 | DAC_CR_TEN2 | DAC_CR_TSEL2; |
MikamiUitOpen | 0:ad30ac2b412b | 30 | fpWriteDac = &DacF446::WriteDac2; |
MikamiUitOpen | 0:ad30ac2b412b | 31 | } |
MikamiUitOpen | 0:ad30ac2b412b | 32 | } |
MikamiUitOpen | 0:ad30ac2b412b | 33 | |
MikamiUitOpen | 0:ad30ac2b412b | 34 | // DAC の CH1 へ出力する |
MikamiUitOpen | 0:ad30ac2b412b | 35 | void DacF446::WriteDac1(uint16_t val) |
MikamiUitOpen | 0:ad30ac2b412b | 36 | { |
MikamiUitOpen | 0:ad30ac2b412b | 37 | DAC->DHR12R1 = val; |
MikamiUitOpen | 0:ad30ac2b412b | 38 | DAC->SWTRIGR = DAC_SWTRIGR_SWTRIG1; |
MikamiUitOpen | 0:ad30ac2b412b | 39 | } |
MikamiUitOpen | 0:ad30ac2b412b | 40 | // DAC の CH2 へ出力する |
MikamiUitOpen | 0:ad30ac2b412b | 41 | void DacF446::WriteDac2(uint16_t val) |
MikamiUitOpen | 0:ad30ac2b412b | 42 | { |
MikamiUitOpen | 0:ad30ac2b412b | 43 | DAC->DHR12R2 = val; |
MikamiUitOpen | 0:ad30ac2b412b | 44 | DAC->SWTRIGR = DAC_SWTRIGR_SWTRIG2; |
MikamiUitOpen | 0:ad30ac2b412b | 45 | } |
MikamiUitOpen | 0:ad30ac2b412b | 46 | } |