This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is there an example code for using PWM on the nRF51822 with a SoftDevice?

I'm looking to add PWM functionality to my design to drive an LED. Examples exist for other devices, and those don't use the SoftDevice. Is there an example or some reference design for making the PWM module work with the nRF51822 and SD?

  • Hi,

    yes i also need some help how to configure the pwm example when using the softdevice. How to configure the PPI?

    best regards Nils

  • try it...add to your function

    
    		
            err_code = sd_ppi_channel_assign(0, &NRF_TIMER2->EVENTS_COMPARE[0], &NRF_GPIOTE->TASKS_OUT[0]);
    		
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
            
            err_code = sd_ppi_channel_enable_set(1 << 0);		
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
    		
            err_code = sd_ppi_channel_assign(1, &NRF_TIMER2->EVENTS_COMPARE[1], &NRF_GPIOTE->TASKS_OUT[0]);
    		
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
            
            err_code = sd_ppi_channel_enable_set(1 << 1);
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }	
    				
            err_code = sd_ppi_channel_assign(2, &NRF_TIMER2->EVENTS_COMPARE[3], &NRF_GPIOTE->TASKS_OUT[1]);
    		
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
            
            err_code = sd_ppi_channel_enable_set(1 << 2);
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }	
    				
            err_code = sd_ppi_channel_assign(3, &NRF_TIMER2->EVENTS_COMPARE[1], &NRF_GPIOTE->TASKS_OUT[1]);
    		
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
            
            err_code = sd_ppi_channel_enable_set(1 << 3);
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }					
    				nrf_gpiote_task_config(0,8, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);		
    				nrf_gpiote_task_config(1, 9, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);				
    				
    				NVIC_SetPriority(TIMER2_IRQn, 1);//must have to set the priority
    ////------------------------
      NVIC_EnableIRQ(TIMER2_IRQn);
      __enable_irq();
      /* Start clock */
      NRF_TIMER2->TASKS_START = 1;
    
    
    
  • HI thanks for the answer,

    But i need more help, it doesen#t work or i don't know how to use your code.

    best regards Nils

  • No one have any other sample code for me? best regards Nils

Related