![](/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@7:442b02fbb2f9, 2014-10-30 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Thu Oct 30 00:26:30 2014 +0000
- Revision:
- 7:442b02fbb2f9
- Parent:
- 6:82cc56bd6307
- Child:
- 8:94fb54f0c9f6
8
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 | 7:442b02fbb2f9 | 5 | // 2014/10/30, 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 | #include "ScfClockTim3.hpp" // for clock supplied to SCF |
MikamiUitOpen | 0:00e1dcdfaaad | 13 | |
MikamiUitOpen | 0:00e1dcdfaaad | 14 | using namespace Mikami; |
MikamiUitOpen | 0:00e1dcdfaaad | 15 | |
MikamiUitOpen | 1:e5e7a45f0cd6 | 16 | const int FS_ = 10000; // Sampling frequency: 10 kHz |
MikamiUitOpen | 5:aa0810bc0a76 | 17 | ADC_Intr adc_(A0, FS_); // for AD |
MikamiUitOpen | 3:4d766c291dba | 18 | DAC_MCP4922 myDac_; // for DA |
MikamiUitOpen | 0:00e1dcdfaaad | 19 | |
MikamiUitOpen | 0:00e1dcdfaaad | 20 | // Interrupt service routine for ADC |
MikamiUitOpen | 0:00e1dcdfaaad | 21 | void AdcIsr() |
MikamiUitOpen | 0:00e1dcdfaaad | 22 | { |
MikamiUitOpen | 0:00e1dcdfaaad | 23 | float xn = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:00e1dcdfaaad | 24 | myDac_.Write(xn); // to DAC |
MikamiUitOpen | 0:00e1dcdfaaad | 25 | } |
MikamiUitOpen | 0:00e1dcdfaaad | 26 | |
MikamiUitOpen | 0:00e1dcdfaaad | 27 | int main() |
MikamiUitOpen | 0:00e1dcdfaaad | 28 | { |
MikamiUitOpen | 0:00e1dcdfaaad | 29 | ScfClockTim3(420000); // cutoff frequency: 4.2 kHz |
MikamiUitOpen | 0:00e1dcdfaaad | 30 | adc_.SetIntrVec(AdcIsr); // Assign ISR for ADC interrupt |
MikamiUitOpen | 0:00e1dcdfaaad | 31 | |
MikamiUitOpen | 0:00e1dcdfaaad | 32 | while (true) {} |
MikamiUitOpen | 0:00e1dcdfaaad | 33 | } |