KIK01 Prototype 04

Dependencies:   mbed-rtos mbed mcp3008

Fork of KIK01_Proto03 by Ryo Od

Files at this revision

API Documentation at this revision

Comitter:
ryood
Date:
Sun Sep 17 23:24:49 2017 +0000
Parent:
22:a3bb7594f9bb
Commit message:
Impl. Amplitude Envelope.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r a3bb7594f9bb -r da7c5f7feff1 main.cpp
--- a/main.cpp	Sun Sep 17 19:11:41 2017 +0000
+++ b/main.cpp	Sun Sep 17 23:24:49 2017 +0000
@@ -23,7 +23,7 @@
 
 #define MCP3008_SPI_SPEED       (1000000)
 #define AD8402_SPI_SPEED        (10000000)
-#define ENVELOPE_UPDATE_RATE    (20000)  //  Hz
+#define ENVELOPE_UPDATE_RATE    (32000)  //  Hz
 
 #define AD8402_RMAX (10000.0f)
 #define AD8402_RMIN (50.0f)
@@ -78,10 +78,8 @@
 #endif
 }
 
-void DcoSetFrequency()
+void DcoSetFrequency(float freq)
 {
-    frequency = envelopeFrequency.getAmplitude(ticks);
-    
     const float c = 0.00000047;
     float r = 1.0f / (2.0f * PI_F * frequency * c);
     if (r < AD8402_RMIN) r = AD8402_RMIN;
@@ -91,7 +89,11 @@
 
     AD8402Write(0, v);
     AD8402Write(1, v);
+}
 
+void DcaSetAmplitude(float amp)
+{
+    Dac1.write(amp);
 }
 
 void update()
@@ -122,7 +124,11 @@
     envelopeFrequency.setAttackTauRatio(frequencyParam.attackTauRatio);
     envelopeFrequency.setReleaseTauRatio(frequencyParam.releaseTauRatio);
 
-    DcoSetFrequency();
+    frequency = envelopeFrequency.getAmplitude(ticks);
+    amplitude = envelopeAmplitude.getAmplitude(ticks); 
+    
+    DcoSetFrequency(frequency);
+    DcaSetAmplitude(amplitude);
 
     ticks++;
     if (ticks >= envelopeLength) {