![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Prototype program of AD and DA using classes in UIT_ADDA. This program does not use interrupt of ADC. This program also example of exchanging input channel for ST Nucleo F401RE. UIT_ADDA のクラスを使った AD および DA のためのプログラムで,入力の切り替えを行う場合の雛形.ADC の割り込みは使わないバージョン.ST Nucleo F401 用.
Dependencies: UIT_ACM1602NI UIT_ADDA mbed
main.cpp@1:5c7f4c52d797, 2014-11-12 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Wed Nov 12 09:07:10 2014 +0000
- Revision:
- 1:5c7f4c52d797
- Parent:
- 0:473989635348
- Child:
- 3:107eba32fd7f
2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:473989635348 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:473989635348 | 2 | // 割り込みを使わずに AD DA を行う場合の雛形, 入力切替 |
MikamiUitOpen | 0:473989635348 | 3 | // Analog line Input : A0 (channel 1) |
MikamiUitOpen | 0:473989635348 | 4 | // Analog mic. Input : A1 (channel 2) |
MikamiUitOpen | 0:473989635348 | 5 | // Analog Output: MCP4922 using SPI |
MikamiUitOpen | 0:473989635348 | 6 | // Switch : D2 |
MikamiUitOpen | 1:5c7f4c52d797 | 7 | // 2014/11/12, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:473989635348 | 8 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:473989635348 | 9 | |
MikamiUitOpen | 0:473989635348 | 10 | #include "mbed.h" |
MikamiUitOpen | 0:473989635348 | 11 | |
MikamiUitOpen | 0:473989635348 | 12 | #include "ADC_Interrupt.hpp" // for ADC using interrupt |
MikamiUitOpen | 0:473989635348 | 13 | #include "DAC_MCP4922.hpp" // for DAC MCP4922 |
MikamiUitOpen | 0:473989635348 | 14 | #include "ACM1602NI.hpp" // for LCD display |
MikamiUitOpen | 0:473989635348 | 15 | |
MikamiUitOpen | 0:473989635348 | 16 | using namespace Mikami; |
MikamiUitOpen | 0:473989635348 | 17 | |
MikamiUitOpen | 0:473989635348 | 18 | const int FS_ = 10000; // Sampling frequency: 10 kHz |
MikamiUitOpen | 0:473989635348 | 19 | ADC_Base adc_(A0, FS_, A1); // for AD |
MikamiUitOpen | 0:473989635348 | 20 | DAC_MCP4922 myDac_; // for DA |
MikamiUitOpen | 0:473989635348 | 21 | |
MikamiUitOpen | 0:473989635348 | 22 | DigitalIn sw_(D2, PullDown); |
MikamiUitOpen | 0:473989635348 | 23 | |
MikamiUitOpen | 0:473989635348 | 24 | int main() |
MikamiUitOpen | 0:473989635348 | 25 | { |
MikamiUitOpen | 1:5c7f4c52d797 | 26 | myDac_.ScfClockTim3(420000); // cutoff frequency: 4.2 kHz |
MikamiUitOpen | 0:473989635348 | 27 | int swBefore = 0; |
MikamiUitOpen | 0:473989635348 | 28 | |
MikamiUitOpen | 0:473989635348 | 29 | while (true) |
MikamiUitOpen | 0:473989635348 | 30 | { |
MikamiUitOpen | 0:473989635348 | 31 | float xn = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:473989635348 | 32 | //----------------------------------------------- |
MikamiUitOpen | 0:473989635348 | 33 | // Put signal processing program here |
MikamiUitOpen | 0:473989635348 | 34 | //----------------------------------------------- |
MikamiUitOpen | 0:473989635348 | 35 | myDac_.Write(xn); // Write to DAC |
MikamiUitOpen | 0:473989635348 | 36 | |
MikamiUitOpen | 0:473989635348 | 37 | int swNow = sw_.read(); |
MikamiUitOpen | 0:473989635348 | 38 | if (swNow != swBefore) |
MikamiUitOpen | 0:473989635348 | 39 | { |
MikamiUitOpen | 0:473989635348 | 40 | if (swNow == 0) adc_.Select1stChannel(); // line input |
MikamiUitOpen | 0:473989635348 | 41 | else adc_.Select2ndChannel(); // mic. input |
MikamiUitOpen | 0:473989635348 | 42 | swBefore = swNow; |
MikamiUitOpen | 0:473989635348 | 43 | } |
MikamiUitOpen | 0:473989635348 | 44 | } |
MikamiUitOpen | 0:473989635348 | 45 | } |