Tau ReSpeaker Setup V01

Dependencies:   MbedJSONValue mbed

Fork of TAU_ReSpeaker_DSP_Test by Yossi_Students

Files at this revision

API Documentation at this revision

Comitter:
Arkadi
Date:
Thu Jul 12 10:11:20 2018 +0000
Parent:
4:59319802012b
Commit message:
minor changes

Changed in this revision

filters.h 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
--- a/filters.h	Mon Feb 19 15:14:44 2018 +0000
+++ b/filters.h	Thu Jul 12 10:11:20 2018 +0000
@@ -47,12 +47,13 @@
 ///////////////////////////////
 
 // off mode, output vdd/2
-inline void offMode(void){
+inline void offMode(void)
+{
     uint16_t ADCValueOut;
     // set to vdd/2
     ADCValueOut=(uint16_t)((0.0f +1.0f) * Float2ADC);
     // Output value using DAC
-    *(__IO uint32_t *) Dac_Reg  = ADCValueOut; 
+    *(__IO uint32_t *) Dac_Reg  = ADCValueOut;
 }// end off mode
 
 // passthrough function (output equals input)
@@ -92,7 +93,7 @@
     static float CurrInput [MAX_SECTION_NUMBER+1];
     static float LastInput [MAX_SECTION_NUMBER+1];
     static float LLastInput [MAX_SECTION_NUMBER+1];
-    
+
     ////////////////////
     // Read ADC input //
     ////////////////////
@@ -135,7 +136,8 @@
 } // end high pass filter
 
 // highpass filter + trigger mode
-inline void highpassTrig(void){
+inline void highpassTrig(void)
+{
     ///////////////////////////////
     //    filter variables:      //
     ///////////////////////////////
@@ -157,7 +159,10 @@
     static float CurrInput [MAX_SECTION_NUMBER+1];
     static float LastInput [MAX_SECTION_NUMBER+1];
     static float LLastInput [MAX_SECTION_NUMBER+1];
-    
+
+    // trigger variables
+    static bool trigFlag=0; // flag to indicate trigger event
+
     ////////////////////
     // Read ADC input //
     ////////////////////
@@ -181,6 +186,30 @@
 
     ADCFloatFiltered = ADCFloatFiltered * GscaleHP;
 
+    ///////////////////////////////////////////////
+    // Event detection                           //
+    ///////////////////////////////////////////////
+    if (trigFlag) { // event already detected
+        trigDelay--;
+        if (trigDelay == 0) { // pulse pass run out, perform delay and reset variables
+            trigDelay = trigDelaySet; //reset counter for next iteration
+            trigFlag=0;
+            // reset filter
+            for (int ii=1; ii <= NumSectionsHP; ii++) {
+                LLastInput[ii] = 0;
+                LastInput[ii] = 0;
+                CurrInput[ii] = 0;
+                ADCFloatFiltered = 0;
+            }
+            // update dac
+            ADCValueOut=(uint16_t)((ADCFloatFiltered +1.0f) * Float2ADC);
+            *(__IO uint32_t *) Dac_Reg = ADCValueOut;
+            // delay for set time
+            wait_us(trigPause);
+        }
+    } else if (ADCFloatFiltered >= trigTresh) {
+        trigFlag=1;
+    }
     ////////////////////////////
     // Apply Filter to Output //
     ////////////////////////////
--- a/main.cpp	Mon Feb 19 15:14:44 2018 +0000
+++ b/main.cpp	Thu Jul 12 10:11:20 2018 +0000
@@ -1,9 +1,9 @@
 ////////////////////////////////////////
 //      Tau_ReSpeaker_DSP V01         //
-//  Arkadiraf@gmail.com - 11/02/2018  //
+//  Arkadiraf@gmail.com - 09/04/2018  //
 ////////////////////////////////////////
 /*
- Json Format: json:{"name":"dsp","filter":"none","mode":"off"}\r\n
+ Json Format: json:{"name":"dsp","mode":"off"}\r\n
 */
 
 
@@ -57,9 +57,8 @@
 //#define DEBUG_MOD1  // json packet recognise
 #define DEBUG_MOD2   // json parse
 #define DEBUG_MOD3   // dsp handler
-#define DEBUG_MOD10   // responsivity msges to gui
-#define DEBUG_MOD11 // loop frequency indicator
-
+#define DEBUG_MOD10  // responsivity msges to gui
+//#define DEBUG_MOD11  // loop frequency indicator
 // Sine generator
 #define PI_DOUBLE (3.141592653589793238462)
 #define PI_FLOAT  (3.14159f)
@@ -131,12 +130,19 @@
 functionPtr FilterFunction;
 
 // alternative functuin selection (faster mcu process)
-volatile uint8_t operationMode = 0;
+volatile uint8_t operationMode = 1;
 // 0 -  off
 // 1 -  passthrough - no filter
 // 2 -  highpass    - High Pass filter
 // 3 -  hpf_trig    - High Pass filter + Trigger mode
 
+
+// Trigger mode variables
+float trigTresh = 0.75; // threshold for trigger mode
+uint32_t trigDelaySet = 3000; // counter for pulse pass
+uint32_t trigDelay = trigDelaySet; // counter for pulse pass
+uint32_t trigPause = 5000; // pause after trigger in microseconds
+
 ///////////////
 // Functions //
 ///////////////
@@ -236,8 +242,8 @@
     Dac_Reg += __HAL_DHR12R1_ALIGNEMENT(DAC_ALIGN_12B_R);
 
     // intialize filter function pointer
-    FilterFunction = offMode;//highpass_filter;
-    operationMode = 0 ;
+    FilterFunction = passthrough;//highpass_filter;
+    operationMode = 1 ;
 }
 
 // Serial Event function