AnsweredAssumed Answered

Smoke Alarm Tone Detection Using STM32F407 

Question asked by patel.chintan on Jul 13, 2017

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.



for(index = 0; index < PCM_OUT_SIZE; index++)
    PCMBuf[(index<<1)+1] = PCMBuf[index<<1];


    //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))
        if(pulse_count >= 5)
   //count pulse tone

   //for debug purpose send to uart 
   HAL_UART_Transmit(&huart2,"---Alarm cycle Found:",sizeof("---Alarm cycle Found:"),1000);

   //pulse count to set become zero after detect 5 time sample
   pulse_count = 0;


HAL_UART_Transmit(&huart2,"---Pulse End---\r\n",sizeof("---Pulse End---\r\n"),1000);
pulse_count = 0;

//count for 8PCM sample

// 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
               HAL_UART_Transmit(&huart2,"---ALARM DETECT---\r\n",sizeof("---ALARM DETECT---\r\n"),1000);
         // alarm cycle not detect so we need to reset all pulse cycle , total pulse count and do agian continuously
            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