AmpController Class Test

Dependencies:   Amp Envelope mbed-rtos mbed

Committer:
ryood
Date:
Sun Jun 26 06:28:04 2016 +0000
Revision:
2:fbc776fc8e12
Parent:
0:e8cd21a7412a
vref?0x0fff???

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryood 0:e8cd21a7412a 1 /*
ryood 0:e8cd21a7412a 2 * EnvelopeをMCP4922に出力するテスト
ryood 0:e8cd21a7412a 3 *
ryood 0:e8cd21a7412a 4 * 2016.06.23
ryood 0:e8cd21a7412a 5 *
ryood 0:e8cd21a7412a 6 */
ryood 0:e8cd21a7412a 7
ryood 0:e8cd21a7412a 8 #include "mbed.h"
ryood 0:e8cd21a7412a 9 #include "rtos.h"
ryood 0:e8cd21a7412a 10 #include "Envelope.h"
ryood 0:e8cd21a7412a 11 #include "SpiAmpController.h"
ryood 0:e8cd21a7412a 12
ryood 0:e8cd21a7412a 13 #define AMP_VREF 0x0fff
ryood 0:e8cd21a7412a 14 #define SPIM_RATE 1000000
ryood 0:e8cd21a7412a 15
ryood 0:e8cd21a7412a 16 const int envLength = 25;
ryood 0:e8cd21a7412a 17
ryood 0:e8cd21a7412a 18 AnalogIn levelIn(A0);
ryood 0:e8cd21a7412a 19 AnalogIn durationIn(A1);
ryood 0:e8cd21a7412a 20 AnalogIn decayIn(A2);
ryood 0:e8cd21a7412a 21 AnalogIn sustainIn(A3);
ryood 0:e8cd21a7412a 22
ryood 0:e8cd21a7412a 23 SPI spiM(SPI_MOSI, SPI_MISO, SPI_SCK);
ryood 0:e8cd21a7412a 24
ryood 0:e8cd21a7412a 25 int main()
ryood 0:e8cd21a7412a 26 {
ryood 0:e8cd21a7412a 27 spiM.format(8, 0);
ryood 0:e8cd21a7412a 28 spiM.frequency(SPIM_RATE);
ryood 0:e8cd21a7412a 29
ryood 0:e8cd21a7412a 30 // Envelope(level, length, duration, decay, sustain)
ryood 0:e8cd21a7412a 31 Envelope envelope(4095, envLength, envLength*3/4, envLength/2, 2047);
ryood 0:e8cd21a7412a 32 SpiAmpController ampController(&spiM, D8, D7);
ryood 0:e8cd21a7412a 33 ampController.setVref(AMP_VREF);
ryood 0:e8cd21a7412a 34
ryood 0:e8cd21a7412a 35 printf("\r\n\n*** Amp Controller Test ***\r\n");
ryood 0:e8cd21a7412a 36 envelope.init();
ryood 0:e8cd21a7412a 37 int cnt = 0;
ryood 2:fbc776fc8e12 38 //int vref = 0;
ryood 2:fbc776fc8e12 39 int vref=0x0fff;
ryood 0:e8cd21a7412a 40 while (true) {
ryood 0:e8cd21a7412a 41 ampController.outDca(envelope.getModLevel());
ryood 0:e8cd21a7412a 42 envelope.update();
ryood 0:e8cd21a7412a 43
ryood 0:e8cd21a7412a 44 cnt++;
ryood 0:e8cd21a7412a 45 if (cnt == envLength) {
ryood 0:e8cd21a7412a 46 cnt = 0;
ryood 0:e8cd21a7412a 47 envelope.setLevel(levelIn * 4095);
ryood 0:e8cd21a7412a 48 envelope.setDuration(durationIn * envLength);
ryood 0:e8cd21a7412a 49 envelope.setDecay(decayIn * envLength);
ryood 0:e8cd21a7412a 50 envelope.setSustain(sustainIn * 4095);
ryood 0:e8cd21a7412a 51
ryood 0:e8cd21a7412a 52 /*
ryood 0:e8cd21a7412a 53 printf("%d\t%d\t%d\t%d\t%d\t\r\n",
ryood 0:e8cd21a7412a 54 envelope.getLevel(), envelope.getLength(), envelope.getDuration(), envelope.getDecay(), envelope.getSustain());
ryood 0:e8cd21a7412a 55 */
ryood 0:e8cd21a7412a 56 envelope.init();
ryood 0:e8cd21a7412a 57 ampController.setVref(vref);
ryood 2:fbc776fc8e12 58 //vref += 0x10;
ryood 0:e8cd21a7412a 59 if (vref > 0x0fff) {
ryood 0:e8cd21a7412a 60 vref = 0;
ryood 0:e8cd21a7412a 61 }
ryood 0:e8cd21a7412a 62 }
ryood 0:e8cd21a7412a 63 Thread::wait(5);
ryood 0:e8cd21a7412a 64 }
ryood 0:e8cd21a7412a 65 }