STM32F446内蔵のADC, DAC を 2 チャンネルで使うためのライブラリの使用例. Example program of library for build-in ADC and DAC in STM32F446 using with dual channels.

Dependencies:   mbed SerialTxRxIntr DSP_ADDA_Dual

main.cpp

Committer:
MikamiUitOpen
Date:
2020-09-22
Revision:
0:c370b7c5a6ad
Child:
1:eb4a0b916723

File content as of revision 0:c370b7c5a6ad:

//----------------------------------------------------------------------
//  NUCLEO-F446 で STM32F446 内蔵の ADC, DAC のためのクラスのデモプログラム
//      使用するクラス:DspAdcDual_Polling, DspDacDual, DspAdcDual_Intr
//      処理の内容:AD 変換器からの入力をそのまま DA 変換器に出力する
//      ポーリング方式と割り込み方式の2つの例を示す
//
//  2020/09/22, Copyright (c) 2020 MIKAMI, Naoki
//----------------------------------------------------------------------

#include "DSP_DacDual.hpp"
// 割り込みの例を有効にする場合,次の #define 文を有効にすること
#define ADC_EXAMPLE_OF_INTERRUPT

//----------------------------------------------------------------
// ポーリングを使う例
#ifndef ADC_EXAMPLE_OF_INTERRUPT
#include "DSP_AdcDualPolling.hpp"
using namespace Mikami;

int main()
{
    const float FS = 10;    // 標本化周波数: 10 kHz
    DspAdcDualPolling myAdc(FS, A0, A1);
    DspDacDual myDac;

    printf("\r\nUsing polling\r\n");
    while (true)
    {
        // float 型の例
        float sn1, sn2;
        myAdc.Read(sn1, sn2);
        myDac.Write(sn1, sn2);
    }
}

//----------------------------------------------------------------
// ADC 変換終了割り込みを使う例
#else
#include "DSP_AdcDualIntr.hpp"
using namespace Mikami;

const float FS = 10;    // 標本化周波数: 10 kHz
DspAdcDualIntr myAdc_(FS, A0, A1);
DspDacDual myDac_;

// ADC 変換終了割り込みに対する割り込みサービス・ルーチン
void AdcIsr()
{
    float sn1, sn2;
    myAdc_.Read(sn1, sn2);
    myDac_.Write(sn1, sn2);
}

int main()
{
    printf("\r\nUsing interrupt\r\n");

    myAdc_.SetIntrVec(&AdcIsr);

    uint32_t n = 0;
    while (true)
    {
        printf("%d\r\n", n++);
        wait(1);
    }
}
#endif