Ryo Od / Mbed 2 deprecated KIK01_Proto06

Dependencies:   AverageMCP3008 VoltageMonitor mbed-rtos mbed mcp3008

Fork of KIK01_Proto05 by Ryo Od

Files at this revision

API Documentation at this revision

Comitter:
ryood
Date:
Fri Dec 01 10:38:26 2017 +0000
Parent:
31:3c7e1cd0d947
Commit message:
Add Power Monitor

Changed in this revision

VoltageMonitor.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VoltageMonitor.lib	Fri Dec 01 10:38:26 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/ryood/code/VoltageMonitor/#ada48e929184
--- a/main.cpp	Sat Oct 21 03:50:56 2017 +0000
+++ b/main.cpp	Fri Dec 01 10:38:26 2017 +0000
@@ -2,6 +2,7 @@
  * KIK01
  * Kick Machine
  *
+ * 2017.11.29 Proto06: Add Power Monitor
  * 2017.10.19 Proto05: Add NOS01 Controller
  * 2017.09.16 Proto04: SPI1 for AD8402 Wein Bridge DCO & Internal DAC for Dual-OTA-VCA
  * 2017.07.04 Proto03: MCP4922 DCA
@@ -17,9 +18,11 @@
 #include "EnvelopeAR.h"
 
 #define UART_TRACE      (1)
+#include "VoltageMonitor.h"
+
 #define PIN_CHECK       (1)
 #define TITLE_STR1      ("KIK01 Kick Machine")
-#define TITLE_STR2      ("20171020")
+#define TITLE_STR2      ("20171129")
 
 #define PI_F            (3.1415926f)
 
@@ -32,6 +35,10 @@
 
 #define AVERAGE_BUFFER_SIZE (4)
 
+#define PM_VDD           (3.32f)
+#define PM_LoThreshold   (2.375f)
+#define PM_HiThreshold   (2.625f)
+
 AnalogOut Dac1(PA_4);
 AnalogOut Dac2(PA_5);
 
@@ -43,12 +50,17 @@
 // MCP3008 SPI
 // SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
 SPI SpiMAdc(PB_5, PB_4, PB_3);
-MCP3008 Adc1(&SpiMAdc, PB_10);
+MCP3008 Adc1(&SpiMAdc, PA_9);
 MCP3008 Adc2(&SpiMAdc, PA_8);
-MCP3008 Adc3(&SpiMAdc, PA_9);
+MCP3008 Adc3(&SpiMAdc, PB_10);
 AverageMCP3008 AvgAdc1(&Adc1, AVERAGE_BUFFER_SIZE); 
 AverageMCP3008 AvgAdc2(&Adc2, AVERAGE_BUFFER_SIZE); 
-AverageMCP3008 AvgAdc3(&Adc3, AVERAGE_BUFFER_SIZE); 
+AverageMCP3008 AvgAdc3(&Adc3, AVERAGE_BUFFER_SIZE);
+
+// Power Monitor
+AnalogIn PowerMonitorIn(PA_0);
+DigitalOut PowerMonitorLed(PA_15);
+VoltageMonitor PWMon(&PowerMonitorIn, PM_VDD, PM_LoThreshold, PM_HiThreshold, &PowerMonitorLed);
 
 // Sync
 DigitalOut SyncPin(PA_10);
@@ -221,6 +233,7 @@
         Dout3 = 0;
 #endif
 
+
 #if UART_TRACE
         printf("%.1f\t%d\t", bpm, envelopeLength);
 
@@ -234,9 +247,11 @@
         
         printf("| %d\t%d\t", noiseAmplitudeParam.attack, noiseAmplitudeParam.release);
         printf("%.2f\t%.2f\t%.2f\t", noiseAmplitudeParam.v0, noiseAmplitudeParam.v1, noiseAmplitudeParam.v2);
-        printf("%.2f\t%.2f\r\n", noiseAmplitudeParam.attackTauRatio, noiseAmplitudeParam.releaseTauRatio);
+        printf("%.2f\t%.2f\t", noiseAmplitudeParam.attackTauRatio, noiseAmplitudeParam.releaseTauRatio);
 #endif
 
+        PWMon.check();
+
         Thread::wait(1);
     }
 }