MCP3008 Version

Dependencies:   mbed-rtos mbed mcp3008

Fork of KIK01_Proto01 by Ryo Od

Files at this revision

API Documentation at this revision

Comitter:
ryood
Date:
Wed Jun 21 00:14:49 2017 +0000
Parent:
12:5b498285d121
Commit message:
MCP3008

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mcp3008.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 5b498285d121 -r 43a43da257e3 main.cpp
--- a/main.cpp	Tue Jun 06 15:31:41 2017 +0000
+++ b/main.cpp	Wed Jun 21 00:14:49 2017 +0000
@@ -2,41 +2,34 @@
  * KIK01
  * Kick Machine
  *
+ * 2017.06.19 Proto02
  * 2017.06.04 created.
  *
  */
 
 #include "mbed.h"
 #include "rtos.h"
+#include "mcp3008.h"
 
 #define UART_TRACE      (1)
 #define PIN_CHECK       (1)
 #define TITLE_STR1      ("KIK01 Kick Machine")
-#define TITLE_STR2      ("20170606")
+#define TITLE_STR2      ("20170621")
 
 #define PI_F            (3.1415926f)
-#define SAMPLING_RATE   (96000)
+#define SAMPLING_RATE   (48000)
 #define SAMPLING_PERIOD (1.0f/SAMPLING_RATE)
-#define ENVELOPE_UPDATE_RATE    (32000)
-
-AnalogOut Dac1(PA_5);
+#define ENVELOPE_UPDATE_RATE    (48000)
 
-AnalogIn Ain0(PA_0);
-AnalogIn Ain1(PA_1);
-AnalogIn Ain2(PA_4);
-AnalogIn Ain3(PB_0);
-AnalogIn Ain4(PC_1);
-AnalogIn Ain5(PC_0);
-AnalogIn Ain6(PC_2);
-AnalogIn Ain7(PC_3);
+AnalogOut Dac1(PA_4);
 
-AnalogIn Ain8(PC_4);
-AnalogIn Ain9(PB_1);
-AnalogIn Ain10(PC_5);
-AnalogIn Ain11(PA_6);
+SPI spiM(SPI_MOSI, SPI_MISO, SPI_SCK);
+MCP3008 Adc0(spiM, D9);
+MCP3008 Adc1(spiM, D10);
 
 DigitalOut Dout0(PA_10);
 DigitalOut Dout1(PB_3);
+DigitalOut Dout2(PB_5);
 
 class EnvelopeAR
 {
@@ -239,30 +232,30 @@
 
 void setParams()
 {
-    bpm = Ain0.read() * 180.0f + 60.0f;
+    bpm = Adc0.read_input(7) * 180.0f + 60.0f;
     envelopeLength = 60 * ENVELOPE_UPDATE_RATE / bpm;
 
-    amplitudeParam.attack = Ain1.read() * envelopeLength;
-    amplitudeParam.release = Ain2.read() * envelopeLength;
-    amplitudeParam.v0 = Ain3.read();
+    amplitudeParam.attack = Adc0.read_input(0) * envelopeLength;
+    amplitudeParam.release = Adc0.read_input(1) * envelopeLength;
+    amplitudeParam.v0 = Adc0.read_input(4);
     amplitudeParam.v1 = 1.0f;
     amplitudeParam.v2 = 0.0f;
     amplitudeParam.attackTauRatio = 0.36f;
-    amplitudeParam.releaseTauRatio = Ain4.read() + 0.01f;
+    amplitudeParam.releaseTauRatio = Adc0.read_input(3) + 0.01f;
 
-    frequencyParam.attack = Ain8.read() * envelopeLength * 0.1f;
-    frequencyParam.release = Ain11.read() * envelopeLength + 1;
-    frequencyParam.v0 = Ain5.read() * 4000.0f;
-    frequencyParam.v1 = Ain6.read() * 400.0f;
-    frequencyParam.v2 = Ain7.read() * 400.0f;
-    frequencyParam.attackTauRatio = Ain9.read() + 0.01f;
-    frequencyParam.releaseTauRatio = Ain10.read() + 0.01f;
+    frequencyParam.attack = Adc1.read_input(0) * envelopeLength * 0.1f;
+    frequencyParam.release = Adc1.read_input(1) * envelopeLength + 1;
+    frequencyParam.v0 = Adc1.read_input(4) * 4000.0f;
+    frequencyParam.v1 = Adc1.read_input(5) * 400.0f;
+    frequencyParam.v2 = Adc1.read_input(6) * 400.0f;
+    frequencyParam.attackTauRatio = Adc1.read_input(2) + 0.01f;
+    frequencyParam.releaseTauRatio = Adc1.read_input(3) + 0.01f;
 }
 
 int main()
 {
     printf("%s %s\r\n", TITLE_STR1, TITLE_STR2);
-
+    
     frequency = 1000.0f;
     phiDelta = 2.0f * frequency / SAMPLING_RATE;
     amplitude = 1.0f;
@@ -277,7 +270,13 @@
     samplingTicker.attach(&update, SAMPLING_PERIOD);
 
     for (;;) {
+#if (PIN_CHECK)
+        Dout2 = 1;
+#endif        
         setParams();
+#if (PIN_CHECK)
+        Dout2 = 0;
+#endif        
 
 #if UART_TRACE
         printf("%.1f\t%d\t", bpm, envelopeLength);
@@ -291,6 +290,6 @@
         printf("%.2f\t%.2f\r\n", frequencyParam.attackTauRatio, frequencyParam.releaseTauRatio);
 #endif
 
-        Thread::wait(100);
+        Thread::wait(1);
     }
 }
diff -r 5b498285d121 -r 43a43da257e3 mbed.bld
--- a/mbed.bld	Tue Jun 06 15:31:41 2017 +0000
+++ b/mbed.bld	Wed Jun 21 00:14:49 2017 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/mbed_official/code/mbed/builds/86740a56073b
\ No newline at end of file
+https://mbed.org/users/mbed_official/code/mbed/builds/0f02307a0877
\ No newline at end of file
diff -r 5b498285d121 -r 43a43da257e3 mcp3008.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mcp3008.lib	Wed Jun 21 00:14:49 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/ryood/code/mcp3008/#96130c28149e