Tau ReSpeaker Setup V01
Dependencies: MbedJSONValue mbed
Fork of TAU_ReSpeaker_DSP_Test by
Diff: filters.h
- Revision:
- 5:ec6f2323a263
- Parent:
- 4:59319802012b
- Child:
- 6:e8b4ca41c691
--- 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 // ////////////////////////////