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?
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?
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;