![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
main.cpp@0:53e66485c864, 2011-05-01 (annotated)
- Committer:
- faker
- Date:
- Sun May 01 12:34:33 2011 +0000
- Revision:
- 0:53e66485c864
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
faker | 0:53e66485c864 | 1 | /*****************************************************/ |
faker | 0:53e66485c864 | 2 | /* MBED MULTI EFFECTOR */ |
faker | 0:53e66485c864 | 3 | /* */ |
faker | 0:53e66485c864 | 4 | /* */ |
faker | 0:53e66485c864 | 5 | /*****************************************************/ |
faker | 0:53e66485c864 | 6 | |
faker | 0:53e66485c864 | 7 | #include "mbed.h" |
faker | 0:53e66485c864 | 8 | #include "Distotion_Unit.h" |
faker | 0:53e66485c864 | 9 | |
faker | 0:53e66485c864 | 10 | Ticker sampling; |
faker | 0:53e66485c864 | 11 | AnalogIn Ain(p17); |
faker | 0:53e66485c864 | 12 | AnalogOut Aout(p18); |
faker | 0:53e66485c864 | 13 | |
faker | 0:53e66485c864 | 14 | /*******************************/ |
faker | 0:53e66485c864 | 15 | /* For Test Signal */ |
faker | 0:53e66485c864 | 16 | /*******************************/ |
faker | 0:53e66485c864 | 17 | #define TEST_SIGNAL_ENABLE (0) // 1 : Internal SinWave for Debug |
faker | 0:53e66485c864 | 18 | #define TEST_SIGNAL_FREQ (1000.0) // Frequency [Hz] |
faker | 0:53e66485c864 | 19 | #define TEST_SIGNAL_AMP (30000.0) // Amplitude |
faker | 0:53e66485c864 | 20 | #define PAI (3.14159) |
faker | 0:53e66485c864 | 21 | |
faker | 0:53e66485c864 | 22 | /*******************************/ |
faker | 0:53e66485c864 | 23 | /* For ADC & DAC Setting */ |
faker | 0:53e66485c864 | 24 | /*******************************/ |
faker | 0:53e66485c864 | 25 | #define SAMPLING_TIME (25.0) // ADC Sampling Rate [us] |
faker | 0:53e66485c864 | 26 | |
faker | 0:53e66485c864 | 27 | volatile unsigned int *g_usiAd0cr, *g_usiAd0dr2; // ADC Reg |
faker | 0:53e66485c864 | 28 | unsigned int *g_usiDacr; // DAC Reg |
faker | 0:53e66485c864 | 29 | unsigned int g_usiFinalOut; |
faker | 0:53e66485c864 | 30 | int g_ssBuff[10]; |
faker | 0:53e66485c864 | 31 | float g_fTestWaveT; |
faker | 0:53e66485c864 | 32 | |
faker | 0:53e66485c864 | 33 | /*******************************/ |
faker | 0:53e66485c864 | 34 | /* Effect Process */ |
faker | 0:53e66485c864 | 35 | /*******************************/ |
faker | 0:53e66485c864 | 36 | void effectProcess() { |
faker | 0:53e66485c864 | 37 | // Line Out |
faker | 0:53e66485c864 | 38 | *g_usiDacr = g_usiFinalOut; |
faker | 0:53e66485c864 | 39 | // ADC Start |
faker | 0:53e66485c864 | 40 | *g_usiAd0cr = 0x01200204; |
faker | 0:53e66485c864 | 41 | |
faker | 0:53e66485c864 | 42 | #if (TEST_SIGNAL_ENABLE == 1) // Test Signal Sin Wave |
faker | 0:53e66485c864 | 43 | g_ssBuff[0] = TEST_SIGNAL_AMP * sin(g_fTestWaveT); |
faker | 0:53e66485c864 | 44 | g_fTestWaveT = g_fTestWaveT + 2.0 * PAI * SAMPLING_TIME * TEST_SIGNAL_FREQ / 1e6; |
faker | 0:53e66485c864 | 45 | if (g_fTestWaveT >= (2.0 * PAI))g_fTestWaveT = 0; |
faker | 0:53e66485c864 | 46 | #endif |
faker | 0:53e66485c864 | 47 | |
faker | 0:53e66485c864 | 48 | // |
faker | 0:53e66485c864 | 49 | // Effect Func(); |
faker | 0:53e66485c864 | 50 | // |
faker | 0:53e66485c864 | 51 | g_ssBuff[1] = distotion(g_ssBuff[0]); |
faker | 0:53e66485c864 | 52 | // |
faker | 0:53e66485c864 | 53 | // Effect Func(); |
faker | 0:53e66485c864 | 54 | // |
faker | 0:53e66485c864 | 55 | |
faker | 0:53e66485c864 | 56 | #if (TEST_SIGNAL_ENABLE == 0) |
faker | 0:53e66485c864 | 57 | while (1) { |
faker | 0:53e66485c864 | 58 | if ((*g_usiAd0dr2 & 0x80000000) != 0)break; // ADC Done ? |
faker | 0:53e66485c864 | 59 | } |
faker | 0:53e66485c864 | 60 | g_ssBuff[0] = (int)(*g_usiAd0dr2 & 0x0000FFF0) - 32768; |
faker | 0:53e66485c864 | 61 | #endif |
faker | 0:53e66485c864 | 62 | |
faker | 0:53e66485c864 | 63 | g_usiFinalOut = 0x00010000 | (g_ssBuff[1] + 32768); |
faker | 0:53e66485c864 | 64 | } |
faker | 0:53e66485c864 | 65 | |
faker | 0:53e66485c864 | 66 | |
faker | 0:53e66485c864 | 67 | /*******************************/ |
faker | 0:53e66485c864 | 68 | /* MAIN */ |
faker | 0:53e66485c864 | 69 | /*******************************/ |
faker | 0:53e66485c864 | 70 | int main() { |
faker | 0:53e66485c864 | 71 | |
faker | 0:53e66485c864 | 72 | g_usiAd0cr = (unsigned int*)0x40034000; |
faker | 0:53e66485c864 | 73 | g_usiAd0dr2 = (unsigned int*)0x40034018; |
faker | 0:53e66485c864 | 74 | g_usiDacr = (unsigned int*)0x4008C000; |
faker | 0:53e66485c864 | 75 | sampling.attach_us(&effectProcess, SAMPLING_TIME); |
faker | 0:53e66485c864 | 76 | |
faker | 0:53e66485c864 | 77 | while (1) { |
faker | 0:53e66485c864 | 78 | |
faker | 0:53e66485c864 | 79 | // |
faker | 0:53e66485c864 | 80 | // Parameter Setting Func() |
faker | 0:53e66485c864 | 81 | // |
faker | 0:53e66485c864 | 82 | |
faker | 0:53e66485c864 | 83 | } |
faker | 0:53e66485c864 | 84 | } |
faker | 0:53e66485c864 | 85 |