app_timer problem

Hellow,

I'm using app_timer to play the buzzer.

The default behavior is

1. key in
2. timer start: 8Sec for key action stop check
3. Buzzer on (pwm1)
3. buzzer timer start
4. Buzzer timer stop.
5. buzzer off

The odd thing is

  1. Abnormal termination of the timer occurs.
  • The 8 second timer in process 2 is terminated as soon as it starts.
  • Due to this phenomenon, abnormal operation of the buzzer makes the overall wrong operation.   Below is a log message. The current issue is being debugged for a few days now. Help is urgently needed.

Thank you.

// *** normal message ***
 0> key in : touch 1
 0> key action : touch 1
 0> *** timer - normal start ***
 0> buzzer start
 0> buzzer timer start : 0
 0> pwm-buzzer uninit error : 0
 0> pwm-buzzer init error : 0
 0> pwm-buzzer enable
 0> pwm-buzzer duty set
 0> *** sleep ***
 0> buzzer timer stop : 0
 0> timer handler
 0> buzzer timer start : 0
 0> pwm-buzzer uninit error : 0
 0> pwm-buzzer init error : 0
 0> pwm-buzzer enable
 0> pwm-buzzer duty set
 0> *** sleep ***
 0> buzzer timer stop : 0
 0> timer handler
 0> buzzer stop
 0> *** sleep ***


// *** abnormal message ***
 0> key in : touch 1
 0> key action : touch 1
 0> *** timer : normal start ***
 0> buzzer start
 0> *** timer : normal end ***      --->>> abnormal timer stop !!!!!!!
 0> buzzer start               
 0> buzzer timer start : 0
 0> pwm-buzzer uninit error : 0
 0> pwm-buzzer init error : 0
 0> pwm-buzzer enable
 0> pwm-buzzer duty set
 0> buzzer timer stop : 0
 0> buzzer timer stop : 0
 0> timer handler
 0> buzzer timer start : 0
 0> pwm-buzzer uninit error : 0
 0> pwm-buzzer init error : 0
 0> pwm-buzzer enable
 0> pwm-buzzer duty set
 0> buzzer timer stop : 0
 0> timer handler
 0> buzzer stop
 0> buzzer timer start : 0
 0> pwm-buzzer uninit error : 0
 0> pwm-buzzer init error : 0
 0> pwm-buzzer enable
 0> pwm-buzzer duty set
 0> *** sleep ***
 0> *** sleep ***

