![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
FIR filter of transposed form for ST Nucleo F401RE.
main.cpp@5:0819b64a9620, 2014-11-15 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Nov 15 06:12:12 2014 +0000
- Revision:
- 5:0819b64a9620
- Parent:
- 4:17ca341bea00
6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:b0e06f5ed486 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:b0e06f5ed486 | 2 | // FIR フィルタ,転置形 |
MikamiUitOpen | 0:b0e06f5ed486 | 3 | // Analog Input : A0 |
MikamiUitOpen | 0:b0e06f5ed486 | 4 | // Analog Output: MCP4922 using SPI |
MikamiUitOpen | 4:17ca341bea00 | 5 | // 2014/11/12, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:b0e06f5ed486 | 6 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:b0e06f5ed486 | 7 | |
MikamiUitOpen | 0:b0e06f5ed486 | 8 | #include "mbed.h" |
MikamiUitOpen | 0:b0e06f5ed486 | 9 | |
MikamiUitOpen | 0:b0e06f5ed486 | 10 | #include "ADC_Base.hpp" // for ADC not using interrupt |
MikamiUitOpen | 0:b0e06f5ed486 | 11 | #include "DAC_MCP4922.hpp" // for DAC MCP4922 |
MikamiUitOpen | 0:b0e06f5ed486 | 12 | #include "Coefficients_200_LPF.hpp" |
MikamiUitOpen | 0:b0e06f5ed486 | 13 | |
MikamiUitOpen | 0:b0e06f5ed486 | 14 | using namespace Mikami; |
MikamiUitOpen | 0:b0e06f5ed486 | 15 | |
MikamiUitOpen | 2:7ac5be6f3e29 | 16 | const int FS_ = 12000; // Sampling frequency: 12 kHz |
MikamiUitOpen | 2:7ac5be6f3e29 | 17 | ADC_Base adc_(A0, FS_); // for AD |
MikamiUitOpen | 2:7ac5be6f3e29 | 18 | DAC_MCP4922 myDac_; // for DA |
MikamiUitOpen | 0:b0e06f5ed486 | 19 | |
MikamiUitOpen | 0:b0e06f5ed486 | 20 | int main() |
MikamiUitOpen | 0:b0e06f5ed486 | 21 | { |
MikamiUitOpen | 4:17ca341bea00 | 22 | myDac_.ScfClockTim3(500000); // cutoff frequency: 5 kHz |
MikamiUitOpen | 0:b0e06f5ed486 | 23 | |
MikamiUitOpen | 0:b0e06f5ed486 | 24 | float un[ORDER_+1]; |
MikamiUitOpen | 0:b0e06f5ed486 | 25 | for (int n=0; n<=ORDER_; n++) |
MikamiUitOpen | 0:b0e06f5ed486 | 26 | un[n] = 0; |
MikamiUitOpen | 0:b0e06f5ed486 | 27 | |
MikamiUitOpen | 0:b0e06f5ed486 | 28 | while (true) |
MikamiUitOpen | 0:b0e06f5ed486 | 29 | { |
MikamiUitOpen | 0:b0e06f5ed486 | 30 | float xn = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:b0e06f5ed486 | 31 | //----------------------------------------------- |
MikamiUitOpen | 0:b0e06f5ed486 | 32 | |
MikamiUitOpen | 0:b0e06f5ed486 | 33 | for (int k=0; k<ORDER_; k++) |
MikamiUitOpen | 0:b0e06f5ed486 | 34 | un[k] = hm_[k]*xn + un[k+1]; |
MikamiUitOpen | 0:b0e06f5ed486 | 35 | un[ORDER_] = hm_[ORDER_]*xn; |
MikamiUitOpen | 0:b0e06f5ed486 | 36 | |
MikamiUitOpen | 0:b0e06f5ed486 | 37 | //----------------------------------------------- |
MikamiUitOpen | 0:b0e06f5ed486 | 38 | myDac_.Write(un[0]); // Write to DAC |
MikamiUitOpen | 0:b0e06f5ed486 | 39 | } |
MikamiUitOpen | 0:b0e06f5ed486 | 40 | } |