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

Timer Prescaler

I have a problem enabling TIMER1: If the prescaler is set between 16MHz and 2 MHz the firmware fails to enable the SoftDevice, even if I didn't manage TIMER0, but TIMER1 which should be dedicated to the softDevice. Using a lower prescaler instead it works. I enable the timer before enabling SoftDevice.

I am working on NRF51822 with softdevice S110 8.0.0.

Am I doing ssomething wrong or not alloweed?

Thank you

Parents
  • I use Timer1, for the reason you mentioned.

    Here some parts of the Code:

    #define TIMER1_ENABLED 1
    
    #if (TIMER1_ENABLED == 1)
    #define TIMER1_CONFIG_FREQUENCY    NRF_TIMER_FREQ_1MHz
    #define TIMER1_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER1_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_16Bit
    #define TIMER1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_HIGH
    
    #define TIMER1_INSTANCE_INDEX      (TIMER0_ENABLED)
    #endif
    

    Here the initialization:

        Timer_DRV.p_reg 			= NRF_TIMER1;
    Timer_DRV.irq					= TIMER1_IRQn;
    Timer_DRV.instance_id = TIMER1_INSTANCE_INDEX;
    
    Timer_DRV_Conf.frequency					= TIMER1_CONFIG_FREQUENCY;
    Timer_DRV_Conf.mode								= TIMER1_CONFIG_MODE;
    Timer_DRV_Conf.bit_width					= TIMER1_CONFIG_BIT_WIDTH;
    Timer_DRV_Conf.interrupt_priority	= TIMER1_CONFIG_IRQ_PRIORITY;
    Timer_DRV_Conf.p_context					= timer_struct;
    
    nrf_drv_timer_init(&Timer_DRV,
                              &Timer_DRV_Conf,
                              timer_clk_handler);
    

    And then configuration interrupt:

                nrf_drv_timer_compare(&Timer_DRV, NRF_TIMER_CC_CHANNEL0, 60, true);
    	nrf_drv_timer_compare(&Timer_DRV, NRF_TIMER_CC_CHANNEL1, 120, true);
    	nrf_drv_timer_compare(&Timer_DRV, NRF_TIMER_CC_CHANNEL2, 180, true);
    	nrf_drv_timer_extended_compare(&Timer_DRV, NRF_TIMER_CC_CHANNEL3, 240, NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK,
                                        true);
    

    Thank you

Reply
  • I use Timer1, for the reason you mentioned.

    Here some parts of the Code:

    #define TIMER1_ENABLED 1
    
    #if (TIMER1_ENABLED == 1)
    #define TIMER1_CONFIG_FREQUENCY    NRF_TIMER_FREQ_1MHz
    #define TIMER1_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER1_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_16Bit
    #define TIMER1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_HIGH
    
    #define TIMER1_INSTANCE_INDEX      (TIMER0_ENABLED)
    #endif
    

    Here the initialization:

        Timer_DRV.p_reg 			= NRF_TIMER1;
    Timer_DRV.irq					= TIMER1_IRQn;
    Timer_DRV.instance_id = TIMER1_INSTANCE_INDEX;
    
    Timer_DRV_Conf.frequency					= TIMER1_CONFIG_FREQUENCY;
    Timer_DRV_Conf.mode								= TIMER1_CONFIG_MODE;
    Timer_DRV_Conf.bit_width					= TIMER1_CONFIG_BIT_WIDTH;
    Timer_DRV_Conf.interrupt_priority	= TIMER1_CONFIG_IRQ_PRIORITY;
    Timer_DRV_Conf.p_context					= timer_struct;
    
    nrf_drv_timer_init(&Timer_DRV,
                              &Timer_DRV_Conf,
                              timer_clk_handler);
    

    And then configuration interrupt:

                nrf_drv_timer_compare(&Timer_DRV, NRF_TIMER_CC_CHANNEL0, 60, true);
    	nrf_drv_timer_compare(&Timer_DRV, NRF_TIMER_CC_CHANNEL1, 120, true);
    	nrf_drv_timer_compare(&Timer_DRV, NRF_TIMER_CC_CHANNEL2, 180, true);
    	nrf_drv_timer_extended_compare(&Timer_DRV, NRF_TIMER_CC_CHANNEL3, 240, NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK,
                                        true);
    

    Thank you

Children
  • You code looks correct (except that i cannot see values of some defines) What is the symptoms you are seeing? is your handler not triggering correctly with softdevice? You description in the question was not so clear about the problem

  • Looking at the behaviour it seems that calling the function: SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false); it has some problem. While not enabling the timer1 it works correctly. The defines are the ones provided by Nordic SDK, the define #define TIMER1_INSTANCE_INDEX (TIMER0_ENABLED) is 0 because there is no TIMER0 enabled

    If there are any other things you need to clarify the situation just ask.

    Thanks

  • LFCLK_XTAL should have nothing to do with TIMERs,

    The define TIMER1_INSTANCE_INDEX is index to the timer driver member, so 0 is fine if Timer0 is not enabled.

    Looking at the behaviour it seems that calling the function: SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false); it has some problem. While not enabling the timer1 it works correctly

    Can you please explain what "It has problems" mean?

  • I meant that that function didn't return(I just put a breakpoint at the following instruction, and it never stops). Now I solved setting the compare at 600, 1200, 1800, 2400, but this lead to another question, is there a lower bound for the compare? To check the interrupt frequency I toggle a pin every compare event, and even if I should have always the same interrupt distance (because of the equidistant comapare settings) the pin toggle is not always at the same interval (I am using an oscilloscope to check). Here's the function code: switch (event_type){

    	case NRF_TIMER_EVENT_COMPARE0:
    			Hw_Interface_SetOutput1();
    	
    	case NRF_TIMER_EVENT_COMPARE1:
    				Hw_Interface_SetOutput();
    				
    	case NRF_TIMER_EVENT_COMPARE2:
    		Hw_Interface_ResetOutput1();
    
    	case NRF_TIMER_EVENT_COMPARE3:
    			Hw_Interface_ResetOutput();
    	}
    

    Is there something wrong, or any limit I should follow? Thanks

Related