cancel
Showing results for 
Search instead for 
Did you mean: 

Smoke Alarm Tone Detection Using STM32F407

chintan
Associate
Posted on July 13, 2017 at 12:35

Hello All,

Application Requirement:

   Alarm detection using STM32F407 discovery Board and if alarm tone detect generate alarm signal

and system become off.

Issue :

1> While Mic Place on the Loudspeaker alarm tone detect accurately but when place on side of loud speaker it has not detect any PCM pulse of alarm tone for identification.

2> Alarm Tone Frequency greater than 600 Hz not detected

We Used:

MCU                :    STM32F407VG Discovery Board

Protocol           :    I2S + DMA + UART

Library             :    stm32cube_fw_f4_v1160

Sample code   :    stm32cube_fw_f4_v1160\STM32Cube_FW_F4_V1.16.0\Projects\STM32F4-Discovery\Applications\Audio\Audio_playback_and_record\

Alarm Tone      :    500 Hz Freq, More On and Off time Tone(so we get more PCM sample during on time)

Software Configuration:

Audio In Freq         :    8000 Hz

Audio Volume        :    64 //(0 to 64)

PDM to PCM filter : PDM_Filter_64_LSB

Alarm Detection Code Scenario:

As per sample code application, we get 8 PCM value for setting AUDIO_IN_FREQ to 8 Khz. so we get 8 sample every Time.

After Debug we get PCM Value of Alarm Tone which remain same while Alarm tone on.

We Compare this value every time with received PCM 8 sample and if it detect more than 5 we increment to pulse detect counter.

and if we detect pulse detect counter more than 10 means alarm Detect and system become stop.

but if does not detect alarm within 100 sample of 8 PCM value it reset pulse detect counter and pulse counter.

Code:

for(index = 0; index < PCM_OUT_SIZE; index++)

{

    PCMBuf[(index<<1)+1] = PCMBuf[index<<1];

    sprintf(uart_buf,'%d\r\n',PCMBuf[index*2]);

    HAL_UART_Transmit(&huart2,uart_buf,7,1000);

    //While Alarm on PCM 32700/32836 value detected so we compare every PCM sample with it

    if((PCMBuf[index*2] == 32700)|| (PCMBuf[index*2] == 32836))

    {

        ++pulse_count;

        if(pulse_count >= 5)

    {

   //count pulse tone

   ++alarm_cycle_found;

   //for debug purpose send to uart 

   HAL_UART_Transmit(&huart2,'---Alarm cycle Found:',sizeof('---Alarm cycle Found:'),1000);

   sprintf(cycle_no,'%d',alarm_cycle_found);

   HAL_UART_Transmit(&huart2,cycle_no,3,1000);

   HAL_UART_Transmit(&huart2,'\r\n',sizeof('\r\n'),1000);

   //pulse count to set become zero after detect 5 time sample

   pulse_count = 0;

}

uart_buf[0]='\0';

HAL_UART_Transmit(&huart2,'---Pulse End---\r\n',sizeof('---Pulse End---\r\n'),1000);

pulse_count = 0;

//count for 8PCM sample

++total_pulse_count;

// check at every 100 8PCM sample

if(total_pulse_count >= 100)

{

         //check if alarm cycle count and more than 10 time means alarm detected

         if(alarm_cycle_found >= 10)

         {

               // Block functionality and send message on uart

            while(1)

            {

               HAL_UART_Transmit(&huart2,'---ALARM DETECT---\r\n',sizeof('---ALARM DETECT---\r\n'),1000);

               HAL_Delay(2000);

            }

         }

         // alarm cycle not detect so we need to reset all pulse cycle , total pulse count and do agian continuously

         else

         {

            pulse_count = 0;

            alarm_cycle_found = 0;

            pulse_count = 0;

            total_pulse_count = 0;

         }

  }  

/************************************************************************************/

so how we will go further for give accurate result in noisy environment also.

If we are doing wrong so guide us if it is possible.

Thanks & Regards

Chintan Patel

#stm32f407 #audio #audio-codec #audio-recording
0 REPLIES 0