KIK01 Proto 08

Dependencies:   AverageMCP3008 VoltageMonitor mbed-rtos mbed mcp3008

Fork of KIK01_Proto07 by Ryo Od

Revision:
35:05798de92fb5
Parent:
34:0ef840ff8f74
Child:
36:3543a352b9d4
--- a/main.cpp	Mon Dec 11 12:19:26 2017 +0000
+++ b/main.cpp	Wed Dec 20 19:53:57 2017 +0000
@@ -2,6 +2,7 @@
  * KIK01
  * Kick Machine
  *
+ * 2017.12.15 Proto08: LEDs
  * 2017.12.03 Proto07: SyncIn
  * 2017.11.29 Proto06: Add Power Monitor
  * 2017.10.19 Proto05: Add NOS01 Controller
@@ -22,12 +23,12 @@
 #include "VoltageMonitor.h"
 
 #define PIN_CHECK       (1)
-#define TITLE_STR1      ("KIK01 Kick Machine")
-#define TITLE_STR2      ("20171211")
+#define TITLE_STR1      ("KIK01 Kick Machine Proto08")
+#define TITLE_STR2      ("20171221")
 
 #define PI_F            (3.1415926f)
 
-#define MCP3008_SPI_SPEED       (1312500)
+#define MCP3008_SPI_SPEED       (1406250)
 #define AD8402_SPI_SPEED        (10000000)
 #define ENVELOPE_UPDATE_RATE    (32000)  //  Hz
 
@@ -37,16 +38,24 @@
 #define AVERAGE_BUFFER_SIZE (4)
 
 #define PM_VDD           (3.32f)
-#define PM_LoThreshold   (2.375f)
-#define PM_HiThreshold   (2.625f)
+#define PM_LoThreshold   (2.3f)
+#define PM_HiThreshold   (2.7f)
 
+// LEDs
+DigitalOut LedPower(PC_5);
+DigitalOut LedBeat(PA_12);
+DigitalOut LedSyncIn(PA_11);
+DigitalOut LedSyncOut(PB_12);
+
+
+// Envelope Output
 AnalogOut Dac1(PA_4);
 AnalogOut Dac2(PA_5);
 
 // 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);
+DigitalOut AD8402Cs(PC_4, 1);   // Initaially Inactive
 
 // MCP3008 SPI
 // SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
@@ -60,9 +69,7 @@
 
 // Power Monitor
 AnalogIn PowerMonitorIn(PA_0);
-DigitalOut PowerMonitorLed(PA_15);
-VoltageMonitor PWMon(&PowerMonitorIn, PM_VDD, PM_LoThreshold, PM_HiThreshold, &PowerMonitorLed);
-//VoltageMonitor PWMon(&PowerMonitorIn, PM_VDD, PM_LoThreshold, PM_HiThreshold, NULL);
+VoltageMonitor PWMon(&PowerMonitorIn, PM_VDD, PM_LoThreshold, PM_HiThreshold, &LedPower);
 
 // Sync
 DigitalOut SyncOut(PC_10);
@@ -144,6 +151,7 @@
     // Output Sync Signal per steps
     if (ticks % stepLength == 0) {
         SyncOut = 1;
+        LedSyncOut = !LedSyncOut;
     }
 
     // set envelope parameters
@@ -162,6 +170,7 @@
     ticks++;
     if (ticks >= envelopeLength) {
         ticks = 0;
+        LedBeat = !LedBeat;
     }
 
     // Output SyncSignal
@@ -203,10 +212,26 @@
     noiseAmplitudeParam.releaseTauRatio = AvgAdc3.read_input(3) + 0.01f;
 }
 
-void syncFunction()
+void syncInFunction()
 {
     ticks = 0;
-    //PowerMonitorLed = !PowerMonitorLed;
+    LedSyncIn = !LedSyncIn;
+}
+
+void LedsCheck(int n, int wait)
+{
+    for (int i = 0; i < n; i++) {
+        //LedPower = 1;
+        LedBeat = 1;
+        LedSyncIn = 1;
+        LedSyncOut = 1;
+        Thread::wait(wait);
+        //LedPower = 0;
+        LedBeat = 0;
+        LedSyncIn = 0;
+        LedSyncOut = 0;
+        Thread::wait(wait);
+    }
 }
 
 int main()
@@ -215,6 +240,9 @@
     printf("\r\n\n%s %s\r\n", TITLE_STR1, TITLE_STR2);
 #endif
 
+    // LEDs Check
+    LedsCheck(4, 100);  // 4 counts, 100ms cycle
+
     SpiMAD8402.format(8, 0);
     SpiMAD8402.frequency(AD8402_SPI_SPEED);
 
@@ -233,7 +261,8 @@
     samplingTicker.attach(&update, (1.0f/ENVELOPE_UPDATE_RATE));
     
     // Sync Interrupt
-    SyncIn.rise(&syncFunction);
+    SyncIn.rise(&syncInFunction);
+    SyncIn.mode(PullDown);
 
     for (;;) {
 #if (PIN_CHECK)