This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

application timer + pwm

Hi

I generate a pwm signal via changing the state of one characteristic. In general, the pwm works fine. But the problem occurs when I add the timer which is responsible to switch on and off the pwm signal for 500ms interval. In this case, the timer starts working occasionally and consequently the pwm signal is also generated occasionally. I spent plenty of time for finding the solution to my problem but I did not make it. According to my problem, I think that the issue is located in app_timer library module. I found the following tread: devzone.nordicsemi.com/.../ which can be related to my problem, I hope so. Is it possible that I have the same type of the problem? It is worth mentioning that I am using the SDK 10 together with the corresponding softdevice S110. Here is the code which is executed when the user changes the state of the actual characteristic:

app_pwm_enable(&PWM1);
while(app_pwm_channel_duty_set(&PWM1, 0, 50) == NRF_ERROR_BUSY);				
err_code = app_timer_start(m_buzzer_lpg_timer_id, BUZZER_START_200MS, NULL);
APP_ERROR_CHECK(err_code);		

Here is the corresponding handler

static void buzzer_lpg_timer_handler(void *p_context)
{	
	static bool    	pwm_count           = false;
    static uint8_t 	test_buzzer_counter = 0; 	
	
	if (test_buzzer_counter == 6) 
	{			
		   app_pwm_disable(&PWM1);	
               pwm_count = false;	
		   test_buzzer_counter = 0; 
               ble_is_Buzzer_Busy_update(&m_lpgs,0);	 		
		  nrf_gpio_pin_set(BUZZER_BOOSTER);			  
		  nrf_gpio_pin_clear(BUZZER_PIN);
	}	
	      		
	pwm_count = !pwm_count;
		
	if(pwm_count)			   
		nrf_gpio_pin_clear(BUZZER_BOOSTER);
	else			  
		nrf_gpio_pin_set(BUZZER_BOOSTER);	    			
						
	test_buzzer_counter++;	 						
			
	app_timer_start(m_buzzer_lpg_timer_id, BUZZER_INTERVAL,NULL);
	
}	

I will be pleased with any kind of advice.

Parents
  • main.c

    Hi Sigurd,

    thanks for your reply. I transferred the critical part of the code in my original project into a template project and the main file is attached. As you can see I have two timers for battery acquisition and one timer for buzzer. To be clear I will explain this part little bit more in detail. When the user writes the number 2 in the actual characteristic (you will see that I have only one characteristic besides the battery one in my program) the PWM is generated. At the same time buzzer timer starts (app_timer_start(m_buzzer_lpg_timer_id, BUZZER_INTERVAL,NULL); ) which power on and off the periphery of the buzzer. In such a way I can get the PWM with on and off control.

    I added a critical region in timer_list_handler() but I get the same fault. If I wait for one or two hours and then I send number 2 to the characteristic, the pwm signal is not generated. I am almost sure that the mentioned problem is not caused by the pwm library. The reason lies in the fact that if the timer (app_timer_start(m_buzzer_lpg_timer_id, BUZZER_INTERVAL,NULL) is not included in the code everything works fine. Please do not forget I am using SDK 10 and corresponding softdevice. I am wondering if the SDK 10 has some major errors regarding the application times.

    Thanks for help in advance

    Best regards

    Samo

Reply
  • main.c

    Hi Sigurd,

    thanks for your reply. I transferred the critical part of the code in my original project into a template project and the main file is attached. As you can see I have two timers for battery acquisition and one timer for buzzer. To be clear I will explain this part little bit more in detail. When the user writes the number 2 in the actual characteristic (you will see that I have only one characteristic besides the battery one in my program) the PWM is generated. At the same time buzzer timer starts (app_timer_start(m_buzzer_lpg_timer_id, BUZZER_INTERVAL,NULL); ) which power on and off the periphery of the buzzer. In such a way I can get the PWM with on and off control.

    I added a critical region in timer_list_handler() but I get the same fault. If I wait for one or two hours and then I send number 2 to the characteristic, the pwm signal is not generated. I am almost sure that the mentioned problem is not caused by the pwm library. The reason lies in the fact that if the timer (app_timer_start(m_buzzer_lpg_timer_id, BUZZER_INTERVAL,NULL) is not included in the code everything works fine. Please do not forget I am using SDK 10 and corresponding softdevice. I am wondering if the SDK 10 has some major errors regarding the application times.

    Thanks for help in advance

    Best regards

    Samo

Children
  • Hi,

    Note that you are not checking the return code when you are calling the function app_timer_start(). Please change this:

    app_timer_start(m_buzzer_lpg_timer_id, BUZZER_INTERVAL,NULL);
    

    to

    uint32_t err_code;
    err_code = app_timer_start(m_buzzer_lpg_timer_id, BUZZER_INTERVAL,NULL);	
    APP_ERROR_CHECK(err_code); 
    

    So we can check if the app timer is actually starting, or if it's returning any error codes.

    If you are getting NRF_SUCCESS , you could try to add the delay as explained here.

    If you are still having problems after this, consider uploading the ble_lpgs.c and ble_lpgs.h files, and I could try to reproduce the issue here.

  • Hi Sigurd,

    I found out a problem. I have a problem with the hardware (buzzer). The software works fine. Sorry, but I did not know that this issue can cause the hardware. Thanks for help.

Related