--->>> another buzzer start when time stopped : not acceptable !!!

  • Which SDK version are you using? Can you upload some code, showing timers/button setup and how you start timers and buzzer?

  • Hello, I use SDK 12.1.0. My co-worker experienced the same problem in the different project. If you are OK, I want to send my code all via e-mail.

  • uint32_t initKey(void) { uint32_t err_code;

    	if(!nrf_drv_gpiote_is_init())
    	{
    		err_code = nrf_drv_gpiote_init();
    		VERIFY_SUCCESS(err_code);
    	}
    
    	// touch int
    	nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
    	config.pull = NRF_GPIO_PIN_PULLUP;
    	err_code = nrf_drv_gpiote_in_init(ADS16_INT_PIN, &config, handler_touchIn);
    	VERIFY_SUCCESS(err_code);
    
    /*
    	// tact s/w int
    	config.pull = NRF_GPIO_PIN_PULLUP;
    
    	err_code = nrf_drv_gpiote_in_init(KEY0_PIN, &config, handler_tactIn);
    	VERIFY_SUCCESS(err_code);
    	err_code = nrf_drv_gpiote_in_init(KEY1_PIN, &config, handler_tactIn);
    	VERIFY_SUCCESS(err_code);
    	err_code = nrf_drv_gpiote_in_init(KEY2_PIN, &config, handler_tactIn);
    	VERIFY_SUCCESS(err_code);
    	err_code = nrf_drv_gpiote_in_init(KEY3_PIN, &config, handler_tactIn);
    	VERIFY_SUCCESS(err_code);
    	err_code = nrf_drv_gpiote_in_init(KEY4_PIN, &config, handler_tactIn);
    	VERIFY_SUCCESS(err_code);
    	err_code = nrf_drv_gpiote_in_init(KEY5_PIN, &config, handler_tactIn);
    	VERIFY_SUCCESS(err_code);
    	err_code = nrf_drv_gpiote_in_init(KEYSTAR_PIN, &config, handler_tactIn);
    	VERIFY_SUCCESS(err_code);
    */
    	return NRF_SUCCESS;
    }
    
    void handler_touchIn(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
    	bool err_code = true;
    	uint8_t writeBuf[1];
    
    //	UNUSED_PARAMETER(p_context);
    	NVIC_ClearPendingIRQ(GPIOTE_IRQn);
    
    //	holdTouch(HOLD_TOUCH);
    //	ENABLE_TWI;
    	__NOP;
    	__NOP;
    	__NOP;
    	__NOP;
    	__NOP;
    
    	// touch data read
    	if(!nrf_gpio_pin_read(ADS16_INT_PIN))				// int recheck
    	{
    //		accessTouch(STOP);
    //		timerScanTouch(START);
    
    		writeBuf[0] = 0x10;									// touch data start address
    		err_code &= twi_master_transfer(ADS16_WRITE_ADDR, writeBuf, 1, TWI_ISSUE_STOP);
    		err_code &= twi_master_transfer(ADS16_READ_ADDR, touchVal, 4, TWI_ISSUE_STOP);
    
    		// error check
    		if(err_code == true)
    		{
    			fkeyScanNeed = 1;
    			fkeyInType = TOUCH_IN;
    		}
    	}
    //	DISABLE_TWI;
    
    	// sleep touch
    	sleepTouch();
    }
    
    
    void timerNormalOpEnd(uint8_t type)
    {
    	uint32_t err_code = NRF_SUCCESS;
    
    	if(type == START)
    	{
    		err_code = app_timer_stop(NORMAL_OP_TIMER_ID);				// for refresh
    		APP_ERROR_CHECK(err_code);
    		err_code = app_timer_start(NORMAL_OP_TIMER_ID, NORMAL_OP_END_INTERVAL, NULL);
    		APP_ERROR_CHECK(err_code);
    	}
    	else if(type == STOP)
    	{
    		err_code = app_timer_stop(NORMAL_OP_TIMER_ID);
    		APP_ERROR_CHECK(err_code);
    	}
    }
    
    void onSound(uint8_t Num)
    {
    	NRF_LOG_PRINTF("buzzer start\r\n");
    
    
    //	offSound();
    
    	if(fonSound)
    	{
    		timerBuzzer(STOP, NULL);			
    		app_pwm_disable(&PWM_BUZZER);
    	}
    	else
    	{
    //		timerBuzzer(STOP, NULL);			
    	}
    
    	BUZZER_USE;
    	fonSound = 1;
    
    	if(Num != BEEP_DOOR_ALARM)
    		doorAlarmBeepCnt = 0;						// door open alarm beep cancel
    
    	beepOrder = 0;
    	beepCnt = beepCntInfo[Num];
    	soundNum = Num;
    
    	timerBuzzer(START, beepTime[soundNum][beepOrder]);			
    //	nrf_delay_ms(1);
    	controlLed(ledInfo[soundNum][beepOrder]);
    	makeSound(beepLevel[soundNum][beepOrder]);
    }
    
    void makeSound(uint16_t level)
    {
    	uint8_t i = 0;
    	ret_code_t err_code;
    
    //	app_pwm_disable(&PWM_BUZZER);
    	err_code = app_pwm_uninit(&PWM_BUZZER);
    	NRF_LOG_PRINTF("pwm-buzzer uninit error : %d\r\n", err_code);
    	APP_ERROR_CHECK(err_code);
    //	nrf_delay_us(200);
    
    	app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(level, BUZZER_PIN);
    	pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
    
    	err_code = app_pwm_init(&PWM_BUZZER, &pwm1_cfg, NULL);			// callback_pwmBuz);
    	NRF_LOG_PRINTF("pwm-buzzer init error : %d\r\n", err_code);
    	APP_ERROR_CHECK(err_code);
    //	nrf_delay_us(200);
    
    	app_pwm_enable(&PWM_BUZZER);
    //	nrf_delay_ms(10);
    	NRF_LOG_PRINTF("pwm-buzzer enable\r\n");
    //	nrf_delay_us(200);
    
    
    	// sound level check
    #if !TEST_SOUND_OFF
    	if(fireStatus)
    		while(app_pwm_channel_duty_set(&PWM_BUZZER, 0, SOUND_MAX) == NRF_ERROR_BUSY);
    	else if(batteryStatusSave <= BATTERY_LOW)
    		while(app_pwm_channel_duty_set(&PWM_BUZZER, 0, SOUND_MIN) == NRF_ERROR_BUSY);
    
    	else if(soundLevelTemp == 0)
    		while(app_pwm_channel_duty_set(&PWM_BUZZER, 0, soundLevelInfo[lockInfo.soundLevel]) == NRF_ERROR_BUSY);
    	else
    		while(app_pwm_channel_duty_set(&PWM_BUZZER, 0, soundLevelTemp) == NRF_ERROR_BUSY);
    #else
    	while(app_pwm_channel_duty_set(&PWM_BUZZER, 0, SOUND_OFF) == NRF_ERROR_BUSY);
    #endif
    
    	NRF_LOG_PRINTF("pwm-buzzer duty set\r\n");
    }
    
    
    void handler_buzzer(void * p_context)
    {
    	UNUSED_PARAMETER(p_context);	  
    	timerBuzzer(STOP, NULL);
    	NRF_LOG_PRINTF("timer handler\r\n");
    
    	beepOrder++;
    	beepCnt--;
    
    	if(beepCnt)
    	{
    		timerBuzzer(START, beepTime[soundNum][beepOrder]);			
    		nrf_delay_ms(1);
    		controlLed(ledInfo[soundNum][beepOrder]);
    		makeSound(beepLevel[soundNum][beepOrder]);
    	}
    	else
    	{
    
    
    
       }
    }
    
  • Could you try updating to SDK 13.0.0? There was a bug in app_timer, which should be fixed in the latest SDK. If you do not want to share your code in public, you can create a private case on MyPage, with a link to this thread. The information on MyPage is threated confidentially.

  • I can't log in. I don't know why? I wonder if there is any other way to send the my code. Also, in SDK13.0.0, I wonder if I can modify only the app_timer related part or not. It is because there is not enough time to fix it all.

    Thanks.