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

NRF_PWM(For LED) and Button Interrupt Clash

Hello,

i am working with nrf_pwm library which is there in git. Also, on my device, with PTR51822, S110 7v is running. I am having tri color led on the device, by using pwm lib i am able to generate RGB colors. But after having done that the Button pin change interrupt is not reflecting.

What arrangement i am having:

  • When button is pressed, send a random character over nus_ble.(this i am carrying out from main context by setting flag)

  • Tri color led to light up color when some pattern of character i receive over nus_ble.()

  • What happening is:

  • If i light up some color first then button interrupt not works.

  • If i first press button, then button interrupt works, then i glow LED then it glows, after that if i again press button, the button interrupt does not works!

  • Desire:

  • Want tri color LED which occupies three gpio of nrf51822/ptr51822, and one button to work together!

Some of my codes goes here: Button related:

static void button_int_Init( void ){
	
	nrf_gpio_cfg_input( TACT, NRF_GPIO_PIN_PULLDOWN );
	
	NRF_GPIOTE->INTENSET  = GPIOTE_INTENSET_IN0_Set << GPIOTE_INTENSET_IN0_Pos;
	
	
	nrf_gpiote_unconfig( 0 );
	nrf_gpiote_event_config( 0, TACT, NRF_GPIOTE_POLARITY_LOTOHI);
	sd_nvic_SetPriority( GPIOTE_IRQn, 1 );
	sd_nvic_EnableIRQ( GPIOTE_IRQn );
	
}

void GPIOTE_IRQHandler(void)
{
    // Event causing the interrupt must be cleared.
    if ((NRF_GPIOTE->EVENTS_IN[0] == 1) && 
        (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN0_Msk))
    {
        NRF_GPIOTE->EVENTS_IN[0] = 0;
    }
	
	buttonPressEventHappended = true;
		
}

My Main context:

 // Initialize
	// Some var init code goes here...
	nDataOffset = 0;
	n_rgb_b_weight = n_rgb_g_weight = n_rgb_r_weight = 0;
	
	//
	
    leds_init();
	peripheral_init();
    timers_init();
    buttons_init();
        
    ble_stack_init();
    scheduler_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();
    sec_params_init();
    
    button_int_Init();
	initAdxl() ;

	pwm_led_set_config( PWM_MODE_LED_255 );// With SoftDevice Enabled 1
    advertising_start();
  • you can check out the body of nrf_pwm_init() , pwm_led_set_config() and nrf_pwm_set_value() from the github here.

  • my button is on 26, which is named as TACT in the code.

What could be the solution so i could make led and button work together? Or any way out so make button and some legs of LED work together with less PWM ?

Parents
  • Issue fix or i would say the arrangement fixed to get the desired behaviour actually. I have to fit the interrupt in proper manner on port terms + 3 as priority level which is arm related stuff. Also, need to initiate the PWM after button interrupt is been planted. Some portion of code here below which helped me to overcome this problem.

    Button Related Code Edit:

    static void button_int_Init( void ){
    	
    	nrf_gpio_cfg_input( TACT, NRF_GPIO_PIN_PULLDOWN ); 	
        
    	NRF_GPIO->PIN_CNF[TACT] = (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos)
                                            | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
                                            | (NRF_GPIO_PIN_PULLDOWN << GPIO_PIN_CNF_PULL_Pos)
                                            | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
                                            | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
    
    	sd_nvic_SetPriority( GPIOTE_IRQn, 3 );
    	sd_nvic_EnableIRQ( GPIOTE_IRQn );
    	NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set << GPIOTE_INTENSET_PORT_Pos;
    }
    //////////////////////////////////////////////
    void GPIOTE_IRQHandler(void)
    {    
        if ((NRF_GPIOTE->EVENTS_PORT != 0))
    	{
    		NRF_GPIOTE->EVENTS_PORT = 0;
    	}
    	// Active low.
    	if (nrf_gpio_pin_read(TACT) == 1)
    	{
    		buttonPressEventHappended = true;
    	}
    }
    

    Main Context Function calls based on the priority :

    peripheral_init();
    timers_init();
    buttons_init();
    pwm_led_set_config( PWM_MODE_LED_255 );// make sure this shall be called before init of BLE.
    ble_stack_init();
    scheduler_init();
    

    So this sequence and statement helped to get the LED line run on PWM and also let Button sense on interrupt too.

    Hope this have helped you. Do let us know if this works on your end or not!

    Regards

Reply
  • Issue fix or i would say the arrangement fixed to get the desired behaviour actually. I have to fit the interrupt in proper manner on port terms + 3 as priority level which is arm related stuff. Also, need to initiate the PWM after button interrupt is been planted. Some portion of code here below which helped me to overcome this problem.

    Button Related Code Edit:

    static void button_int_Init( void ){
    	
    	nrf_gpio_cfg_input( TACT, NRF_GPIO_PIN_PULLDOWN ); 	
        
    	NRF_GPIO->PIN_CNF[TACT] = (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos)
                                            | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
                                            | (NRF_GPIO_PIN_PULLDOWN << GPIO_PIN_CNF_PULL_Pos)
                                            | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
                                            | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
    
    	sd_nvic_SetPriority( GPIOTE_IRQn, 3 );
    	sd_nvic_EnableIRQ( GPIOTE_IRQn );
    	NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set << GPIOTE_INTENSET_PORT_Pos;
    }
    //////////////////////////////////////////////
    void GPIOTE_IRQHandler(void)
    {    
        if ((NRF_GPIOTE->EVENTS_PORT != 0))
    	{
    		NRF_GPIOTE->EVENTS_PORT = 0;
    	}
    	// Active low.
    	if (nrf_gpio_pin_read(TACT) == 1)
    	{
    		buttonPressEventHappended = true;
    	}
    }
    

    Main Context Function calls based on the priority :

    peripheral_init();
    timers_init();
    buttons_init();
    pwm_led_set_config( PWM_MODE_LED_255 );// make sure this shall be called before init of BLE.
    ble_stack_init();
    scheduler_init();
    

    So this sequence and statement helped to get the LED line run on PWM and also let Button sense on interrupt too.

    Hope this have helped you. Do let us know if this works on your end or not!

    Regards

Children
No Data
Related