IIR filter of 1st order for ST Nucleo F401RE.

Dependencies:   UIT_ADDA mbed

main.cpp

Committer:
MikamiUitOpen
Date:
2014-11-15
Revision:
3:b17e5d790a55
Parent:
2:ed56284ebeb7

File content as of revision 3:b17e5d790a55:

//--------------------------------------------------------------
// 1次の IIR フィルタ
//      Analog Input : A0
//      Analog Output: MCP4922 using SPI
// 2014/11/12, Copyright (c) 2014 MIKAMI, Naoki
//--------------------------------------------------------------

#include "mbed.h"

#include "ADC_Base.hpp"         // for ADC not using interrupt
#include "DAC_MCP4922.hpp"      // for DAC MCP4922

using namespace Mikami;

const int FS_ = 12000;  // Sampling frequency: 12 kHz
ADC_Base adc_(A0, FS_); // for AD
DAC_MCP4922 myDac_;     // for DA

int main()
{
    myDac_.ScfClockTim3(500000);    // cutoff frequency: 5 kHz

    const float A1 = 0.8f;
    const float B0 = 1.0f - A1;
    float yn = 0;
    
    while (true)
    {
        float xn = adc_.Read();     // Read from A0
        //-----------------------------------------------

        yn = A1*yn + B0*xn;

        //-----------------------------------------------
        myDac_.Write(yn);           // Write to DAC
    }
}