![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Two-phase sinusoidal wave generator using digital filter for ST Nucleo F401RE.
main.cpp@4:937488128696, 2015-02-02 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Feb 02 08:18:43 2015 +0000
- Revision:
- 4:937488128696
- Parent:
- 2:9a42515e6e21
5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:5b53b74d1fb7 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:5b53b74d1fb7 | 2 | // Two-phase sinusoidal wave generator |
MikamiUitOpen | 4:937488128696 | 3 | // 2015/02/02, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 0:5b53b74d1fb7 | 4 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:5b53b74d1fb7 | 5 | |
MikamiUitOpen | 0:5b53b74d1fb7 | 6 | #include "mbed.h" |
MikamiUitOpen | 0:5b53b74d1fb7 | 7 | |
MikamiUitOpen | 0:5b53b74d1fb7 | 8 | #include "ADC_Base.hpp" // for ADC not using interrupt |
MikamiUitOpen | 0:5b53b74d1fb7 | 9 | #include "DAC_MCP4922Dual.hpp" // for DAC MCP4922 |
MikamiUitOpen | 0:5b53b74d1fb7 | 10 | |
MikamiUitOpen | 0:5b53b74d1fb7 | 11 | #include "TwoPhaseGenerator.hpp" // Two-phase generator |
MikamiUitOpen | 0:5b53b74d1fb7 | 12 | |
MikamiUitOpen | 0:5b53b74d1fb7 | 13 | using namespace Mikami; |
MikamiUitOpen | 0:5b53b74d1fb7 | 14 | |
MikamiUitOpen | 0:5b53b74d1fb7 | 15 | const int FS_ = 12000; // 12 kHz |
MikamiUitOpen | 0:5b53b74d1fb7 | 16 | ADC_Base adc_(A0, FS_); |
MikamiUitOpen | 0:5b53b74d1fb7 | 17 | DAC_MCP4922Dual myDac_; |
MikamiUitOpen | 0:5b53b74d1fb7 | 18 | |
MikamiUitOpen | 0:5b53b74d1fb7 | 19 | int main() |
MikamiUitOpen | 0:5b53b74d1fb7 | 20 | { |
MikamiUitOpen | 4:937488128696 | 21 | TwoPhaseGenerator gen(1500, (float)FS_); |
MikamiUitOpen | 0:5b53b74d1fb7 | 22 | while (true) |
MikamiUitOpen | 0:5b53b74d1fb7 | 23 | { |
MikamiUitOpen | 0:5b53b74d1fb7 | 24 | float xn = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:5b53b74d1fb7 | 25 | //----------------------------------------------- |
MikamiUitOpen | 0:5b53b74d1fb7 | 26 | |
MikamiUitOpen | 0:5b53b74d1fb7 | 27 | float cos, sin; |
MikamiUitOpen | 0:5b53b74d1fb7 | 28 | gen.Generate(cos, sin); |
MikamiUitOpen | 0:5b53b74d1fb7 | 29 | |
MikamiUitOpen | 0:5b53b74d1fb7 | 30 | //----------------------------------------------- |
MikamiUitOpen | 0:5b53b74d1fb7 | 31 | myDac_.Write(cos, sin); // Write to DAC |
MikamiUitOpen | 0:5b53b74d1fb7 | 32 | } |
MikamiUitOpen | 0:5b53b74d1fb7 | 33 | } |