KIK01 Release

Dependencies:   mcp3008 mbed mbed-rtos AverageMCP3008 VoltageMonitor

Revision:
20:70a05941db8c
Parent:
19:d9e4c66cb49b
Child:
21:a527f51381d6
--- a/main.cpp	Sat Sep 16 00:01:49 2017 +0000
+++ b/main.cpp	Sat Sep 16 00:10:18 2017 +0000
@@ -24,6 +24,9 @@
 #define AD8402_SPI_SPEED        (4000000)
 #define ENVELOPE_UPDATE_RATE    (10000)  //  Hz
 
+#define AD8402_RMAX (10000.0f)
+#define AD8402_RMIN (50.0f)
+
 AnalogOut Dac1(A2);
 
 // AD8402 SPI
@@ -189,9 +192,13 @@
 #endif
 
     frequency = envelopeFrequency.getAmplitude(ticks);
+    
     const float c = 0.00000047;
     float r = 1.0f / (2.0f * PI_F * frequency * c);
-    uint8_t v = 256.0f * (r - 50.0f) / 10000.0f;
+    if (r < AD8402_RMIN) r = AD8402_RMIN;
+    if (r > AD8402_RMAX) r = AD8402_RMAX;
+    
+    uint8_t v = 256.0f * (r - AD8402_RMIN) / AD8402_RMAX;
     
     AD8402Write(0, v);
     AD8402Write(1, v);