![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Prototype program of AD and DA using classes in UIT_ADDA. This program uses interrupt of ADC for ST Nucleo F401RE. UIT_ADDA のクラスを使った AD および DA のためのプログラムの雛形.ADC の割り込みを使うバージョン.ST Nucleo F401 用.
main.cpp@16:176629901288, 2016-11-11 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Fri Nov 11 02:50:27 2016 +0000
- Revision:
- 16:176629901288
- Parent:
- 13:278ffde769f7
17
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:00e1dcdfaaad | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:00e1dcdfaaad | 2 | // 割り込みを使って AD DA を行う場合の雛形1(入力:1 チャンネル) |
MikamiUitOpen | 0:00e1dcdfaaad | 3 | // Analog Input : A0 |
MikamiUitOpen | 0:00e1dcdfaaad | 4 | // Analog Output: MCP4922 using SPI |
MikamiUitOpen | 13:278ffde769f7 | 5 | // 2014/12/19, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:00e1dcdfaaad | 6 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:00e1dcdfaaad | 7 | |
MikamiUitOpen | 0:00e1dcdfaaad | 8 | #include "mbed.h" |
MikamiUitOpen | 0:00e1dcdfaaad | 9 | |
MikamiUitOpen | 0:00e1dcdfaaad | 10 | #include "ADC_Interrupt.hpp" // for ADC using interrupt |
MikamiUitOpen | 0:00e1dcdfaaad | 11 | #include "DAC_MCP4922.hpp" // for DAC MCP4922 |
MikamiUitOpen | 0:00e1dcdfaaad | 12 | |
MikamiUitOpen | 0:00e1dcdfaaad | 13 | using namespace Mikami; |
MikamiUitOpen | 0:00e1dcdfaaad | 14 | |
MikamiUitOpen | 1:e5e7a45f0cd6 | 15 | const int FS_ = 10000; // Sampling frequency: 10 kHz |
MikamiUitOpen | 5:aa0810bc0a76 | 16 | ADC_Intr adc_(A0, FS_); // for AD |
MikamiUitOpen | 3:4d766c291dba | 17 | DAC_MCP4922 myDac_; // for DA |
MikamiUitOpen | 0:00e1dcdfaaad | 18 | |
MikamiUitOpen | 0:00e1dcdfaaad | 19 | // Interrupt service routine for ADC |
MikamiUitOpen | 0:00e1dcdfaaad | 20 | void AdcIsr() |
MikamiUitOpen | 0:00e1dcdfaaad | 21 | { |
MikamiUitOpen | 0:00e1dcdfaaad | 22 | float xn = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:00e1dcdfaaad | 23 | myDac_.Write(xn); // to DAC |
MikamiUitOpen | 0:00e1dcdfaaad | 24 | } |
MikamiUitOpen | 0:00e1dcdfaaad | 25 | |
MikamiUitOpen | 0:00e1dcdfaaad | 26 | int main() |
MikamiUitOpen | 0:00e1dcdfaaad | 27 | { |
MikamiUitOpen | 8:94fb54f0c9f6 | 28 | myDac_.ScfClockTim3(420000); // cutoff frequency: 4.2 kHz |
MikamiUitOpen | 8:94fb54f0c9f6 | 29 | adc_.SetIntrVec(AdcIsr); // Assign ISR for ADC interrupt |
MikamiUitOpen | 0:00e1dcdfaaad | 30 | |
MikamiUitOpen | 0:00e1dcdfaaad | 31 | while (true) {} |
MikamiUitOpen | 0:00e1dcdfaaad | 32 | } |