![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Example of use of library for build-in ADC and DAC in STM32F446 mounted on Nucleo F446RE. Nucleo F446RE に搭載されている STM32F446 の内蔵 ADC, DAC 用のライブラリの使用例.
main.cpp@4:5a893341990d, 2017-02-21 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Tue Feb 21 12:57:13 2017 +0000
- Revision:
- 4:5a893341990d
- Parent:
- 3:ec03e3cffc9b
5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 2:2e6922bceec1 | 1 | //---------------------------------------------------------------------- |
MikamiUitOpen | 2:2e6922bceec1 | 2 | // NUCLEO-F446 で STM32F446 内蔵の ADC, DAC のためのクラスのデモプログラム |
MikamiUitOpen | 0:d1d504410da6 | 3 | // 使用するクラス:AdcDual, DacDual, AdcDualIntr |
MikamiUitOpen | 0:d1d504410da6 | 4 | // 処理の内容:AD 変換器からの入力をそのまま DA 変換器に出力する |
MikamiUitOpen | 0:d1d504410da6 | 5 | // ポーリング方式と割り込み方式の2つの例を示す |
MikamiUitOpen | 0:d1d504410da6 | 6 | // |
MikamiUitOpen | 4:5a893341990d | 7 | // 2017/02/19, Copyright (c) 2017 MIKAMI, Naoki |
MikamiUitOpen | 2:2e6922bceec1 | 8 | //---------------------------------------------------------------------- |
MikamiUitOpen | 0:d1d504410da6 | 9 | |
MikamiUitOpen | 0:d1d504410da6 | 10 | // 割り込みの例を有効にする場合,次の #define 文を有効にすること |
MikamiUitOpen | 1:e462cfe9476d | 11 | //#define ADC_EXAMPLE_OF_INTERRUPT |
MikamiUitOpen | 0:d1d504410da6 | 12 | |
MikamiUitOpen | 0:d1d504410da6 | 13 | //---------------------------------------------------------------- |
MikamiUitOpen | 0:d1d504410da6 | 14 | // ポーリングを使う例 |
MikamiUitOpen | 0:d1d504410da6 | 15 | #ifndef ADC_EXAMPLE_OF_INTERRUPT |
MikamiUitOpen | 0:d1d504410da6 | 16 | #include "F446_ADC.hpp" |
MikamiUitOpen | 1:e462cfe9476d | 17 | using namespace Mikami; |
MikamiUitOpen | 0:d1d504410da6 | 18 | |
MikamiUitOpen | 0:d1d504410da6 | 19 | int main() |
MikamiUitOpen | 0:d1d504410da6 | 20 | { |
MikamiUitOpen | 3:ec03e3cffc9b | 21 | const int FS = 10000; // Sampling frequency: 10 kHz |
MikamiUitOpen | 0:d1d504410da6 | 22 | AdcDual myAdc(FS); // See "F446_ADC.hpp" |
MikamiUitOpen | 0:d1d504410da6 | 23 | DacDual myDac; // See "F446_DAC.hpp" |
MikamiUitOpen | 0:d1d504410da6 | 24 | myDac.ScfClock(420000); // 出力の LPF の遮断周波数を 4.2 kHz に設定 |
MikamiUitOpen | 0:d1d504410da6 | 25 | |
MikamiUitOpen | 0:d1d504410da6 | 26 | printf("\r\nUsing polling\r\n"); |
MikamiUitOpen | 0:d1d504410da6 | 27 | while (true) |
MikamiUitOpen | 0:d1d504410da6 | 28 | { |
MikamiUitOpen | 0:d1d504410da6 | 29 | // float 型の例 |
MikamiUitOpen | 0:d1d504410da6 | 30 | float sn1, sn2; |
MikamiUitOpen | 0:d1d504410da6 | 31 | myAdc.Read(sn1, sn2); |
MikamiUitOpen | 0:d1d504410da6 | 32 | /* |
MikamiUitOpen | 0:d1d504410da6 | 33 | // uint16_t 型の例 |
MikamiUitOpen | 0:d1d504410da6 | 34 | uint16_t sn1, sn2; |
MikamiUitOpen | 0:d1d504410da6 | 35 | myAdc.Read(sn1, sn2); |
MikamiUitOpen | 0:d1d504410da6 | 36 | */ |
MikamiUitOpen | 0:d1d504410da6 | 37 | myDac.Write(sn1, sn2); |
MikamiUitOpen | 0:d1d504410da6 | 38 | } |
MikamiUitOpen | 0:d1d504410da6 | 39 | } |
MikamiUitOpen | 0:d1d504410da6 | 40 | |
MikamiUitOpen | 0:d1d504410da6 | 41 | //---------------------------------------------------------------- |
MikamiUitOpen | 0:d1d504410da6 | 42 | // ADC 変換終了割り込みを使う例 |
MikamiUitOpen | 0:d1d504410da6 | 43 | #else |
MikamiUitOpen | 0:d1d504410da6 | 44 | #include "F446_ADC_Interrupt.hpp" |
MikamiUitOpen | 1:e462cfe9476d | 45 | using namespace Mikami; |
MikamiUitOpen | 0:d1d504410da6 | 46 | |
MikamiUitOpen | 0:d1d504410da6 | 47 | const int FS_ = 10000; // Sampling frequency: 10 kHz |
MikamiUitOpen | 1:e462cfe9476d | 48 | AdcDual_Intr myAdc_(FS_); // See "F446_ADC_Interrupt.hpp" |
MikamiUitOpen | 0:d1d504410da6 | 49 | DacDual myDac_; // See "F446_DAC.hpp" |
MikamiUitOpen | 0:d1d504410da6 | 50 | |
MikamiUitOpen | 0:d1d504410da6 | 51 | // ADC 変換終了割り込みに対する割り込みサービス・ルーチン |
MikamiUitOpen | 0:d1d504410da6 | 52 | void AdcIsr() |
MikamiUitOpen | 0:d1d504410da6 | 53 | { |
MikamiUitOpen | 0:d1d504410da6 | 54 | float sn1, sn2; |
MikamiUitOpen | 0:d1d504410da6 | 55 | myAdc_.Read(sn1, sn2); |
MikamiUitOpen | 0:d1d504410da6 | 56 | myDac_.Write(sn1, sn2); |
MikamiUitOpen | 0:d1d504410da6 | 57 | } |
MikamiUitOpen | 0:d1d504410da6 | 58 | |
MikamiUitOpen | 0:d1d504410da6 | 59 | int main() |
MikamiUitOpen | 0:d1d504410da6 | 60 | { |
MikamiUitOpen | 0:d1d504410da6 | 61 | printf("\r\nUsing interrupt\r\n"); |
MikamiUitOpen | 0:d1d504410da6 | 62 | |
MikamiUitOpen | 0:d1d504410da6 | 63 | myDac_.ScfClock(420000); // 出力の LPF の遮断周波数を 4.2 kHz に設定 |
MikamiUitOpen | 0:d1d504410da6 | 64 | // ADC 変換終了割り込みに対する割り込みサービス・ルーチンを割り当てる |
MikamiUitOpen | 0:d1d504410da6 | 65 | myAdc_.SetIntrVec(&AdcIsr); |
MikamiUitOpen | 0:d1d504410da6 | 66 | |
MikamiUitOpen | 0:d1d504410da6 | 67 | uint32_t n = 0; |
MikamiUitOpen | 0:d1d504410da6 | 68 | while (true) |
MikamiUitOpen | 0:d1d504410da6 | 69 | { |
MikamiUitOpen | 0:d1d504410da6 | 70 | printf("%d\r\n", n++); |
MikamiUitOpen | 0:d1d504410da6 | 71 | wait(1); |
MikamiUitOpen | 0:d1d504410da6 | 72 | } |
MikamiUitOpen | 0:d1d504410da6 | 73 | } |
MikamiUitOpen | 0:d1d504410da6 | 74 | #endif |