KIK 01 Prototype 05

Dependencies:   AverageMCP3008 mbed-rtos mbed mcp3008

Fork of KIK01_Proto03 by Ryo Od

Revision:
26:866d672ba446
Parent:
25:b4977c7e0db7
Child:
27:b07a55935230
--- a/main.cpp	Thu Sep 28 02:32:53 2017 +0000
+++ b/main.cpp	Thu Oct 19 06:10:00 2017 +0000
@@ -2,6 +2,7 @@
  * KIK01
  * Kick Machine
  *
+ * 2017.10.19 Proto05: Add Noise Generator Controller
  * 2017.09.16 Proto04: SPI1 for AD8402 Wein Bridge DCO & Internal DAC for Dual-OTA-VCA
  * 2017.07.04 Proto03: MCP4922 DCA
  * 2017.06.19 Proto02
@@ -17,7 +18,7 @@
 #define UART_TRACE      (1)
 #define PIN_CHECK       (1)
 #define TITLE_STR1      ("KIK01 Kick Machine")
-#define TITLE_STR2      ("20170928")
+#define TITLE_STR2      ("20171019")
 
 #define PI_F            (3.1415926f)
 
@@ -28,24 +29,27 @@
 #define AD8402_RMAX (10000.0f)
 #define AD8402_RMIN (50.0f)
 
-AnalogOut Dac1(A2);
+AnalogOut Dac1(PA_4);
 
-// AD8402 SPI
-SPI SpiMAD8402(SPI_MOSI, SPI_MISO, SPI_SCK);
-DigitalOut AD8402Cs(D10);
+// AD8402 SPI (SPI2)
+// SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
+SPI SpiMAD8402(PB_15, PB_14, PB_13);
+DigitalOut AD8402Cs(PC_4);
 
 // MCP3008 SPI
-SPI SpiM3(D4, D5, D3);
-MCP3008 Adc0(&SpiM3, D6);
-MCP3008 Adc1(&SpiM3, D7);
+// SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
+SPI SpiMAdc(PB_5, PB_4, PB_3);
+MCP3008 Adc1(&SpiMAdc, PB_10);
+MCP3008 Adc2(&SpiMAdc, PA_8);
+MCP3008 Adc3(&SpiMAdc, PA_9);
 
 // Sync
-DigitalOut SyncPin(D2);
+DigitalOut SyncPin(PA_10);
 
 // Check pins
-DigitalOut Dout0(D8);
-DigitalOut Dout1(D9);
-DigitalOut Dout2(D14);
+DigitalOut Dout1(PB_9);
+DigitalOut Dout2(PB_8);
+DigitalOut Dout3(PC_9);
 
 EnvelopeAR envelopeFrequency(5, 300, 880.0f, 120.0f, 40.0f, 0.36f, 0.1f);
 EnvelopeAR envelopeAmplitude(50, 200, 0.99f, 1.0f, 0.0f);
@@ -64,7 +68,7 @@
 void AD8402Write(uint8_t address, uint8_t value)
 {
 #if (PIN_CHECK)
-    Dout1 = 1;
+    Dout2 = 1;
 #endif    
 
     AD8402Cs = 0;
@@ -74,7 +78,7 @@
     wait_us(1);
 
 #if (PIN_CHECK)
-    Dout1 = 0;
+    Dout2 = 0;
 #endif
 }
 
@@ -99,7 +103,7 @@
 void update()
 {
 #if (PIN_CHECK)
-    Dout0 = 1;
+    Dout1 = 1;
 #endif
 
     // Output Sync Signal per steps
@@ -126,31 +130,31 @@
     SyncPin = 0;
 
 #if (PIN_CHECK)
-    Dout0 = 0;
+    Dout1 = 0;
 #endif
 }
 
 void readParams()
 {
-    bpm = Adc0.read_input(7) * 180.0f + 60.0f;
+    bpm = Adc1.read_input(7) * 180.0f + 60.0f;
     envelopeLength = 60 * ENVELOPE_UPDATE_RATE / bpm;
     stepLength = envelopeLength / 4;
 
-    amplitudeParam.attack = Adc0.read_input(0) * envelopeLength;
-    amplitudeParam.release = Adc0.read_input(1) * envelopeLength;
-    amplitudeParam.v0 = Adc0.read_input(4);
-    amplitudeParam.v1 = Adc0.read_input(5);
-    amplitudeParam.v2 = Adc0.read_input(6);
-    amplitudeParam.attackTauRatio = Adc0.read_input(2) + 0.01f;
-    amplitudeParam.releaseTauRatio = Adc0.read_input(3) + 0.01f;
+    amplitudeParam.attack = Adc1.read_input(0) * envelopeLength;
+    amplitudeParam.release = Adc1.read_input(1) * envelopeLength;
+    amplitudeParam.v0 = Adc1.read_input(4);
+    amplitudeParam.v1 = Adc1.read_input(5);
+    amplitudeParam.v2 = Adc1.read_input(6);
+    amplitudeParam.attackTauRatio = Adc1.read_input(2) + 0.01f;
+    amplitudeParam.releaseTauRatio = Adc1.read_input(3) + 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;
+    frequencyParam.attack = Adc2.read_input(0) * envelopeLength * 0.1f;
+    frequencyParam.release = Adc2.read_input(1) * envelopeLength + 1;
+    frequencyParam.v0 = Adc2.read_input(4) * 4000.0f;
+    frequencyParam.v1 = Adc2.read_input(5) * 400.0f;
+    frequencyParam.v2 = Adc2.read_input(6) * 400.0f;
+    frequencyParam.attackTauRatio = Adc2.read_input(2) + 0.01f;
+    frequencyParam.releaseTauRatio = Adc2.read_input(3) + 0.01f;
 }
 
 int main()
@@ -160,8 +164,8 @@
     SpiMAD8402.format(8, 0);
     SpiMAD8402.frequency(AD8402_SPI_SPEED);
 
-    SpiM3.format(8, 0);
-    SpiM3.frequency(MCP3008_SPI_SPEED);
+    SpiMAdc.format(8, 0);
+    SpiMAdc.frequency(MCP3008_SPI_SPEED);
 
     frequency = 100.0f;
     amplitude = 1.0f;
@@ -175,13 +179,13 @@
 
     for (;;) {
 #if (PIN_CHECK)
-        Dout2 = 1;
+        Dout3 = 1;
 #endif
 
         readParams();
 
 #if (PIN_CHECK)
-        Dout2 = 0;
+        Dout3 = 0;
 #endif
 
 #if UART_TRACE